Fixed issues #300 & Updated inventory in product grid after order received

This commit is contained in:
Prashant Singh 2018-12-21 16:14:20 +05:30
parent 5ebe171117
commit 6fba17ea81
3 changed files with 21 additions and 7 deletions

View File

@ -25,7 +25,7 @@ class Order {
try {
Mail::send(new NewOrderNotification($order));
} catch (\Exception $e) {
}
}
@ -39,7 +39,7 @@ class Order {
try {
Mail::send(new NewInvoiceNotification($invoice));
} catch (\Exception $e) {
}
}
@ -53,7 +53,7 @@ class Order {
try {
Mail::send(new NewShipmentNotification($shipment));
} catch (\Exception $e) {
}
}
@ -67,7 +67,7 @@ class Order {
$productListener = app(\Webkul\Admin\Listeners\Product::class);
foreach ($order->items as $item) {
$productListener->afterProductCreated($item->product);
$productListener->afterOrderRecieved($item->product->id, $item->qty_ordered);
}
}
}

View File

@ -213,6 +213,20 @@ class Product {
return true;
}
/**
* Updates the product quantity when the order is received
*
* @param $productId
* @param $itemQuantity
*/
public function afterOrderRecieved($productId, $itemQuantity) {
$productGrid = $this->productGrid->findOneByField('product_id', $productId);
$productGrid->update(['quantity' => $productGrid->quantity - $itemQuantity]);
return true;
}
/**
* Manually invoke this function when you have created the products by importing or seeding or factory.
*/

View File

@ -639,9 +639,9 @@ class Cart {
}
}
$cart->customer_email = $cart->shipping_address->email;
$cart->customer_first_name = $cart->shipping_address->first_name;
$cart->customer_last_name = $cart->shipping_address->last_name;
$cart->customer_email = $cart->billing_address->email;
$cart->customer_first_name = $cart->billing_address->first_name;
$cart->customer_last_name = $cart->billing_address->last_name;
$cart->save();
return true;