This commit is contained in:
rahulshukla-home 2020-05-12 14:23:41 +05:30
parent eefa67ff6b
commit 18e4af0356
2 changed files with 34 additions and 1 deletions

2
.gitignore vendored
View File

@ -25,4 +25,4 @@ yarn.lock
storage/
storage/*.key
/docker-compose-collection/
/resources/themes/velocity/*
/resources/themes/velocity/*

View File

@ -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;
}
}