0

In some situations, custom catalog_product attributes that I've created aren't loaded with the rest of the product data. So take the custom attribute, multiplier.

I want to display the multiplier attribute right next to the price attribute in the Mage_Catalog_Block_Product_Price block. However, the instance of the model that I get from $_product = $this->getProduct(); doesn't include this custom attribute.

Now I know there are some tricks to get it to load, for instance:

$_product = $this->getProduct();
$_product = $_product->load($_product->getId());

Or I can add the attribute when selecting the product

Mage::getModel('catalog/product')
     ->getCollection()
     ->addAttributeToSelect('multiplier')

But I'd rather avoid this. Instead, I think I've done something wrong to cause my custom attributes to not be loaded by default along with system attributes. I'd like to correct the problem at the root, but I don't know how to do that.

Edit:

I have found that setting Use in Product Listings to Yes for this attribute fixes the problem. However, I'm not sure if that's a good idea. Won't some themes end up listing this with other attributes like Color and Size?

1

Use in Product Listings to Yes and Visible on Product View Page on Front-end to Yes is standard Magento approach and this is the easiest and good solution. It doesn't cause of another problem on product listing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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