2014-09-23 196 views
1

我需要添加自定義屬性到tabs.phtml文件,但是當我做:Magento的添加自定義屬性,tabs.phtml

<?php 
    $_product = $this->getProduct(); 
    echo $_product->getData('color_availability'); 
?> 

它拋出我下面的錯誤:

致命錯誤:在/var/www/vhosts/website.co.uk/httpdocs/app/design/frontend/customtemplate/default/template/catalog/product/view/tabs.phtml上的非對象中調用成員函數getData()在線102

$ _product爲NULL。

我在這裏錯過了什麼?任何人都可以幫助我嗎?

+0

您是否在產品頁面上進行操作? – 2014-09-24 01:41:25

+1

如果是產品頁面,則只需調用Mage :: registry('current_product') - > getData('color_availability'); – 2014-09-24 01:42:42

+0

簡單而有效 – human 2014-09-24 08:10:54

回答

0

如果該產品,那麼你可以在產品的任何地方使用註冊表中獲得的產品型號變量

如果是產品頁面,則只需致電Mage::registry('current_product')->getData('color_availability');

4

你期望完成什麼? tabs.phtml只是遍歷所有可用的選項卡並顯示其內容。 $ this-> getProduct不適用於此Block類型。

$這個 - > getProduct()不會是一個產品對象

你需要做的是:

<?php 
    //Get the current product 
    $productId = Mage::registry('current_product')->getId(); 
    //Load the current product 
    $_product = Mage::getModel('catalog/product')->load($productId); 
    //Get the attribute data of the loaded product 
    $color_availability = $_product->getData('color_availability'); 
    //This may not work. Depends upon what kind of attribute color_availability is 
    //If this doesn't work let me know 
?> 
<!-- echo the value --> 
<?php echo $color_availability ;?>