Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.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
禁用在magento主页上具有占位符图像的产品_Magento_Random - Fatal编程技术网

禁用在magento主页上具有占位符图像的产品

禁用在magento主页上具有占位符图像的产品,magento,random,Magento,Random,我使用随机代码在magento动力商店的主页上显示不同类别的产品。这很好用。现在,我想排除所有的产品,其中只有一个占位符图像显示在主页上。我使用以下代码进行了尝试: class Mage_Catalog_Block_Product_List_Random extends Mage_Catalog_Block_Product_List { protected function _getProductCollection() { if (is_null($this-&

我使用随机代码在magento动力商店的主页上显示不同类别的产品。这很好用。现在,我想排除所有的产品,其中只有一个占位符图像显示在主页上。我使用以下代码进行了尝试:

class Mage_Catalog_Block_Product_List_Random extends Mage_Catalog_Block_Product_List
{
    protected function _getProductCollection()
    {
        if (is_null($this->_productCollection)) {
            $categoryID = $this->getCategoryId();
            if($categoryID)
            {
              $category = new Mage_Catalog_Model_Category();
              $category->load($categoryID); // this is category id
              $collection = $category->getProductCollection();
            } else
            {
              $collection = Mage::getResourceModel('catalog/product_collection');
            }
            Mage::getModel('catalog/layer')->prepareProductCollection($collection);
            $collection->getSelect()->order('rand()');
            $collection->addStoreFilter();
            $numProducts = $this->getNumProducts() ? $this->getNumProducts() : 3;
            $collection->setPage(1, $numProducts)->load();

            $collection->addAttributeToFilter(
                array('attribute' => 'small_image', 'eq' => ''),
                array('attribute' => 'small_image', 'eq' => 'no_selection')
            );

            $this->_productCollection = $collection;
        }
        return $this->_productCollection;
    }
} 
但这不起作用,只有占位符图像的产品仍然会出现

任何帮助都将不胜感激

谢谢,
Daniel

在已加载收藏后,您正在添加“小图像”过滤器,因此您的过滤器将不再影响收藏

除此之外,我觉得你的过滤器很奇怪。假设“no_selection”也是某个占位符图像,那么您的过滤器确实接受占位符图像,我认为您应该拒绝它们

尝试改用AND筛选器:

$collection->addAttributeToFilter(
    array('attribute' => 'small_image', 'neq' => '')
);
$collection->addAttributeToFilter(
    array('attribute' => 'small_image', 'neq' => 'no_selection')
);

在已加载集合后,您将添加“小图像”筛选器,因此您的筛选器将不再影响集合

除此之外,我觉得你的过滤器很奇怪。假设“no_selection”也是某个占位符图像,那么您的过滤器确实接受占位符图像,我认为您应该拒绝它们

尝试改用AND筛选器:

$collection->addAttributeToFilter(
    array('attribute' => 'small_image', 'neq' => '')
);
$collection->addAttributeToFilter(
    array('attribute' => 'small_image', 'neq' => 'no_selection')
);