Banning
Banning

Reputation: 2287

Can’t Access Custom Attributes

I’ve been looking all over for an answer to this. I’ve been using Magento for about a week now and Im fixing a bunch of templates that we messed up. Anyway I’m at a spot now that should probably be easy but its not working. I need to access and custom attribute… this code works.

standard attribute

$_product->getName()

but this code wont.. custom attribute of “designer”

$_product->getDesigner()

the original code from the developer had this.. however this code didn’t work either lol

$_helper->productAttribute($_product, $_product->getDesigner(), 'designer');

any help would be great thanks guys!

Upvotes: 0

Views: 1491

Answers (2)

Steve Robbins
Steve Robbins

Reputation: 13812

Make sure that $_product is an instance of Mage_Catalog_Model_Product, or set it to one with $_product = Mage::getModel("catalog/product")->load($_product->getId())

In addition to the "magic" getter of $_product->getDesigner() you could use getData() instead:

$_product = Mage::getModel("catalog/product")->load($_product->getId());
$_designer = $_product->getData('designer');

Upvotes: 1

chason
chason

Reputation: 36

How do you get $_product? Maybe u need to make a load.

$_product = Mage::getModel("catalog/product")->load($_product->getId());

Magento doesn't load all attributes of an model until you make an load.

Try to log all data in product by doing Mage::log($_product->getData()).

Upvotes: 2

Related Questions