Added product inventory levels to BundleOption - can be used to display out of stock bundle items in front end

This commit is contained in:
Matt April 2020-05-29 12:30:32 -04:00
parent e189a4fa80
commit 7cf6cdb9f0
1 changed files with 5 additions and 0 deletions

View File

@ -35,6 +35,9 @@ class BundleOption extends AbstractProduct
{
$options = [];
# eager load all inventories for bundle options
$this->product->bundle_options->load('bundle_option_products.product.inventories');
foreach ($this->product->bundle_options as $option) {
$options[$option->id] = $this->getOptionItemData($option);
}
@ -87,6 +90,8 @@ class BundleOption extends AbstractProduct
'product_id' => $bundleOptionProduct->product_id,
'is_default' => $bundleOptionProduct->is_default,
'sort_order' => $bundleOptionProduct->sort_order,
'in_stock' => $bundleOptionProduct->product->inventories->sum('qty') >= $bundleOptionProduct->qty,
'inventory' => $bundleOptionProduct->product->inventories->sum('qty'),
];
}