【问题标题】:Filter products without images in Magento在 Magento 中过滤没有图像的产品
【发布时间】:2014-12-31 16:50:55
【问题描述】:

要求:我们有一堆有图片和没有图片的产品。我们只需要在前端展示带有图片的产品。

我做了什么:我已经尝试了几乎所有的 SO 资源,例如:

Filter products without images on Magento frontend

How can I find all products without images in Magento?

Hide Products without images magento

以及它们的各种组合都没有运气。我认为新版本的 Magento 发生了一些变化。我使用的是 1.8.1.0 版本

有人可以在这里发光吗?

更新:在我的调试中,我发现

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

确实有效。但是在分层价格过滤器中出现错误。我在想这不是更早的工作。我收到类似于:Magento 1.7 price filter error (Column not found: 1054 Unknown column 'e.min_price' in 'where clause')...

根据Royw对上述问题的回答,我相信,我们需要编辑文件:Mage/Catalog/Model/Layer/Filter/price.php

【问题讨论】:

    标签: php magento filtering magento-1.8 product


    【解决方案1】:

    你试过了吗?

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

    【讨论】:

    • 在我的调试中,我发现这确实有效。但是在分层价格过滤器中出现错误。我在想这不是更早的工作。我收到类似于以下内容的错误:stackoverflow.com/questions/14997912/…... 这是错误报告中的内容:pastebin.com/1S5qyJdQ
    • 根据Royw的回答,我相信,我们需要编辑文件:Mage/Catalog/Model/Layer/Filter/price.php
    • 感谢您的回复:)
    • @Binod,如果对你有用,你能接受答案吗?
    • @Charlie 对不起,它实际上不是一个答案。我在问题中的链接中已经提到了您提供的代码。虽然我很欣赏你的回应
    【解决方案2】:

    这可以使用 Magento 事件来完成。我为事件添加了一个观察者:

    catalog_product_collection_load_before

    在加载产品集合时添加一个过滤器以删除所有没有图像的产品。观察者如下:

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

    这里我们需要禁用“使用平面目录产品”。为此:

    Admin > Configuration > Catalog > Frontend > Use Flat Catalog Product 为“否”

    由于此过滤与“平面目录产品”的使用不兼容

    搜索页面中的产品计数可以正常使用。

    【讨论】:

      猜你喜欢
      • 2014-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-14
      • 2014-09-19
      • 1970-01-01
      相关资源
      最近更新 更多