Note that there are some explanatory texts on larger screens.

plurals
  1. POCatching Magento Events With Observer
    primarykey
    data
    text
    <p>My observer does not seem to be catching events emitted by Magento v1.12.0.2. I'm following a tutorial very closely from <a href="http://inchoo.net/ecommerce/magento/dispatching-before-and-after-events-to-magento-core-actions/" rel="nofollow">http://inchoo.net/ecommerce/magento/dispatching-before-and-after-events-to-magento-core-actions/</a> and cannot seem to reproduce.</p> <p><strong>app/etc/modules/Require_Additional_Product.xml</strong>:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;config&gt; &lt;modules&gt; &lt;RequireAdditionalProduct&gt; &lt;active&gt;true&lt;/active&gt; &lt;codePool&gt;local&lt;/codePool&gt; &lt;/RequireAdditionalProduct&gt; &lt;/modules&gt; &lt;/config&gt; </code></pre> <p><strong>app/code/local/Hatclub/RequireAdditionalProduct/etc/config.xml</strong>:</p> <p> </p> <pre><code>&lt;modules&gt; &lt;RequireAdditionalProduct&gt; &lt;version&gt;1.0.0&lt;/version&gt; &lt;/RequireAdditionalProduct&gt; &lt;/modules&gt; &lt;global&gt; &lt;models&gt; &lt;dispatcher&gt; &lt;class&gt;Hatclub_RequireAdditionalProduct_Model&lt;/class&gt; &lt;/dispatcher&gt; &lt;/models&gt; &lt;events&gt; &lt;!-- Hooking to Magento's default event "controller_action_predispatch" --&gt; &lt;controller_action_predispatch&gt; &lt;observers&gt; &lt;controller_action_before&gt; &lt;class&gt;dispatcher/observer&lt;/class&gt; &lt;method&gt;hookToControllerActionPreDispatch&lt;/method&gt; &lt;/controller_action_before&gt; &lt;/observers&gt; &lt;/controller_action_predispatch&gt; &lt;!-- Hooking to Magento's default event "controller_action_postdispatch" --&gt; &lt;controller_action_postdispatch&gt; &lt;observers&gt; &lt;controller_action_after&gt; &lt;class&gt;dispatcher/observer&lt;/class&gt; &lt;method&gt;hookToControllerActionPostDispatch&lt;/method&gt; &lt;/controller_action_after&gt; &lt;/observers&gt; &lt;/controller_action_postdispatch&gt; &lt;!-- Hooking to our own event "add_to_cart_before" --&gt; &lt;add_to_cart_before&gt; &lt;observers&gt; &lt;add_to_cart_before&gt; &lt;class&gt;dispatcher/observer&lt;/class&gt; &lt;method&gt;hookToAddToCartBefore&lt;/method&gt; &lt;/add_to_cart_before&gt; &lt;/observers&gt; &lt;/add_to_cart_before&gt; &lt;!-- Hooking to our own event "add_to_cart_after" --&gt; &lt;add_to_cart_after&gt; &lt;observers&gt; &lt;add_to_cart_after&gt; &lt;class&gt;dispatcher/observer&lt;/class&gt; &lt;method&gt;hookToAddToCartAfter&lt;/method&gt; &lt;/add_to_cart_after&gt; &lt;/observers&gt; &lt;/add_to_cart_after&gt; &lt;/events&gt; &lt;/global&gt; </code></pre> <p></p> <p><strong>app/code/local/Hatclub/RequireAdditionalProduct/Model/Observer.xml</strong>:</p> <p> <pre><code>class Hatclub_RequireAdditionalProduct_Model_Observer { //this is hook to Magento's event dispatched before action is run public function hookToControllerActionPreDispatch($observer) { error_log('test 1', 0); //we compare action name to see if that's action for which we want to add our own event if($observer-&gt;getEvent()-&gt;getControllerAction()-&gt;getFullActionName() == 'checkout_cart_add') { //We are dispatching our own event before action ADD is run and sending parameters we need Mage::dispatchEvent("add_to_cart_before", array('request' =&gt; $observer-&gt;getControllerAction()-&gt;getRequest())); } } public function hookToControllerActionPostDispatch($observer) { error_log('test 1', 0); //we compare action name to see if that's action for which we want to add our own event if($observer-&gt;getEvent()-&gt;getControllerAction()-&gt;getFullActionName() == 'checkout_cart_add') { //We are dispatching our own event before action ADD is run and sending parameters we need Mage::dispatchEvent("add_to_cart_after", array('request' =&gt; $observer-&gt;getControllerAction()-&gt;getRequest())); } } public function hookToAddToCartBefore($observer) { error_log('test 1', 0); //Hooking to our own event $request = $observer-&gt;getEvent()-&gt;getRequest()-&gt;getParams(); // do something with product Mage::log("Product ".$request['product']." will be added to cart."); } public function hookToAddToCartAfter($observer) { error_log('test 1', 0); // Hooking to our own event $request = $observer-&gt;getEvent()-&gt;getRequest()-&gt;getParams(); // do something with product Mage::log("Product ".$request['product']." is added to cart."); } } </code></pre> <p>I'm simply trying to get output so that I know the observer is catching the event (through the use of php error_log, and Mage::log). Neither are outputting anything, so it seems that this is not working at all. Can anyone spot where I'm going wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload