访问 Magento 自定义属性

发布于 2024-12-23 06:13:28 字数 1357 浏览 0 评论 0原文

我有两个自定义属性,一种称为“amz_prod_description”,一种称为“upc”。

根据这个> 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

我应该能够访问它们 $product->getUpc() 和$product->getAmzProdDescription() 其中 $product.在同一个交换机中,我同时使用这两个。 'upc' 属性 var 工作正常,另一个根本不起作用,这真的让我很烦恼,因为它们都使用 Magento 要求的方法并且在同一个 PHP 函数中。所以它们都处于相同的上下文中,等等。

帮助我!? :\

这是我的实际代码,它的价值>

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;

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷︶言冷语的世界 2024-12-30 06:13:28

Magento 管理员的属性管理中有一个标志,称为“在前端的产品视图页面上可见”。确保这两个属性都设置为“Yes”,否则该属性将不会构建到 getData 数组中。这假设您的代码在前端运行,尽管您尚未指定。

还要确保重建索引并刷新缓存和缓存。缓存存储。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文