问题
I have two custom attributes, one called 'amz_prod_description' and one called 'upc'.
According to this > http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/0_-_theming_in_magento/data_accessing_methods_from_within_various_scopes#accessing_the_value_of_a_product_s_custom_attribute
I should be able to access them both $product->getUpc() and $product->getAmzProdDescription() where $product. In the same switch, I am using both of these. The 'upc' attribute var works fine, the other doesn't work at all which is really bugging the you-know-what out of me as they're both using the methodology that Magento calls for and in the same PHP function. So they're both in the same context, etc.
Help me!? :\
Here's my actual code for what it's worth >
case "{amazon_description}":
$description = $product->getAmzProdDescription();
// I have tested, $description is not being set. I have changed the bottom return to just $description and it returns nothing.
if(strlen($description) > 1499) {
$amz_description = substr($description,0,1500) . "...";
} else {
$amz_description = $description;
}
return $amz_description;
break;
case "{upc}":
$upc = $product->getUpc();
return $upc;
break;
回答1:
There's a flag in the attribute management in the Magento admin called "Visible on Product View Page on Front-end". Make sure that's set to "Yes" for both attributes, otherwise the attribute won't be built into the getData array. This assumes that your code is running in the frontend, although you haven't specified that.
Also make sure you rebuild indexes and flush the cache & cache storage.
来源:https://stackoverflow.com/questions/8661920/accessing-magento-custom-attribute