4

バンドル製品の 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 で同様のことを複製したい。ただし、これらのメソッドにアクセスできません。誰も私がそれを行う方法を知っていますか。

4

1 に答える 1

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();
    }
}
于 2013-10-25T04:39:30.003 に答える