cancel
Showing results for 
Search instead for 
Did you mean: 

magento show quantity bundle product

SOLVED

magento show quantity bundle product

Hi, I now have the simple products show their stock but now I would also like to show the stock of bundle products.

 

I have the following code found in bundle.phtml and I replaced <p class="availability in-stock"><?php echo $this->helper('catalog')->__('Availability:') ?> <span><?php echo $this->helper('catalog')->__('In stock') ?></span></p>

 

 I put the following code instead but unfortunately I do not see the stock. I only get the message Availability 0 in stock  <p class="availability in-stock"><?php echo $this->__('Availability: ') ?><?=(int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()?><?php echo $this->__(' Availability.') ?></p>

 

Below is the original code

 

?>
<?php $_product = $this->getProduct() ?>

<?php if ($_product->isSaleable()): ?>
<script type="text/javascript">
//<![CDATA[
var skipTierPricePercentUpdate = true;
var bundle = new Product.Bundle(<?php echo $this->getJsonConfig() ?>);
var taxCalcMethod = "<?php echo Mage::helper('tax')->getConfig()->getAlgorithm($_product->getStore()) ?>";
var CACL_UNIT_BASE = "<?php echo Mage_Tax_Model_Calculation::CALC_UNIT_BASE ?>";
var CACL_ROW_BASE = "<?php echo Mage_Tax_Model_Calculation::CALC_ROW_BASE ?>";
var CACL_TOTAL_BASE = "<?php echo Mage_Tax_Model_Calculation::CALC_TOTAL_BASE ?>";
//]]>
</script>
<?php endif; ?>
<?php if ($this->displayProductStockStatus()): ?>
<?php if ($_product->isAvailable()): ?>
<p class="availability in-stock"><?php echo $this->helper('catalog')->__('Availability:') ?>
<span><?php echo $this->helper('catalog')->__('In stock') ?></span></p>
<?php else: ?>
<p class="availability out-of-stock"><?php echo $this->helper('catalog')->__('Availability:') ?>
<span><?php echo $this->helper('catalog')->__('Out of stock') ?></span></p>
<?php endif; ?>
<?php endif; ?>
<div class="price-box-bundle">
<?php echo $this->getPriceHtml($_product) ?>
</div>
<?php echo $this->getChildHtml('bundle_prices') ?>

 

Does anyone know how I can visualize the stock to bundle products

 

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions

Re: magento show quantity bundle product

Wherever you want it to appear, for bundled products the file would be

 

app/design/frontend/{theme}/template/bundle/catalog/product/view/type/bundle/availability.phtml

There you can update

 

        <p class="availability in-stock">
            <span class="label"><?php echo $this->helper('catalog')->__('Availability:') ?></span>
            <span class="value"><?php echo $this->helper('catalog')->__('In stock') ?></span>
        </p>

to

 

<?php
$selectionCollection = $_product->getTypeInstance()->getSelectionsCollection($_product->getTypeInstance()->getOptionsIds());
$qty = false;
foreach ($selectionCollection as $option) {
    $product_id = $option->product_id;
    $bundleOption = Mage::getModel('catalog/product')->load($product_id);
    $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($bundleOption);
    if ($qty === false) {
        $qty = $stock->getQty();
    } else {
        $qty = min(array($qty, $stock->getQty()));
    }
}
?>


<p class="availability in-stock">
    <span class="label"><?php echo $this->helper('catalog')->__('Availability:') ?></span>
    <span class="value"><?php echo $qty . ' ' . $this->helper('catalog')->__('In stock') ?></span>
</p>

 

 

Did I help you solve your problem? Click Accept as Solution!
DudeSquare Web Development

View solution in original post

8 REPLIES 8

Re: magento show quantity bundle product

As far as I understand, the bundled product doesn't have an inventory qty by itself, but it's saleability is determined by its required bundle options. So if you want to show the qty for the bundled product, you should actually display the lowest qty of it's required options. Do you know how to get those quantities?

Did I help you solve your problem? Click Accept as Solution!
DudeSquare Web Development

Re: magento show quantity bundle product

Hi,

 

Thanks for your comment. I would not know how to do this.

Re: magento show quantity bundle product

If you have the bundle product as a variable $_product, you can get the options by using something like

 

$selectionCollection = $_product->getTypeInstance()->getSelectionsCollection($_product->getTypeInstance()->getOptionsIds());

Now, if you want to get the lowest qty available of these options, you can try something like

 

$qty = false;
foreach ($selectionCollection as $option) { $product_id = $option->product_id; $bundleOption = Mage::getModel('catalog/product')->load($product_id); $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($bundleOption); if ($qty === false) { $qty = $stock->getQty(); } else { $qty = min(array($qty, $stock->getQty())); } } echo $qty;
Did I help you solve your problem? Click Accept as Solution!
DudeSquare Web Development

Re: magento show quantity bundle product

Thank you for your answer

 

But where exactly should I put this code.

 

Regards

Re: magento show quantity bundle product

Wherever you want it to appear, for bundled products the file would be

 

app/design/frontend/{theme}/template/bundle/catalog/product/view/type/bundle/availability.phtml

There you can update

 

        <p class="availability in-stock">
            <span class="label"><?php echo $this->helper('catalog')->__('Availability:') ?></span>
            <span class="value"><?php echo $this->helper('catalog')->__('In stock') ?></span>
        </p>

to

 

<?php
$selectionCollection = $_product->getTypeInstance()->getSelectionsCollection($_product->getTypeInstance()->getOptionsIds());
$qty = false;
foreach ($selectionCollection as $option) {
    $product_id = $option->product_id;
    $bundleOption = Mage::getModel('catalog/product')->load($product_id);
    $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($bundleOption);
    if ($qty === false) {
        $qty = $stock->getQty();
    } else {
        $qty = min(array($qty, $stock->getQty()));
    }
}
?>


<p class="availability in-stock">
    <span class="label"><?php echo $this->helper('catalog')->__('Availability:') ?></span>
    <span class="value"><?php echo $qty . ' ' . $this->helper('catalog')->__('In stock') ?></span>
</p>

 

 

Did I help you solve your problem? Click Accept as Solution!
DudeSquare Web Development

Re: magento show quantity bundle product

Thanks!!!

Re: magento show quantity bundle product

Hi,

 

How can i remove the decimals i get now 18.000 and it has to be 18

And is it posible to divide the number through 6.

 

Becouse i have 18 single products is stock and i sell a box of 6. So 18 ÷ 6 = 3 boxes available

And if the products are 17 in stock the bundle has to shows 2 boxes available

Re: magento show quantity bundle product

Thanks for your answer , I want to check whether the bundled Item (Item not product) is available or not in order to show or not the label of it .

Thanks in advance!