Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, I finally got it working the way i think it should.</p> <p>Wgenie put me in the right direction.</p> <p>I use this code instead of Wgenie's and it not only adds the item to the cart but controls the stock of the bundle options and shows Not available if one option is out of stock:</p> <pre><code>&lt;?php if ($_item-&gt;getTypeId() == 'bundle') : ?&gt; &lt;form action="&lt;?php echo Mage::helper('checkout/cart')-&gt;getAddUrl($_item); ?&gt;" method="post" id="product_addtocart_form_&lt;?php echo $_item-&gt;getId()?&gt;"&gt; &lt;?php $selectionCollection = $_item-&gt;getTypeInstance(true)-&gt;getSelectionsCollection( $_item-&gt;getTypeInstance(true)-&gt;getOptionsIds($_item), $_item ); ?&gt; &lt;?php $saleable = true; ?&gt; &lt;?php foreach($selectionCollection as $option) : ?&gt; &lt;input type="hidden" name="bundle_option[&lt;?php echo $option-&gt;option_id; ?&gt;][]" value="&lt;?php echo $option-&gt;selection_id; ?&gt;" /&gt; &lt;input type="hidden" name="bundle_option_qty[&lt;?php echo $option-&gt;option_id; ?&gt;][]" value="1" /&gt; &lt;?php //Stock control for each bundle option $opt_product = Mage::getModel('catalog/product')-&gt;load($option-&gt;product_id); $stocklevel = (int)Mage::getModel('cataloginventory/stock_item') -&gt;loadByProduct($opt_product)-&gt;getQty(); if($stocklevel&lt;=0) $saleable = false; ?&gt; &lt;?php endforeach; ?&gt; &lt;?php if($saleable): ?&gt; &lt;button type="button" title="&lt;?php echo $this-&gt;__('Add to Cart') ?&gt;" class="button" onclick="this.form.submit()"&gt;&lt;span&gt;&lt;span&gt;&lt;?php echo $this-&gt;__('Add to Cart') ?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/button&gt; &lt;?php else: ?&gt; &lt;p class="availability out-of-stock"&gt;&lt;span&gt;&lt;?php echo $this-&gt;__('Out of stock') ?&gt;&lt;/span&gt;&lt;/p&gt; &lt;?php endif; ?&gt; &lt;/form&gt;&lt;?php else : ?&gt; &lt;button type="button" title="&lt;?php echo $this-&gt;__('Add to Cart') ?&gt;" class="button" onclick="setLocation('&lt;?php echo $this-&gt;getAddToCartUrl($_item) ?&gt;')"&gt;&lt;span&gt;&lt;span&gt;&lt;?php echo $this-&gt;__('Add to Cart') ?&gt;&lt;/span&gt;&lt;/span&gt;&lt;/button&gt;&lt;?php endif; ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload