Пример #1
0
 public function checkForLogin(Varien_Event_Observer $observer)
 {
     if (Mage::app()->getWebsite()->getId() == Mage::helper("mey_b2b")->getWebsiteId()) {
         $allow = array('customer_account_login', 'customer_account_forgotpassword', 'customer_account_resetpassword', 'customer_account_loginpost', 'customer_account_forgotpasswordpost', 'customer_account_resetpasswordpost', 'customer_account_createb2b', 'customer_account_createb2bpost', 'customer_account_createb2bsuccess', 'mey_b2bcustomer_index_approve', 'mey_b2bcustomer_index_disapprove', 'turpentine_esi_getblock');
         $allowCms = array("/newsletter/", "/newsletter-abmelden/");
         $disallowRoute = false;
         if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
             if ($observer->getControllerAction()->getFullActionName() === "cms_page_view") {
                 $pathInfo = Mage::app()->getFrontController()->getRequest()->getOriginalPathInfo();
                 if (!in_array($pathInfo, $allowCms)) {
                     $disallowRoute = true;
                 }
             } else {
                 if (!in_array(strtolower($observer->getControllerAction()->getFullActionName()), $allow)) {
                     $disallowRoute = true;
                 }
             }
         }
         if ($disallowRoute) {
             $fullRequestUrl = Mage::app()->getRequest()->getScheme() . "://" . Mage::app()->getRequest()->getHttpHost() . Mage::app()->getRequest()->getRequestUri();
             Mage::getSingleton("customer/session")->setBeforeAuthUrl($fullRequestUrl);
             Mage::app()->getResponse()->setRedirect(Mage::helper("customer")->getLoginUrl())->sendResponse();
             exit;
         }
     }
 }
Пример #2
0
 /**
  * Appends the "sortable" js code to the bottom of ajax-Request for the category-products loaded after
  * changing sort order.
  *
  * @param Varien_Event_Observer $observer
  */
 public function addSortableScriptOnGrid($observer)
 {
     if (Mage::helper('hackathon_productdnd')->isActivated() && $observer->getControllerAction()->getRequest()->getParam('sort') == 'position') {
         $content = $observer->getControllerAction()->getResponse()->getBody();
         $content = $this->appendScript($content);
         $observer->getControllerAction()->getResponse()->setBody($content);
     }
 }
Пример #3
0
 /**
  * Set the current form key for Login form
  */
 public function SetFormKey(Varien_Event_Observer $observer)
 {
     $controller = $observer->getControllerAction();
     $request = $controller->getRequest();
     $form_key = Mage::getSingleton('core/session')->getFormKey();
     $request->setParam('form_key', $form_key);
 }
Пример #4
0
 public function actionAfter(Varien_Event_Observer $o)
 {
     if ($o->getEvent()->getControllerAction()->getFullActionName() == 'review_product_post') {
         Mage::dispatchEvent("review_product_post_after", array('request' => $o->getControllerAction()->getRequest()));
     }
     return $o;
 }
Пример #5
0
 /**
  * MageMagick_Protect_Model_Observer:checkAccess
  *
  *  This method checks if user have permissions for browse store,
  *  if have no permissions then  will be redirected on login page.
  *
  *  NOTE: I think would be better overwrite front controller,
  *  because observer not intended in general for implement tasks like this,
  *  but this was fastest way
  *
  * @param Varien_Event_Observer $observer
  * @return mixed
  */
 public function checkAccess(Varien_Event_Observer $observer)
 {
     if (0 === (int) Mage::getStoreConfig('protect/protect/enabled')) {
         return $this;
     }
     $isLoggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
     if (false != $isLoggedIn) {
         return $this;
     }
     $request = Mage::app()->getRequest();
     $response = $observer->getControllerAction()->getResponse();
     $moduleName = $request->getModuleName();
     $controllerName = $request->getControllerName();
     $action = $request->getActionName();
     // TODO: use Mage::app()->getStore()->isAdmin()
     if ($moduleName == 'admin') {
         return $this;
     }
     if ($moduleName != 'customer' && $moduleName != 'cms') {
         $this->_hardRedirect($request, $response, Mage::getUrl('/'));
     }
     self::$addSplashScreen = true;
     if ($moduleName == 'cms' && $controllerName == 'index') {
         self::$handleId = 'default';
         return $this;
     }
     if ($moduleName == 'customer') {
         self::$handleId = $action;
         return $this;
     }
     return $this;
 }
