简体   繁体   中英

Magento adding custom attribute in tabs.phtml

I need to add a custom attribute into the tabs.phtml file but when I do:

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

It throws me the following error:

Fatal error: Call to a member function getData() on a non-object in /var/www/vhosts/website.co.uk/httpdocs/app/design/frontend/customtemplate/default/template/catalog/product/view/tabs.phtml on line 102

$_product is NULL.

What am I missing here? Can anybody help me with this?

What are you looking to accomplish? tabs.phtml just loops through all the available tabs and displays their content. $this->getProduct will not work with this Block type.

$this->getProduct() will not be a product object

You would need to do this:

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

If this product then you can get product model at anywhere of product using registry variable

if it is product page then just call Mage::registry('current_product')->getData('color_availability');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM