From 8fc71a1281260d7c59aca6878c71205b19c395ff Mon Sep 17 00:00:00 2001 From: adonis Date: Mon, 29 Jun 2026 19:11:03 +0330 Subject: [PATCH] ghatre changes 2 --- app/Http/Controllers/Customer/CartController.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/Customer/CartController.php b/app/Http/Controllers/Customer/CartController.php index 104090b..d96a541 100644 --- a/app/Http/Controllers/Customer/CartController.php +++ b/app/Http/Controllers/Customer/CartController.php @@ -344,11 +344,6 @@ class CartController extends Controller $priceRow = Price::latest()->first(); $goldPrice = $priceRow ? (float) $priceRow->price : 0; - $requestLines = collect($payload) - ->filter(fn ($row) => is_array($row) && isset($row['product_id'])) - ->groupBy('product_id') - ->map(fn ($group) => $group->last()); - $wallet_interface = new WalletInterface($customerId, auth('customer')->user()->type); $total_price = 0; @@ -366,13 +361,10 @@ class CartController extends Controller app(ConfigService::class)->assertProductTradingOpen($product); - $line = $requestLines->get($item->product_id); $qty = (int) $item->quantity; - $unitPrice = (float) ($line['price'] ?? 0); - if ($unitPrice <= 0) { - $unitPrice = (float) (($product->price ?? 0) + ($product->price_profit ?? 0)); - } + // قیمت واحد از DB — نه قیمت ارسالی کلاینت (در فروشگاه قیمت نقدی هر عدد است، نه هر گرم) + $unitPrice = (float) (($product->price ?? 0) + ($product->price_profit ?? 0)); if ($unitPrice <= 0 && (float) $product->amount > 0 && $goldPrice > 0) { $unitPrice = (float) $product->amount * $goldPrice; } @@ -395,8 +387,10 @@ class CartController extends Controller $orderData = [ 'customer_id' => $customerId, + 'cart_id' => (int) $cart->id, 'price_id' => $priceRow?->id, - 'price' => $total_amount > 0 ? (int) round($total_price / $total_amount) : 0, + // مظنهٔ مرجع (ریال/گرم) — نه total_price/amount که برای سبد فروشگاهی overflow می‌دهد + 'price' => $goldPrice > 0 ? (int) round($goldPrice) : 0, 'price_original' => $goldPrice, 'amount' => $total_amount, 'service_charge_percentage' => 0,