magento获得捆绑产品下拉菜单

时间:2013-10-22 15:47:30

标签: php magento magento-1.7

我已将捆绑产品sku与简单产品相关联。

现在我正在尝试获取捆绑的产品选项。

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

我使用了上面的代码,但它返回了捆绑下的所有简单产品。 但我想要一系列选项。 从选项中我想要选择数组,以便我可以迭代并为每个捆绑选项创建下拉列表

我查看了核心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>

我想在view.phtml上复制类似的东西。但是我无法访问这些方法。 有谁知道我该怎么做。

1 个答案:

答案 0 :(得分:12)

$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();
    }
}