write me a warner
This commit is contained in:
1 parent
d3ac6ff8d9
commit
e2adf5e9da
6 files changed
+94
-2
No files matched your search
@@ -41,10 +41,24 @@ public function execute(User $user, array $data): Order
|
||||
'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