【问题标题】:Change addAttributeToFilter in new products widget (Magento 1.9.0)在新产品小部件中更改 addAttributeToFilter (Magento 1.9.0)
【发布时间】:2015-02-23 17:52:07
【问题描述】:

我正在尝试编辑此代码

->addAttributeToFilter('news_from_date', array('or'=> array(
            0 => array('date' => true, 'to' => $todayEndOfDayDate),
            1 => array('is' => new Zend_Db_Expr('null')))
        ), 'left')
        ->addAttributeToFilter('news_to_date', array('or'=> array(
            0 => array('date' => true, 'from' => $todayStartOfDayDate),
            1 => array('is' => new Zend_Db_Expr('null')))
        ), 'left')
        ->addAttributeToFilter(
            array(
                array('attribute' => 'news_from_date', 'is'=>new Zend_Db_Expr('not null')),
                array('attribute' => 'news_to_date', 'is'=>new Zend_Db_Expr('not null'))
                )
          )

用这个替换

->addAttributeToFilter('featured', array('is' => 1))

app\code\core\Mage\Catalog\Block\Product\New.php

CMS -> PAGE 我自然有我的小部件

{{widget type="catalog/product_widget_new" display_type="new_products" products_count="16" template="catalog/product/widget/new/content/new_grid.phtml"}}

现在我不明白为什么如果我在我的主页中更改 New.php 中的任何内容,我会得到相同的结果。这个过滤器不起作用。我哪里错了?

【问题讨论】:

    标签: php magento magento-1.9


    【解决方案1】:

    这可能是过滤器不起作用,因为您使用的是平面产品集合,并且您的 featured 属性没有打开“用于产品列表”。

    试试这个:

    $collection->addFieldToFilter(array(array('attribute' => 'featured', 'eq' => 1)));
    

    【讨论】:

    • 你说得对!!!我正在使用平面产品和平面类别,现在我启用了“在产品列表中使用”并插入您的代码,但结果没有改变。我认为文件的路径是正确的,但是当我尝试删除文件时我不明白我没有错误。这是正常的???其他建议???
    【解决方案2】:

    **

    解决了!!!解决方法很简单!

    **

    不要编辑 新产品小部件 或更改 magento 的文件,但是 最好创建新的 cms 静态块。如果你按照这个步骤 想要创建您的特色产品。

    第 1 步

    属性 -> 管理属性中创建新属性

    • 属性代码:特色
    • 范围:商店视图
    • 在产品列表中使用:

    管理标签/选项

    • 管理员:特色产品
    • 默认商店视图:特色产品

    不要忘记管理属性集

    第 2 步

    复制你的list.phtml

    app/design/frontend/base/default/template/catalog/product/list.phtml

    app\design\frontend\default\yourtemplate\template\catalog\product\list.phtml

    收件人

    app\design\frontend\default\yourtemplate\template\catalog\product\listFeatured.phtml

    打开 listFeatured.phtml 并找到它:

    $_productCollection=$this->getLoadedProductCollection();
    

    更改为:

    $_product = Mage::getModel('catalog/product');
    $attribute = $_product->getResource()->getAttribute("featured");
    
    // Check the attribute from a select or multiselect
    if($attribute->usesSource()):
    
        $options = $attribute->getSource()->getAllOptions(false);
        $idValue = 0;
    
        //Save the option's Id  if the label is "Yes"
        foreach ($options as $option):          
            if ($option['label'] == "Yes"):
                $idValue = $option['value'];
            endif;
        endforeach;
    
    endif;
    
    $_productCollection = $_product->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('featured', $idValue) // Filter the collection   
    ->setPage(1,16); //show max 1 page for 16 rows
    $_productCollection->getSelect()->order('rand()');
    

    第 3 步

    创建您的 CMS 静态块

    • 块标题:精选
    • 标识符:特色产品
    • 状态:已启用
    • 内容:{{block type="catalog/product_list" template="catalog/product/listFeatured.phtml"}}

    第 4 步

    在您的 CMS -> 页面中插入您的 CMS 静态块

    第 5 步

    转到管理产品并编辑您的产品以更改特色属性。

    第 6 步

    重新索引索引。

    【讨论】:

      【解决方案3】:

      直接替换

      ->addAttributeToFilter('featured', array('is' => 1))
      

      ->addAttributeToFilter('featured', array('eq' => 1))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多