FalconFashionFrontend/fix_quantity_change.ps1
2025-12-11 22:07:09 +05:30

32 lines
1.6 KiB
PowerShell

$filePath = "d:\Metatron cube\falcon fashion\anvogue-multipurpose-ecommerce-react-nextjs\Main\anvogue\src\app\cart\page.tsx"
$content = Get-Content $filePath -Raw
# Find and replace - add the updateCart logic before the token line
$oldLine = " const token = localStorage.getItem(`"token`")"
$newLines = @"
// Immediately update CartContext for instant subtotal update
const cartItem = cartState.cartArray.find(
(cartItem) => (cartItem.id === item.product._id || cartItem.id === item.product.id)
);
if (cartItem) {
updateCart(cartItem.id, newQuantity, item.size, item.color);
}
// Then sync with API
const token = localStorage.getItem("token")
"@
$content = $content.Replace($oldLine, $newLines)
# Also update the comment after getCartData
$content = $content.Replace(
" getCartData()",
" getCartData() // Refresh local cart state"
)
# Remove the old commented code
$content = $content -replace " // const itemToUpdate = cart\.find\(\(item\) => item\._id === cart\._id\);[\r\n]+[\r\n]+[\r\n]+ // // Kiểm tra xem sản phẩm có tồn tại không[\r\n]+ // if \(itemToUpdate\) \{[\r\n]+ // // Truyền giá trị hiện tại của selectedSize và selectedColor[\r\n]+ // updateCart\(cart\._id, newQuantity, itemToUpdate\.selectedSize, itemToUpdate\.selectedColor\);[\r\n]+ // \}[\r\n]+", ""
Set-Content -Path $filePath -Value $content -NoNewline
Write-Host "✅ Updated handleQuantityChange function successfully"