Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在新产品小部件(Magento 1.9.0)中更改addAttributeToFilter_Php_Magento_Magento 1.9 - Fatal编程技术网

Php 在新产品小部件(Magento 1.9.0)中更改addAttributeToFilter

Php 在新产品小部件(Magento 1.9.0)中更改addAttributeToFilter,php,magento,magento-1.9,Php,Magento,Magento 1.9,我正在尝试编辑此代码 ->addAttributeToFilter('news_from_date', array('or'=> array( 0 => array('date' => true, 'to' => $todayEndOfDayDate), 1 => array('is' => new Zend_Db_Expr('null'))) ), 'left') ->

我正在尝试编辑此代码

->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中更改任何内容,我会得到相同的结果。这个过滤器坏了。我错在哪里?

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

请尝试以下方法:

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

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

不要编辑新产品小部件或更改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\listfected.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静态块

  • 作品名称:精选
  • 标识符:featuredprod
  • 状态:已启用
  • 内容:
    {{block type=“catalog/product_list”template=“catalog/product/listfected.phtml”}
步骤4

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

步骤5

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

步骤6

重新索引。

只需替换

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


你说得对!!!我使用的是平面产品和平面类别,现在我启用了“用于产品列表”并插入代码,但结果不变。我认为该文件的路径是正确的,但我不明白当试图删除该文件时,我没有错误。正常吗???其他建议???
->addAttributeToFilter('featured', array('eq' => 1))