【问题标题】:Accessing Magento Custom Attribute访问 Magento 自定义属性
【发布时间】:2011-12-28 22:16:02
【问题描述】:

我有两个自定义属性,一个叫做“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() where $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;

【问题讨论】:

  • $product->getData() 是否显示自定义属性?

标签: magento custom-attributes


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-04
    • 2011-07-19
    • 1970-01-01
    • 2019-05-03
    • 2015-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多