2

I'm trying to observe the catalog_product_collection_load_before event so that I can filter out products with a certain attribute on the frontend (whether a product is discontinued). I am able to observe the event in the adminhtml scope, but not frontend. Code as follows:

etc/config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Jps_ProductDiscontinuation>
            <version>0.0.1</version>
        </Jps_ProductDiscontinuation>
    </modules>
    <global>
        <models>
            <jps_productdiscontinuation>
                <class>Jps_ProductDiscontinuation_Model</class>
            </jps_productdiscontinuation>
        </models>
        <events>
            <catalog_product_collection_load_before>
                <observers>
                    <jps_productdiscontinuation>
                        <class>jps_productdiscontinuation/observer</class>
                        <method>filterOutDiscontinued</method>
                        <type>singleton</type>
                    </jps_productdiscontinuation>
                </observers>
            </catalog_product_collection_load_before>
        </events>
    </global>
</config>

/Model/Observer.php:

class Jps_ProductDiscontinuation_Model_Observer {
    public function filterOutDiscontinued(Varien_Event_Observer $observer) {
        Mage::log("Event observed ~ jps 7/21/2017");
        $collection = $observer->getEvent()->getCollection();
//        $collection->addAttributeToFilter('discontinued', array('eq' => 'yes'));

        return $this;
    }
}

I don't believe it's an issue with my code because I logged the output of the dispatchEvent method in Mage.php while loading a category list on the frontend and catalog_product_collection_load_before was never dispatched, only in admin. This is on a dev server with settings that might vary slightly from production. Any idea what might suppress the event on the frontend or some sort of event related setting that might be related?

Edit: the event is dispatched and dispatch is confirmed through logging dispatchEvent().

Update: Per @sv3n's advice I installed Firegento and determined that the observers were not actually recognized. Through changing:

<class>jps_productdiscontinuation/observer</class>

to:

<class>Jps_Discontinuation_Model_Observer</class>

I was able to get them to appear in the Firegento observer list, but they're appearing under the incorrect module. Magento thinks they're part of the Netzarbeiter_GroupsCatalog2 module in the community code pool when they're part of their own module in the local code pool.

15
  • 1
    You are trying this at catalog view page?
    – sv3n
    Commented Jul 21, 2017 at 15:59
  • 1
    It should be there .... use it on my own. (1.9CE)
    – sv3n
    Commented Jul 21, 2017 at 16:06
  • 1
    Can you try catalog_product_collection_load_after? Both should be fired.
    – sv3n
    Commented Jul 21, 2017 at 16:09
  • 1
    Tested your code ... and it works on frontend. So please make sure all extension files are in correct place and extension is loaded. I've no further idea so far.
    – sv3n
    Commented Jul 21, 2017 at 19:14
  • 1
    No :) I'm happy about every accepted answer, but as long it's not resolved, it should stay open. And I'm interessed in what causes this, so please leave a comment when you've found the reason. :)
    – sv3n
    Commented Jul 21, 2017 at 21:21

1 Answer 1

0

Try this:

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Jps_ProductDiscontinuation>
            <version>0.0.1</version>
        </Jps_ProductDiscontinuation>
    </modules>
    <global>
        <models>
            <jps_productdiscontinuation>
                <class>Jps_ProductDiscontinuation_Model</class>
            </jps_productdiscontinuation>
        </models>
        <helpers>
            <jps_productdiscontinuation>
                <class>Jps_ProductDiscontinuation_Helper</class>
            </jps_productdiscontinuation>
        </helpers>
    </global>
    <frontend>
        <events>
            <catalog_product_collection_load_before>
                <observers>
                    <Jps_Productdiscontinuation_Observer>
                        <type>singleton</type>
                        <class>jps_productdiscontinuation/observer</class>
                        <method>filterOutDiscontinued</method>
                    </Jps_Productdiscontinuation_Observer>
                </observers>
            </catalog_product_collection_load_before>
        </events>
    </frontend>
</config>
1
  • Unfortunately, this doesn't do anything. There's no helper defined - I'm not sure what including it in the config is supposed to do? Changing the scope of the event observer doesn't help because it's the frontend that I cannot view the events in.
    – derivative
    Commented Jul 21, 2017 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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