Magento:从订单中获取固定捆绑订单项价格

时间:2017-06-19 21:10:10

标签: php magento magento-1.8

我现在正在使用Magento 1.8.x CE,我正试图获取固定捆绑包上的选项的订单项定价:

enter image description here

这是我目前用于测试的代码:

$orderId = 18562;
$order = Mage::getModel('sales/order')->load($orderId);

foreach ($order->getAllItems() as $item){ 
    echo $item->getPrice() . "<br>";
}

这是我得到的输出:

399.9900
0.0000
0.0000

知道如何从固定捆绑订单中获取订单项价格吗?

1 个答案:

答案 0 :(得分:2)

找到答案,不确定它是否是最佳做法,但它正在努力从订单中获得所有简单的产品价格(包括来自固定捆绑包)

foreach ($order->getAllItems() as $item){

    /* Simple Product */
    if(($item->getProduct()->getTypeID() == 'simple') && !$item->getParentItemId()){        
        $prices[] += $item->getPrice();
    }

    /* Bundle (Fixed & Dynamic) Products */
    if($item->getProduct()->getTypeID() == 'bundle'){
        $items = $item->getProductOptions();    
        $options = $items['bundle_options'];

        foreach ($options as $option) {             
            $price = $option['value'][0]['price'];      
            $prices[] = number_format((float)$price, 2, '.', '');
        }
    }   
}

echo '"' . implode($prices,', ') . '"';

这会输出原始问题中的示例,如下所示:

"349.99, 50.00"

相关问题