2

I need to filter blank image product in Magento from catalog and catalogsearch. But it working fine on catalog. bt not fine in catalog search.

I got error when search product in search....

  Column not found: 1054 Unknown column 'e.small_image' in 'where clause'"

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Nine_Catalog>
            <version>1.0.0</version>
        </Nine_Catalog>
    </modules>
    <global>
        <events>
            <catalog_block_product_list_collection>
                <observers>
                    <filter_blank_image> // unique idrntifer
                        <type>model</type>
                        <class>Nine_Catalog_Model_Observer</class>
                        <method>filterBlankImage</method>
                    </filter_blank_image>
                </observers>
            </catalog_block_product_list_collection>
        </events>
    </global>
</config>

Observer.php

class Nine_Catalog_Model_Observer extends Varien_Event_Observer
{

    public function filterBlankImage(Varien_Event_Observer $observer)
    {
        $collection = $observer->getEvent()->getCollection();
        return  $collection->addAttributeToFilter('small_image',array('neq'=>'no_selection'));
    }

}
0

If you enable catalog product flat setting then may be small_image column is not created at catalog_product_flat_YourStoreId table.So please reindex catalog product from admin Index Management.

If small_image column is not create then add below code to config. xml for enable this attribute to flat.

<frontend>
    <product>
        <collection>
            <attributes>
                <small_image/>
                <small_image_label/>
            </attributes>
        </collection>
    </product>
</frontend>

Code Observer code:

<?php
class Nine_Catalog_Model_Observer extends Varien_Event_Observer{

    public function filterBlankImage(Varien_Event_Observer $observer)
    {

        $collection = $observer->getEvent()->getCollection();
        $collection->addAttributeToFilter('small_image',array('notnull'=>'','neq'=>'no_selection'));
        return $this;
    }
}

If this not work then must issue with indexing See at another example how to filter blank image product collection by observer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.