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.
catalog_product_collection_load_after
? Both should be fired.