4

I've a problem, I want to show the label of a custom attribute in the product page. I explain me better, starting from this link because is what I want to do: http://www.customy.com/blog/how-to-display-video-on-magento-product-page/

I want a video product in the sidebar of the product page, so I create a new custompage.phtml and i put this in the sidebar from catalog.xml, in my custompage.phtml I put this code to have the custom label:

getResource()->getAttribute('video')->getStoreLabel();?>

but I have this error:

"Fatal error: Call to a member function getResource() on a non-object in ..path//"

I have try different code but still have this problem. I think that I forget to put something in my .phtml but I'm new of Magento and I don't know what!

Thank in advance!

2 Answers 2

6

Since $_product didn't work then you'll need to load the object before attempting to access the attribute. Try this:

$product_id = Mage::registry('current_product')->getId();
$_product=Mage::getModel('catalog/product')->load($product_id);
echo $_product->getResource()->getAttribute('video')->getStoreLabel();
0
1

If you don't have access to the product model, I wrote a small query to get it from DB. This could be done better, but should be a decent starting point for your class:

protected $_dbConn;

public function __construct()
{
    $this->_dbConn = Mage::getSingleton('core/resource')->getConnection('core_read');
}

public function getAttributeLabel($code)
{
    $query = "
    SELECT b.value
    FROM eav_attribute a
    JOIN eav_attribute_label b
    ON a.attribute_id = b.attribute_id
    WHERE a.attribute_code = '".$code."'";

    return $this->_dbConn->fetchOne($query);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.