write me a warner
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user