magento产品详细信息 [英] Product details in magento

查看:94
本文介绍了magento产品详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have this code in my magento app

<?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())知道将获得数组列表.但是我在任何情况下都不会这样做

I know by simply print_r($order_details->getAllItems()) will get the array list.but im in no situation to do this

推荐答案

您需要加载完整的产品模型才能访问该数据.

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.

尝试一下:

<?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  ?>

这篇关于magento产品详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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