write me a warner

This commit is contained in:
Mekan1206
2026-02-11 03:15:43 +05:00
parent d3ac6ff8d9
commit e2adf5e9da
6 changed files with 94 additions and 2 deletions

View File

@@ -41,10 +41,24 @@ class CreateOrderService
'updated_at' => now(),
]);
// Update Stock
// Update Stock directly in products table, also relationship
$stock = $cart->product->stock - $cart->product_quantity;
$cart->product->update([
'stock' => $cart->product->stock - $cart->product_quantity,
'stock' => $stock,
]);
$data = DB::table('inventory_product')->where('product_id', $cart->product_id)->first();
if ($data) {
DB::table('inventory_product')->where('id', $data->id)->update([
'stock' => $stock,
]);
} else {
warn('Product has no inventory record', json_encode([
'product_id' => $cart->product_id,
'order_id' => $order->id,
]));
}
});
// 3. Clear User Cart