请帮助我解决问题。我需要从magento购物车中获取捆绑产品,而不是我需要获得每个捆绑产品的选定项目。我怎样才能做到这一点?感谢名单!
答案 0 :(得分:6)
在magento 1.8.1中
$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $_item) :
$_product = Mage::getModel('catalog/product')->load($_item->getProduct()->getId());
if($_product->getTypeId()==='bundle') :
$options = $_item->getProduct()->getTypeInstance(true)->getOrderOptions($_item->getProduct());
?>
<dl class="item-options">
<?php foreach ($options['bundle_options'] as $option):?>
<dt><?php echo $option['label'] ?></dt>
<?php foreach ($option['value'] as $sub) :?>
<dd><?php echo $sub['qty'] . " x " . $sub['title'] . " " . Mage::helper('core')->currency($sub['price']) ?></dd>
<?php endforeach;
endforeach;
?>
</dl>
<?php endif;
endforeach
答案 1 :(得分:1)
$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 )
{
$product_simple = Mage::getModel('catalog/product')->load($selection->getId());
}
}
希望这对你有用。 :)
祝你好运。
答案 2 :(得分:0)
$_product = Mage::getModel('catalog/product')->load($_item->getProduct()->getId());
if($_product->getTypeId()==='bundle') {
$options = $_item->getProduct()->getTypeInstance(true)->getOrderOptions($_item->getProduct());
?>
<dl class="item-options">
<?php
foreach ($options['bundle_options'] as $option) {?>
<dt><?php echo $option['label'] ?></dt>
<dd><?php echo $option['value'][0]['title'] ?></dd>
<?php
}
?>
</dl>
<?php }
此工作用于捆绑项目的输入类型“下拉列表”