如何在成功页面上获得捆绑产品的选项? [英] How do I get the options for bundled products on the success page?

查看:74
本文介绍了如何在成功页面上获得捆绑产品的选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在成功页面上,我毫不费力地获得了使用以下代码购买的产品的列表:

On the success page, I have no trouble getting a list of the products purchased with the following code:

$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
foreach ($order->getAllItems() as $item){
   $subtotal = number_format($item->getSubtotal(),2);
}

我不知道的是如何获取捆绑产品的对象或选项数组.这些是标准选项,例如产品的颜色.

What I can't figure out, is how to get an object or an array of the options for bundled products. These are standard options like what color a product is.

推荐答案

我尚未对捆绑产品进行专门的尝试,但是下面的代码可用于可配置产品,并且我确定您可以根据需要进行修改以适合您的产品情况.

I have not specifically tried this with bundled products, but the code below works with configurable products, and I'm sure you can modify it as needed to fit your situation.

$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
foreach ($order->getAllItems() as $item){
  $productOptions = $item->getProductOptions();
    if (isset($productOptions['attributes_info'])) {
      foreach ($productOptions['attributes_info'] as $productOption) {
        echo $label = $productOption['label']; 
        echo '<br />'; 
        echo $value = $productOption['value'];  
    }  
  }
}

我的建议是从广泛的角度(即在$item级别)开始,看看Magento的回报(使用Zend_Debug::dump($item->getData()),然后逐步解决您的需求).

My suggestion is to start broad (i.e. at the $item level), see what Magento returns (using Zend_Debug::dump($item->getData()), and then work your way down to what you need.

希望有帮助.

这篇关于如何在成功页面上获得捆绑产品的选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