Пример #6
0
 public function getListproduct(Varien_Event_Observer $event)
 {
     $controller = $event->getControllerAction();
     $param = array();
     $ajaxcatalog = Mage::app()->getRequest()->getParam('ajaxcatalog');
     $layout = Mage::app()->getLayout();
     $blocks = array();
     if ($ajaxcatalog == 1) {
         //$templ = $layout->getBlock('product_list')->setTemplate('ajaxcatalog/list.phtml');
         /*
         			if($templ){
         				//@header('Content-type: application/json');
         				$blocks['toolbarlistproduct']	=	$templ->toHtml();
         				echo json_encode($blocks);
         				exit;
         			}
         
         			$templ = $layout->getBlock('search_result_list');
         			if($templ){
         				@header('Content-type: application/json');
         				$blocks['toolbarlistproduct']	=	$templ->toHtml();
         				echo json_encode($blocks);
         			}
         			exit;*/
     }
 }
Пример #7
0
 /**
  * This event is called when the MoTo order is saved. The event is fired after the controller action 'save' is executed.
  * The event is used to redirect the customer to the payment interface.
  */
 public function postOrderSave(Varien_Event_Observer $observer)
 {
     $controller = $observer->getControllerAction();
     $message = Mage::getSingleton('adminhtml/session')->getMessages()->getLastAddedMessage();
     if ($message == null) {
         return;
     }
     $messageType = $message->getType();
     $redirectLocation = $this->getRedirectionUrl($controller);
     Mage::getSingleton('adminhtml/session')->setCustomwebRedirectUrl($redirectLocation);
     $orderId = $this->extractOrderId($redirectLocation);
     if ($orderId) {
         $order = Mage::getModel('sales/order')->load($orderId);
         $payment = $order->getPayment();
         if (strpos($payment->getMethodInstance()->getCode(), 'saferpaycw') !== false) {
             Mage::helper('SaferpayCw')->log("Codes match.");
             if ($messageType == 'success') {
                 $order->addStatusToHistory(Customweb_SaferpayCw_Model_Method::SAFERPAYCW_STATUS_PENDING, Mage::helper('SaferpayCw')->__('Payment is pending at SaferpayCw'));
                 $order->save();
                 Mage::helper('SaferpayCw')->log("Redirect to Moto authorization");
                 Mage::getSingleton('adminhtml/session')->setIsUrlNotice($controller->getFlag('', Mage_Adminhtml_Controller_Action::FLAG_IS_URLS_CHECKED));
                 $controller->getResponse()->setRedirect(Mage::helper('adminhtml')->getUrl('*/motosaferpaycw/process', array('order_id' => $order->getId())));
             }
         }
     }
 }
Пример #8
0
 public function postdispatch(Varien_Event_Observer $event)
 {
     /* @var $controller Mage_Core_Controller_Varien_Action */
     $controller = $event->getControllerAction();
     if (!$controller->getRequest()->getHeader('X-Requested-With')) {
         return;
     }
     $param = array();
     $headers = Mage::app()->getRequest()->getParams();
     foreach ($headers as $headerName => $headerValue) {
         $headerName = strtolower($headerName);
         if (!preg_match('/tr(.*)/', $headerName, $regs)) {
             continue;
         }
         $param[str_replace('_', '.', $regs[1])] = $headerValue;
     }
     //orginal magento ajax request
     if (!count($param)) {
         return;
     }
     $layout = Mage::app()->getLayout();
     $blocks = array();
     foreach ($param as $blockName => $selector) {
         $temp = $layout->getBlock($blockName);
         $blocks[$blockName] = array('selector' => $selector, 'html' => $temp ? $temp->toHtml() : '');
     }
     echo json_encode($blocks);
     exit;
 }
