2014-01-27 52 views
0

我添加的屬性「項的具有admin.I輸入類型文本要顯示在購物cart.For該屬性,我已經在template/checkout/cart/sidebar-top.phtml其中加入此代碼的值低於:如何在購物車中顯示屬性的值?

<?php 
     $productId = $_item->getId(); 
     $productInfo = Mage::getModel("catalog/product")->load($productId); 
     echo $productInfo->getAttributeText('product_type'); 
?> 

但當我添加上面的代碼顯示

Fatal error: Call to a member function getId() on a non-object 

如果有人知道這一點,請幫我out.thanks!

回答

0

使用下面的代碼

$productId = $_item->getProduct()->getId(); 
$productInfo = Mage::getModel("catalog/product")->load($productId); 
echo $productInfo->getAttributeText('product_type'); 
+0

我加入這個代碼,然後顯示錯誤 致命錯誤:調用一個成員函數getProduct()一個非對象 –

+0

你可以檢出$ _item-> getCount將(); – MagentoDiary

0

你說的是自定義選項,或簡單的屬性?

對於簡單的屬性(文本),如果你是在產品頁面嘗試貝羅代碼:

<?php $_item = $this->getItem()?> 
<?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProductId()) ?> 
<?php echo $_product->getResource()->getAttribute('attribute_code')->getFrontend()->getValue($_product); ?> 

如果您不是在產品頁面上,那麼你可以使用下面的代碼,通過SKU加載的產品和讓你的屬性值

$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku()); 
echo $product->getResource()->getAttribute('attribute_code')->getFrontEnd()->getValue($product); 
+0

當我添加上面的代碼顯示致命錯誤:調用一個非對象 –

+0

上的成員函數getProductId()是否真的調用產品對象並根據需要獲取產品數據? – Slimshadddyyy

+0

我在管理'項目'中添加了一個屬性,輸入類型爲'textbox'。無論我在管理中添加什麼值,它都應該在購物車中顯示....多數情況下 以及上面給出的任何代碼,我使用過在頁面中顯示錯誤在非對象 –

相關問題