2013-10-22 123 views
4

我已经将捆绑产品sku与简单产品关联起来。magento获得捆绑产品下拉

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

$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类似的事情创建下拉列表。但是我无法访问这些方法。 有没有人有想法,我该怎么做。

回答

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

非常感谢!一直试图从过去3小时内得到这个! $ options = $ optionCollection-> appendSelections($ selectionCollection);诀窍! –