Пример #9
0
 /**
  * Hook to record all fron controller events
  * @param Varien_Event_Observer $observer 
  */
 public function controller_action_predispatch(Varien_Event_Observer $observer)
 {
     try {
         if (extension_loaded('newrelic')) {
             $controllerAction = $observer->getControllerAction();
             $request = $controllerAction->getRequest();
             $controllerName = explode("_", $request->getControllerName());
             if (Mage::getStoreConfig('newrelic/settings/ignore_admin_routes') && $request->getRouteName() == 'adminhtml' || $request->getModuleName() == 'admin' || in_array('adminhtml', $controllerName)) {
                 Mage::Helper('newrelic')->setAppName(false);
                 newrelic_ignore_transaction();
                 newrelic_ignore_apdex();
                 return $this;
             }
             if (mage::helper('newrelic')->ignoreModule($request->getModuleName()) === true) {
                 Mage::Helper('newrelic')->setAppName(false);
                 newrelic_ignore_transaction();
                 newrelic_ignore_apdex();
                 return $this;
             }
             if (Mage::getStoreConfig('newrelic/settings/named_transactions')) {
                 $route = $request->getRouteName() . '/' . $request->getControllerName() . '/' . $request->getActionName();
                 if (Mage::getStoreConfig('newrelic/settings/add_module_to_named_transactions')) {
                     $route .= ' (module: ' . $request->getModuleName() . ')';
                 }
                 newrelic_name_transaction($route);
                 Mage::Helper('newrelic')->setAppName(true);
                 return $this;
             }
         }
     } catch (Exception $e) {
         mage::logException($e);
     }
 }
 /**
  * Listens for the controller_action_postdispatch_adminhtml Event to
  * check if an Admin that was sent to either:
  *   (a) My Account to associate a Two Factor Auth, or
  *   (b) interstitial page to enter their TFA value
  * is attempting to navigate away without performing the necessary TFA action
  *
  * @event controller_action_postdispatch_adminhtml
  * @param Varien_Event_Observer $observer
  * @return MageHackDay_TwoFactorAuth_Model_Observer
  */
 public function checkTfaSubmitted(Varien_Event_Observer $observer)
 {
     $request = $observer->getControllerAction()->getRequest();
     if ($request->getActionName() == 'logout' || !Mage::helper('twofactorauth')->isActive()) {
         return $this;
     }
     if ($request->getControllerName() == 'twofactorauth') {
         return $this;
     }
     $vRedirectUrl = '';
     if ($this->_getAdminhtmlSession()->getTfaNotAssociated()) {
         $vRedirectUrl = Mage::helper('adminhtml')->getUrl('adminhtml/twofactorauth/qr');
     } else {
         if ($this->_getAdminhtmlSession()->getTfaNotEntered()) {
             $vRedirectUrl = Mage::helper('adminhtml')->getUrl('adminhtml/twofactorauth/interstitial');
         }
     }
     if ($vRedirectUrl) {
         $vAction = $request->getActionName();
         Mage::app()->getFrontController()->getAction()->setFlag($vAction, Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, TRUE);
         $oResponse = Mage::app()->getResponse();
         $oResponse->setRedirect($vRedirectUrl);
         $oResponse->sendResponse();
     }
     return $this;
 }
Пример #11
0
 /**
  * Sets sku_autogenerate parameter
  * 
  * The parameter would usually be set via checkbox in the "quick create" form
  * but since the SKU field is now a label instead of a text field, it is not included.
  * 
  * @see Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Simple
  * @see event controller_action_predispatch_adminhtml_catalog_product_quickCreate
  * @param Varien_Event_Observer $observer
  */
 public function setAutogenerateSku(Varien_Event_Observer $observer)
 {
     $request = $observer->getControllerAction()->getRequest();
     $simpleProductRequest = $request->getParam('simple_product');
     $simpleProductRequest['sku_autogenerate'] = '1';
     $request->setParam('simple_product', $simpleProductRequest);
 }
Пример #12
0
 /**
  * Check Captcha On Product Reviews Page
  *
  * @param Varien_Event_Observer $observer
  *
  * @return Mage_Captcha_Model_Observer
  */
 public function checkReview($observer)
 {
     $formId = 'user_review';
     $captchaModel = Mage::helper('captcha')->getCaptcha($formId);
     if ($captchaModel->isRequired()) {
         $controller = $observer->getControllerAction();
         if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) {
             Mage::getSingleton('core/session')->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
             $data = $controller->getRequest()->getPost();
             Mage::getSingleton('review/session')->setFormData($data);
             if ($this->isOldMagento()) {
                 $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
                 if ($redirectUrl = Mage::getSingleton('review/session')->getRedirectUrl(true)) {
                     $controller->getResponse()->setRedirect($redirectUrl);
                     return $this;
                 }
                 $controller->getResponse()->setRedirect($this->_getRefererUrl($controller));
             } else {
                 //invalidate the formkey, which will force the controller to redirect back to referer
                 $controller->getRequest()->setParam('form_key', 'Incorrect CAPTCHA.');
             }
         }
     }
     return $this;
 }
Пример #13
0
 /**
  * Sets the coupon code on the quote or on the session
  *
  * @param Varien_Event_Observer $observer
  */
 public function addCodeToSession($observer)
 {
     $action = $observer->getControllerAction();
     if ($this->_isApplicable($action)) {
         $this->_helper->applyCodeFromRequest($action->getRequest());
     }
     return false;
 }
Пример #14
0
 public function customerLogout(Varien_Event_Observer $observer)
 {
     if (Mage::helper('redirection')->isEnabled() && Mage::helper('redirection')->isoptionEnabled('logout_redirection')) {
         if ($this->_CustomerGroup()) {
             $observer->getControllerAction()->setRedirectWithCookieCheck(Mage::helper('redirection')->setRedirectOnLogout());
         }
     }
 }
Пример #15
0
 /**
  * Add CMS page tag on all CMS pages except homepage
  *
  * @param Varien_Event_Observer $observer
  */
 public function addPageTag(Varien_Event_Observer $observer)
 {
     $pageId = $observer->getPage()->getIdentifier();
     $homePageId = Mage::getStoreConfig('web/default/cms_home_page');
     if ($pageId != $homePageId) {
         $observer->getControllerAction()->getLayout()->getUpdate()->addHandle('mbiz_trackingtags_page');
     }
 }
 /**
  * Postdispatch for Cart reconfigure action to update the mini cart
  * @param  Varien_Event_Observer $observer
  * @return void
  */
 public function controllerActionPostdispatchCheckoutCartUpdateItemOptions(Varien_Event_Observer $observer)
 {
     $controllerAction = $observer->getControllerAction();
     $response = Mage::app()->getResponse();
     if (!$controllerAction->getRequest()->isAjax()) {
         return;
     }
     $result = $this->_buildUpdateResponse($controllerAction);
     $this->_sendAjaxResponse($response, $result);
 }
Пример #17
0
 /**
  * paypal compatibility for "Require Customer To Be Logged In To Checkout" option
  */
 public function onPredispatchCustomerAccountLoginPost(Varien_Event_Observer $observer)
 {
     try {
         $http_reffer = $observer->getControllerAction()->getRequest()->getServer('HTTP_REFERER');
         if ($http_reffer && (strpos($http_reffer, "checkout/cart") !== false || strpos($http_reffer, "aitcheckout/checkout") !== false)) {
             Mage::getSingleton('customer/session')->setBeforeAuthUrl($http_reffer);
         }
     } catch (Exception $e) {
         Mage::logException($e);
     }
 }
Пример #18
0
 /**
  * Post dispatch proccess compress html file
  * 
  * @param Varien_Event_Observer $event
  */
 public function postDispatch(Varien_Event_Observer $event)
 {
     if (!Mage::getStoreConfig('psoptimizationhead/html/disable')) {
         return;
     }
     /* @var $controller Mage_Core_Controller_Varien_Action */
     $controller = $event->getControllerAction();
     $allHtml = $controller->getResponse()->getBody();
     $allHtml = PSystemHtmlMinify::min($allHtml);
     $controller->getResponse()->setBody($allHtml);
 }
Пример #19
0
 /**
  * Check if we're viewing a simple product with an active parent
  * 
  * @param Varien_Event_Observer $observer
  * 
  * @return void
  */
 public function checkForRedirect(Varien_Event_Observer $observer)
 {
     $productIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($observer->getControllerAction()->getRequest()->getParam('id'));
     if ($productIds && isset($productIds[0])) {
         // Only capture the first matched product id
         $this->_product = Mage::getModel("catalog/product")->load($productIds[0]);
         if ($this->_canRedirect()) {
             $this->_redirect();
         }
     }
 }
 /**
  * Redirects to custom url after logout if set in system > configuration > customer > startup
  *
  * @param Varien_Event_Observer $observer
  * @return $this
  */
 public function logoutRedirect(Varien_Event_Observer $observer)
 {
     if (!Mage::getStoreConfigFlag('customer/startup/redirect_logout')) {
         return $this;
     }
     $transportObj = new Varien_Object(array('url' => Mage::getStoreConfig('customer/startup/redirect_logout_url'), 'code' => 302));
     Mage::dispatchEvent('ambimax_logoutredirect', array('data' => $transportObj));
     /** @var Mage_Customer_AccountController $controller */
     $controller = $observer->getControllerAction();
     $controller->getResponse()->setRedirect($transportObj->getUrl(), $transportObj->getCode());
 }
Пример #21
0
 /**
  * @param Varien_Event_Observer $observer
  * @return $this
  */
 public function registerController(Varien_Event_Observer $observer)
 {
     $action = $observer->getControllerAction()->getFullActionName();
     switch ($action) {
         case 'adminhtml_report_shopcart_abandoned':
         case 'adminhtml_report_shopcart_exportAbandonedCsv':
         case 'adminhtml_report_shopcart_exportAbandonedExcel':
             Mage::register('abandonedcart_report', true);
             break;
     }
     return $this;
 }
Пример #22
0
 /**
  * Observer for contact
  *
  * @param Varien_Event_Observer $observer
  */
 public function contactAlert($observer)
 {
     $helper = Mage::helper('storealerts');
     $controllerAction = $observer->getControllerAction();
     $post = $controllerAction->getRequest()->getPost();
     $title = $helper->__('New message') . ': ' . $post['name'];
     $message = $helper->__('Name') . ': ' . $post['name'] . "\n" . $helper->__('Email') . ': ' . $post['email'] . "\n" . $helper->__('Telephone') . ': ' . $post['telephone'] . "\n";
     $message .= $helper->__('Comment') . ': ' . $post['comment'];
     $message = trim($message);
     $helper->saveAlert(ExtensionsStore_StoreAlerts_Model_Alert::CONTACT, $message, $title);
     return $observer;
 }
Пример #23
0
 /**
  * Process response by performing a search and replace on urls to be processed
  *
  * @param Varien_Event_Observer $observer
  */
 public function controller_action_postdispatch(Varien_Event_Observer $observer)
 {
     /** @var $helper Guidance_Cachebuster_Helper_Data */
     $helper = Mage::helper('guidance_cachebuster');
     if (!$helper->isEnabled()) {
         return;
     }
     $parser = $helper->getParser();
     $response = $observer->getControllerAction()->getResponse();
     $body = $parser->parseHtml($response->getBody());
     $response->setBody($body);
 }
Пример #24
0
 /**
  * Observes controller_action_postdispatch_adminhtml_catalog_product_action_attribute_save
  *
  * Save related product sets
  *
  * @param   Varien_Event_Observer $observer
  * @return  PWS_RelatedProductSets_Model_Observer
  */
 public function saveRelatedProductSetsMassAction(Varien_Event_Observer $observer)
 {
     $controller_action = $observer->getControlerAction();
     //var_dump($observer->getControllerAction()->getRequest()->getParams());
     $product_set_id_add = $observer->getControllerAction()->getRequest()->getParam('product_set_id_add', null);
     $position_add = $observer->getControllerAction()->getRequest()->getParam('position_add', null);
     $product_set_id_remove = $observer->getControllerAction()->getRequest()->getParam('product_set_id_remove', null);
     $selectedProductsIds = Mage::getSingleton('adminhtml/session')->getProductIds();
     $store_id = (int) $observer->getControllerAction()->getRequest()->getParam('store', 0);
     // build data array
     $data_add = array();
     if ($product_set_id_add) {
         for ($i = 0; $i < count($product_set_id_add); $i++) {
             $data_add[$product_set_id_add[$i]]['position'] = isset($position_add[$i]) ? $position_add[$i] : 0;
         }
     }
     $data_remove = array();
     if ($product_set_id_remove) {
         for ($i = 0; $i < count($product_set_id_remove); $i++) {
             $data_remove[] = $product_set_id_remove[$i];
         }
     }
     //var_dump($data_add);
     //var_dump($data_remove);
     foreach ($selectedProductsIds as $_selectedProductId) {
         $selectedProduct = Mage::getModel('catalog/product');
         $selectedProduct->setData(array());
         $selectedProduct->setStoreId($store_id)->load($_selectedProductId)->setIsMassupdate(true)->setExcludeUrlRewrite(true);
         if (!$selectedProduct->getId()) {
             continue;
         }
         $relatedProductSetsModel = Mage::getModel('pws_relatedproductsets/relatedproductsets');
         if ($data_add) {
             $relatedProductSetsModel->saveRelatedSetProducts($selectedProduct->getId(), $data_add);
         }
         if ($data_remove) {
             $relatedProductSetsModel->removeRelatedSetProducts($selectedProduct->getId(), $data_remove);
         }
     }
 }
