Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

magento get bundled product dropdowns

I have associated a bundle product sku with simple product.

Now I am trying to fetch bundled product options.

$selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection(
      $bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product 

I have used the above code but it returns me all simple product under bundled. But i want the array of options. From options i want array of selections so that i can iterate and create dropdown for every bundled option

I looked into the core select.phtml

<select onchange="bundle.changeSelection(this)" id="bundle-option-<?php echo $_option->getId() ?>" name="bundle_option[<?php echo $_option->getId() ?>]" class="bundle-option-<?php echo $_option->getId() ?><?php if ($_option->getRequired()) echo ' required-entry' ?> bundle-option-select change-container-classname">

                <option value=""><?php echo $this->__('Choose a option') ?></option>
            <?php foreach ($_selections as $_selection): ?>
                <option value="<?php echo $_selection->getSelectionId() ?>"<?php if ($this->_isSelected($_selection)) echo ' selected="selected"' ?><?php if (!$_selection->isSaleable()) echo ' disabled="disabled"' ?>><?php echo $this->getSelectionTitlePrice($_selection, false) ?></option>
            <?php endforeach; ?>
            </select>

I want to replicate similar thing on view.phtml. However i am not able access those methods. Does anyone has idea how do i do that.

like image 557
Satyendra Mishra Avatar asked Dec 16 '22 05:12

Satyendra Mishra


1 Answers

$optionCollection = $product->getTypeInstance()->getOptionsCollection();
$selectionCollection = $product->getTypeInstance()->getSelectionsCollection($product->getTypeInstance()->getOptionsIds());
$options = $optionCollection->appendSelections($selectionCollection);
foreach( $options as $option )
{
    $_selections = $option->getSelections();
    foreach( $_selections as $selection )
    {
        echo  $selection->getName();
    }
}
like image 184
Satyendra Mishra Avatar answered Dec 23 '22 21:12

Satyendra Mishra