0

我的 magento 应用程序中有此代码

<?php
$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId(); 
$order_details = Mage::getModel('sales/order')->loadByIncrementId($order_id);  

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

//here i know we can get item name as $item->getName(), sku as $item->getSku()
//but how do we get the following details
//1.category name,2.store,3.tax,city,country,state   

<?php }  ?>

我知道只是print_r($order_details->getAllItems())会得到数组列表。但我在任何情况下都不会这样做

4

2 回答 2

2

此项目与产品不同,它们不具有所有属性。你可以做一个Mage::getModel('catalog/product')->load($item->getProductId());快速的方法来测试一些东西,但这会为循环中的每个项目添加一个额外的查询到 mysql。或者我建议编辑 sales xml -> Mage > Sales > etc > config.xml (在本地模块中)。您应该将要从产品复制到项目的属性添加到节点 sales_convert_quote_item 或 sales_convert_order_item。在您的情况下,它将是 sales_convert_order_item 节点,因为您正在处理订单。

于 2013-08-19T08:05:03.207 回答
1

You need to load the full product model to access that data.

The collection you are loading is not of products, it's a collection of Order Items, which has minimal data associated with it. You need to load the full product model, by getting the product if from the Order Item.

try this:

<?php
$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId(); 
$order_details = Mage::getModel('sales/order')->loadByIncrementId($order_id);  
?>
<?php foreach ($order_details->getAllItems() as $item): ?> 
    <?php $product = Mage::getModel('catalog/product')->load($item->getProductId()) ?>
    <?php echo $product->getName() ?>
    <?php // now you have the full product model/data loaded ?>
<?php endforeach  ?>
于 2013-08-19T08:01:06.743 回答