简体   繁体   English

在Magento中过滤没有图像的产品

[英]Filter products without images in Magento

Requrement: We have a bunch of products with and without images. 配备:我们有很多带有和不带有图像的产品。 We only need to display products with images in the frontend. 我们只需要在前端显示带有图像的产品。

What I did: I have tried almost all the SO resources like: 我做了什么:我已经尝试了几乎所有的SO资源,例如:

Filter products without images on Magento frontend 在Magento前端过滤没有图像的产品

How can I find all products without images in Magento? 如何在Magento中找到所有没有图像的产品?

Hide Products without images magento 隐藏没有图像的产品magento

and their various combinations with no luck.. I think something changed in the new version of Magento. 以及它们的各种组合都没有运气。.我认为新版本的Magento中发生了一些变化。 I am using version 1.8.1.0 我正在使用版本1.8.1.0

Is somebody able to shed some lights here? 有人可以在这里开灯吗?

UPDATE: On my debugging, I found out that 更新:在调试中,我发现

->addAttributeToFilter('small_image', array('neq' => 'no_selection'))

really worked. 确实有效。 But an error occurs in layered price filter. 但是分层价格过滤器中会发生错误。 I was thinking this is not working earlier.I am getting the error similar to: Magento 1.7 price filter error (Column not found: 1054 Unknown column 'e.min_price' in 'where clause') ... 我以为这无法更早地工作。我收到类似于以下错误: Magento 1.7价格过滤器错误(未找到列:1054'where子句'中的未知列'e.min_price') ...

According to Royw's answer to the above question, I believe, we need to edit the file: Mage/Catalog/Model/Layer/Filter/price.php 根据Royw对上述问题的回答,我相信,我们需要编辑以下文件:Mage / Catalog / Model / Layer / Filter / price.php

你试过这个吗?

->addAttributeToFilter('small_image', array('neq' => 'no_selection'))

This can be done using Magento events. 这可以使用Magento事件来完成。 I added an observer for the event: 我为事件添加了一个观察者:

catalog_product_collection_load_before

which adds a filter to remove all the products without images when loading product collection. 会在加载产品集合时添加一个过滤器以删除所有没有图像的产品。 The observer is as follows: 观察者如下:

public function filterProductsWithoutImages($observer) {
    if (isset($observer['collection'])) {
        $collection = $observer['collection'];
        $collection->addAttributeToFilter('small_image', array('neq' => "no_selection"));
        return $this;
    }
}

Here we need to disable "Use Flat Catalog Product". 在这里,我们需要禁用“使用平面目录产品”。 For that: 为了那个原因:

Admin > Configuration > Catalog > Frontend > Use Flat Catalog Product to "No" 管理员>配置>目录>前端>使用平面目录产品为“否”

Since this filtering is not compatible with the use of "Flat Catalog Product" 由于此过滤与“平面目录产品”的使用不兼容

Product counts in search pages work fine with this. 搜索页面中的产品计数与此配合使用很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM