May be "clarification" is one of the reasons, I am posting a query about Magento 2 Observer here.
As I am trying to execute an event observer on sales_quote_collect_totals_after
event but it doesn't seem to run at all, when I do hard-refresh the Checkout/Cart page.
I have searched many online posts and tutorials, but every post seems to have different code and it goes a bit confusing at times, so my final question is how to get observer working with only observer class file and events xml ?
Learning/Custom/Model/Observer:
<?php
namespace Learning\Custom\Model;
use \Magento\Framework\Event\Observer;
use \Magento\Framework\Event\ObserverInterface;
class Observer implements ObserverInterface {
public function execute(Observer $observer) {
$event = $observer->getEvent();
$quote = $event->getQuote();
Mage::log(print_r(Zend_Debug::dump($quote->getData()), true),NULL, 'developer.log');
exit;
}
/*public function execute(\Magento\Framework\Event\Observer $observer) {
rm_state()->controllerSet($observer['controller_action']);
}*/
}
etc/frontend/events.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
<event name="sales_quote_collect_totals_after">
<observer name="learning_custom_event_obs" instance="Learning\Custom\Model\Observer" />
</event>
</config>
etc/module.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Learning_Custom" setup_version="1.0.0">
<sequence><module name="Magento_Core"/></sequence>
<sequence><module name="Magento_Store"/></sequence>
</module>
</config>