commit
89613136ff
|
|
@ -38,42 +38,44 @@ class OrderItemInventoryRepository extends Repository
|
|||
|
||||
$product = $orderItem->type == 'configurable' ? $orderItem->child->product : $orderItem->product;
|
||||
|
||||
if ($product) {
|
||||
$inventories = $product->inventory_sources()->orderBy('priority', 'asc')->get();
|
||||
|
||||
foreach ($inventories as $inventorySource) {
|
||||
if (! $orderedQuantity)
|
||||
break;
|
||||
|
||||
$sourceQuantity = $inventorySource->pivot->qty;
|
||||
|
||||
if (! $inventorySource->status || !$sourceQuantity)
|
||||
continue;
|
||||
|
||||
if ($sourceQuantity >= $orderedQuantity) {
|
||||
$orderItemQuantity = $orderedQuantity;
|
||||
|
||||
$sourceQuantity -= $orderItemQuantity;
|
||||
|
||||
$orderedQuantity = 0;
|
||||
} else {
|
||||
$orderItemQuantity = $sourceQuantity;
|
||||
|
||||
$sourceQuantity = 0;
|
||||
|
||||
$orderedQuantity -= $orderItemQuantity;
|
||||
}
|
||||
|
||||
$this->model->create([
|
||||
'qty' => $orderItemQuantity,
|
||||
'order_item_id' => $orderItem->id,
|
||||
'inventory_source_id' => $inventorySource->id,
|
||||
]);
|
||||
|
||||
$inventorySource->pivot->update([
|
||||
'qty' => $sourceQuantity
|
||||
]);
|
||||
}
|
||||
if (!$product) {
|
||||
return ;
|
||||
}
|
||||
$inventories = $product->inventory_sources()->orderBy('priority', 'asc')->get();
|
||||
|
||||
foreach ($inventories as $inventorySource) {
|
||||
if (! $orderedQuantity)
|
||||
break;
|
||||
|
||||
$sourceQuantity = $inventorySource->pivot->qty;
|
||||
|
||||
if (! $inventorySource->status || !$sourceQuantity)
|
||||
continue;
|
||||
|
||||
if ($sourceQuantity >= $orderedQuantity) {
|
||||
$orderItemQuantity = $orderedQuantity;
|
||||
|
||||
$sourceQuantity -= $orderItemQuantity;
|
||||
|
||||
$orderedQuantity = 0;
|
||||
} else {
|
||||
$orderItemQuantity = $sourceQuantity;
|
||||
|
||||
$sourceQuantity = 0;
|
||||
|
||||
$orderedQuantity -= $orderItemQuantity;
|
||||
}
|
||||
|
||||
$this->model->create([
|
||||
'qty' => $orderItemQuantity,
|
||||
'order_item_id' => $orderItem->id,
|
||||
'inventory_source_id' => $inventorySource->id,
|
||||
]);
|
||||
|
||||
$inventorySource->pivot->update([
|
||||
'qty' => $sourceQuantity
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -90,9 +90,9 @@ class OrderItemRepository extends Repository
|
|||
|
||||
$product = $orderItem->type == 'configurable' ? $orderItem->child->product : $orderItem->product;
|
||||
|
||||
if (! $product) {
|
||||
if (! $product)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$orderedInventory = $product->ordered_inventories()
|
||||
->where('channel_id', $orderItem->order->channel->id)
|
||||
|
|
@ -126,14 +126,15 @@ class OrderItemRepository extends Repository
|
|||
->where('channel_id', $orderItem->order->channel->id)
|
||||
->first();
|
||||
|
||||
if ($orderedInventory) {
|
||||
if (($qty = $orderedInventory->qty - $orderItem->qty_to_cancel) < 0) {
|
||||
$qty = 0;
|
||||
}
|
||||
|
||||
$orderedInventory->update([
|
||||
'qty' => $qty
|
||||
]);
|
||||
if (! $orderedInventory)
|
||||
return ;
|
||||
|
||||
if (($qty = $orderedInventory->qty - $orderItem->qty_to_cancel) < 0) {
|
||||
$qty = 0;
|
||||
}
|
||||
|
||||
$orderedInventory->update([
|
||||
'qty' => $qty
|
||||
]);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue