¨4.0.1¨
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Modules\Order\Http\Controllers\Admin;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Order\Entities\OrderProduct;
|
||||
use Modules\Order\Events\OrderStatusChanged;
|
||||
@@ -11,8 +12,9 @@ class OrderStatusController
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Modules\Order\Entities\Order $request
|
||||
* @return \Illuminate\Http\Response
|
||||
* @param Order $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function update(Order $order)
|
||||
{
|
||||
@@ -27,6 +29,7 @@ class OrderStatusController
|
||||
return $message;
|
||||
}
|
||||
|
||||
|
||||
private function adjustStock(Order $order)
|
||||
{
|
||||
if ($this->canceledOrRefunded(request('status'))) {
|
||||
@@ -38,36 +41,54 @@ class OrderStatusController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function canceledOrRefunded($status)
|
||||
{
|
||||
return in_array($status, [Order::CANCELED, Order::REFUNDED]);
|
||||
}
|
||||
|
||||
|
||||
private function restoreStock(Order $order)
|
||||
{
|
||||
$order->products->each(function (OrderProduct $orderProduct) {
|
||||
if ($orderProduct->product->manage_stock) {
|
||||
$orderProduct->product->increment('qty', $orderProduct->qty);
|
||||
}
|
||||
if ($orderProduct->product_variant) {
|
||||
if ($orderProduct->product_variant->manage_stock) {
|
||||
$orderProduct->product_variant->increment('qty', $orderProduct->qty);
|
||||
}
|
||||
|
||||
if ($orderProduct->product->qty > 0) {
|
||||
$orderProduct->product->markAsInStock();
|
||||
if ($orderProduct->product_variant->qty === 1) {
|
||||
$orderProduct->product_variant->markAsInStock();
|
||||
}
|
||||
} else {
|
||||
if ($orderProduct->product->manage_stock) {
|
||||
$orderProduct->product->increment('qty', $orderProduct->qty);
|
||||
}
|
||||
|
||||
if ($orderProduct->product->qty > 0) {
|
||||
$orderProduct->product->markAsInStock();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private function reduceStock(Order $order)
|
||||
{
|
||||
$order->products->each(function (OrderProduct $orderProduct) {
|
||||
if (
|
||||
$orderProduct->product->manage_stock
|
||||
&& $orderProduct->product->qty !== 0
|
||||
) {
|
||||
$orderProduct->product->decrement('qty', $orderProduct->qty);
|
||||
}
|
||||
|
||||
if ($orderProduct->product->qty === 0) {
|
||||
$orderProduct->product->markAsOutOfStock();
|
||||
if ($orderProduct->product_variant) {
|
||||
if (
|
||||
$orderProduct->product_variant->manage_stock
|
||||
&& $orderProduct->product_variant->qty !== 0
|
||||
) {
|
||||
$orderProduct->product_variant->decrement('qty', $orderProduct->qty);
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
$orderProduct->product->manage_stock
|
||||
&& $orderProduct->product->qty !== 0
|
||||
) {
|
||||
$orderProduct->product->decrement('qty', $orderProduct->qty);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user