Пример #25
0
 /**
  * login facebook user as a customer.
  * @param Varien_Event_Observer $observer
  */
 public function loginCustomer(Varien_Event_Observer $observer)
 {
     $controller = $observer->getControllerAction();
     if ($controller->getFullActionName() == 'customer_account_index') {
         $userId = $this->getMageApp()->getRequest()->getParam('user_id');
         if ($userId) {
             /** @var Alaa_FacebookConnect_Model_User $user */
             $user = $this->getFacebookUser()->load($userId);
             if ($user->getId()) {
                 $this->login($user->getCustomerObject());
             }
         }
     }
 }
 /**
  * Add product relations to alsoviewed_log table
  *
  * @param Varien_Event_Observer $observer
  */
 public function catalogProductView(Varien_Event_Observer $observer)
 {
     $session = $this->_getSession();
     $productId = $observer->getControllerAction()->getRequest()->getParam('id');
     $viewedIds = $session->getViewedProductIds();
     if (!$viewedIds) {
         $viewedIds = array();
     }
     if ($productId && !in_array($productId, $viewedIds)) {
         if (count($viewedIds)) {
             Mage::getResourceModel('alsoviewed/log')->insertRelations($productId, $viewedIds);
         }
         $session->addViewedProductId($productId);
     }
 }
Пример #27
0
 /**
  * Check when caching should be enabled. Caching can still be disabled
  * before the response is sent.
  *
  * @param Varien_Event_Observer $observer
  */
 public function controllerActionPredispatch(Varien_Event_Observer $observer)
 {
     if (Mage::registry('diehard')) {
         return;
     }
     Mage::register('diehard', $this->helper());
     if ($this->helper()->isEnabled() && Mage::app()->getRequest()->isGet()) {
         $fullActionName = $observer->getControllerAction()->getFullActionName();
         $lifetime = $this->helper()->isCacheableAction($fullActionName);
         if ($lifetime) {
             // Set current request as cacheable for the given lifetime
             $this->helper()->setLifetime($lifetime);
         }
     }
 }
Пример #28
0
 /**
  * Break the execution in case of incorrect CAPTCHA
  *
  * @param Varien_Event_Observer $observer
  * @return Your_Module_Model_Observer
  */
 public function checkCaptcha($observer)
 {
     $formId = 'contact_form';
     $captchaModel = Mage::helper('captcha')->getCaptcha($formId);
     if ($captchaModel->isRequired()) {
         $controller = $observer->getControllerAction();
         if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) {
             Mage::getSingleton('customer/session')->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
             $controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
             Mage::getSingleton('customer/session')->setCustomerFormData($controller->getRequest()->getPost());
             $controller->getResponse()->setRedirect(Mage::getUrl('*/*/index'));
         }
     }
     return $this;
 }
 /**
  * Postdispatch for Cart Add Action to sniff for Ajax Add
  * @param  Varien_Event_Observer $observer 
  * @return void
  */
 public function controllerActionPostdispatchCheckoutCartAdd(Varien_Event_Observer $observer)
 {
     /* @var $coreHelper Mage_Core_Helper_Abstract */
     $coreHelper = Mage::helper('core');
     $controllerAction = $observer->getControllerAction();
     $response = Mage::app()->getResponse();
     $responseCode = 200;
     if (!$controllerAction->getRequest()->isAjax()) {
         return;
     }
     $result = $this->_buildResponse($observer, $controllerAction, $coreHelper);
     $response->clearAllHeaders();
     $responseCode = $result['status'] === self::STATUS_SUCCESS ? 200 : 520;
     $response->setHttpResponseCode($responseCode);
     $response->clearHeaders()->setHeader('Content-Type', 'application/json')->setBody($coreHelper->jsonEncode($result));
 }
 /**
  * Hook build/save widget action and inject rule as parameters to post
  *
  * @param Varien_Event_Observer $observer
  */
 public function onControllerActionPredispatch($observer)
 {
     /** @var Mage_Core_Controller_Request_Http $request */
     $request = $observer->getControllerAction()->getRequest();
     $action = $request->getActionName();
     $controller = $request->getControllerName();
     if ($action == 'buildWidget' && $controller == 'widget' || $action == 'save' && $controller == 'widget_instance') {
         $rule = $request->getPost('rule', array());
         if (!empty($rule)) {
             $params = $request->getPost('parameters', array());
             // Serialize, encode and inject rule to post parameters
             $params['rule'] = base64_encode(serialize($rule));
             $request->setPost('parameters', $params);
         }
     }
 }