【问题标题】:Cannot access new product attributes in grid display无法在网格显示中访问新产品属性
【发布时间】:2010-04-12 22:26:02
【问题描述】:

我为我的产品添加了几个新属性(布尔“是/否”字段)。它们是用于启用/禁用在产品详细信息页面和网格视图上显示价格的变量。

我设法让它在产品信息页面上运行。但是在产品网格页面上,我似乎无法访问这些变量。具体来说,我正在使用的模板是catalog/product/list.phtml。

我尝试将它们添加到 xml 文件中,例如这样的 layout/catalog.xml:

<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
    <action method="addAttribute"><name>DisplayPrice</name></action>
    <action method="addAttribute"><name>CustomOrder</name></action>               

</block>

我正在尝试访问目录/产品/list.phtml中的属性:

<?php echo $_product->getDisplayPriceName()? "Yes" : "No" ; echo $_product->getCustomOrderName()? "Yes" : "No" ;?>

我还在 Mage 配置文件 app/code/core/Catalog/etc/config.xml 中添加了:

<frontend>
<!---- stuff before this -->
        <product>
            <collection>
                <attributes>
                    <name />
                    <url_key />
                    <price />
                    <special_price />
                    <custom_order />      <!--new attribute -->
                    <display_price />     <!--new attribute -->
                    <special_from_date />
                    <special_to_date />
                    <short_description />
                    <thumbnail />
                    <small_image />
                    <image_label />
                    <thumbnail_label />
                    <small_image_label />
                    <tax_class_id />
                    <status />
                    <news_from_date />
                    <news_to_date />
                    <created_at />
                    <updated_at />
                </attributes>
            </collection>
        </product>
    </frontend>

此时我在黑暗中拍摄。我对 Magento 后端的了解不够多,不知道我还需要去哪里或看什么。任何反馈将不胜感激。

提前致谢。

【问题讨论】:

    标签: php zend-framework magento


    【解决方案1】:

    在加载您的产品时,指定您想要加载的自定义属性。默认情况下,Magento 不会加载它们。尽管我认为应该加载。

    $products = Mage::getModel('catalog/product')->getCollection()
        ->addAttributeToSelect("custom_order")
        ->addAttributeToSelect("display_price ") 
    ;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-14
      • 2012-01-26
      • 2021-01-02
      • 2015-02-19
      • 1970-01-01
      • 2014-10-22
      • 2015-12-30
      相关资源
      最近更新 更多