我想在Magento订单成功页面上获取简单的产品数据。我有以下代码:
$order = Mage::getSingleton('sales/order')->load($orderId, 'increment_id');
$items = $order->getAllVisibleItems();
foreach($items as $item) {
$product = Mage::getModel('catalog/product')->load($item->getProductId());
echo '"identifier":"'.$product->getSku().'",';
echo '"amount":"'.$product->getPrice().'",';
仍然,它显示了可配置的产品而不是简单的产品(实际上是订购的)。那么,我怎样才能获得简单的产品?
谢谢!
答案 0 :(得分:0)
添加此内容;
$order = Mage::getSingleton('sales/order')->load($orderId, 'increment_id');
$items = $order->getAllItems();
foreach($items as $item) {
$product = Mage::getModel('catalog/product')->load($item->getProductId());
if($product->getTypeId() == 'simple' ) {
echo '"identifier":"'.$product->getSku().'",';
echo '"amount":"'.$product->getPrice().'",';
}
}