Issue #3047
This commit is contained in:
parent
eefa67ff6b
commit
18e4af0356
|
|
@ -25,4 +25,4 @@ yarn.lock
|
|||
storage/
|
||||
storage/*.key
|
||||
/docker-compose-collection/
|
||||
/resources/themes/velocity/*
|
||||
/resources/themes/velocity/*
|
||||
|
|
@ -573,6 +573,8 @@ class Configurable extends AbstractType
|
|||
public function haveSufficientQuantity($qty)
|
||||
{
|
||||
$backorders = core()->getConfigData('catalog.inventory.stock_options.backorders');
|
||||
|
||||
$backorders = ! is_null ($backorders) ? $backorders : false;
|
||||
|
||||
foreach ($this->product->variants as $variant) {
|
||||
if ($variant->haveSufficientQuantity($qty)) {
|
||||
|
|
@ -598,4 +600,35 @@ class Configurable extends AbstractType
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function totalQuantity()
|
||||
{
|
||||
$total = 0;
|
||||
|
||||
$channelInventorySourceIds = core()->getCurrentChannel()
|
||||
->inventory_sources()
|
||||
->where('status', 1)
|
||||
->pluck('id');
|
||||
|
||||
foreach ($this->product->variants as $variant) {
|
||||
foreach ($variant->inventories as $inventory) {
|
||||
if (is_numeric($index = $channelInventorySourceIds->search($inventory->inventory_source_id))) {
|
||||
$total += $inventory->qty;
|
||||
}
|
||||
}
|
||||
|
||||
$orderedInventory = $variant->ordered_inventories()
|
||||
->where('channel_id', core()->getCurrentChannel()->id)
|
||||
->first();
|
||||
|
||||
if ($orderedInventory) {
|
||||
$total -= $orderedInventory->qty;
|
||||
}
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue