/** * On submission saved * @param AppEvent $event */ public static function saved($event) { $app = self::app(); $params = $event->getParameters(); $item = $params['item']; // add advert to cart if ($request = $item->getElementsByType('jbadvert')) { $redirect = false; foreach ($request as $element) { $request = $app->jbrequest->getArray('elements'); $elemId = $element->identifier; if (isset($request[$elemId]['gotocart']) && (int) $request[$elemId]['gotocart']) { $element->addToCart(); $redirect = true; } } if ($redirect) { JFactory::getApplication()->redirect($app->jbrouter->basket()); } } }
/** * After adminmenu items added * @param AppEvent $event */ public static function addMenuItems($event) { $app = self::app(); $params = $event->getParameters(); $controller = $app->jbrequest->getCtrl(); if (strpos($controller, 'jb') === 0) { $params['tab']->setAttribute('data-href-replace', 'controller=' . $controller); } $event->setReturnValue($params); }
/** * Execute all elements for system event (zoo trigger) * @param AppEvent $event * @return void */ public function fireElements(AppEvent $event) { $eventName = $this->app->jbvars->lower($event->getName(), true); // simple check if (!$eventName || !isset($this->_eventList[$eventName])) { return; } // prepare vars $eventData = $this->_eventList[$eventName]; $order = $event->getSubject(); $params = $event->getParameters(); // system events $cartConf = JBModelConfig::model()->getGroup('cart.' . JBCart::CONFIG_NOTIFICATION); $elements = $cartConf->get($eventData['name'], array()); $this->_execElements($event, $elements, $order, $params); // status events if (isset($eventData['status']) && $eventData['status']) { $cartConf = JBModelConfig::model()->getGroup('cart.' . JBCart::CONFIG_STATUS_EVENTS); $elements = $cartConf->get($eventData['status'] . '__' . $params['newStatus'], array()); $this->_execElements($event, $elements, $order, $params); } }
/** * After render some item layout (experemental) * @param AppEvent $event */ public static function afterRenderLayout($event) { $item = $event->getSubject(); $params = $event->getParameters(); $app = self::app(); if ($params['layout'] == 'full') { $app->jbviewed->add($item); } }
/** * On after edit view display * @param AppEvent $event */ public static function afterEdit($event) { $params = $event->getParameters(); if (isset($params['html'][0])) { $element = $event->getSubject(); $find = 'element-' . $element->getElementType(); $params['html'][0] = JString::str_ireplace($find, $find . ' element-' . $element->identifier, $params['html'][0]); } $event->setReturnValue($params); }
/** * InitApp event handler - hack for custom JBZoo controllers * @param AppEvent $event */ public static function initApp($event) { $zoo = App::getInstance('zoo'); $params = $event->getParameters(); $curApp = $params['application']; $currentCtrl = strtolower($zoo->request->getCmd('controller')); $jbzooCtrls = array('autocomplete', 'basket', 'compare', 'favorite', 'payment', 'search', 'viewed'); if (empty($curApp) || $curApp->getGroup() != JBZOO_APP_GROUP && in_array($currentCtrl, $jbzooCtrls)) { $jbzooApp = $zoo->table->application->first(array('conditions' => array('application_group="' . JBZOO_APP_GROUP . '"'))); if ($jbzooApp) { $params['application'] = $jbzooApp; $event->setReturnValue($params); } } }
/** * Parse current url (usually) and fix some urls bugs (from classical Zoo) * @param AppEvent $event */ public function sefParseRoute($event) { $this->_jbdebug->mark('jbzoo-sef::sefParseRoute::start'); $params = $event->getParameters(); // parse category or item by priority order if ($this->_config->get('parse_priority', 'item') == 'category') { // try to find category if (empty($params['vars']) || isset($params['vars']['category_id']) && $params['vars']['category_id'] == 0) { $params = $this->_parseCategoryUrl($params); } // try to find item if (empty($params['vars']) || isset($params['vars']['item_id']) && $params['vars']['item_id'] == 0) { $params = $this->_parseItemUrl($params); } } else { // try to find item if (empty($params['vars']) || isset($params['vars']['item_id']) && $params['vars']['item_id'] == 0) { $params = $this->_parseItemUrl($params); } // try to find category if (empty($params['vars']) || isset($params['vars']['category_id']) && $params['vars']['category_id'] == 0) { $params = $this->_parseCategoryUrl($params); } } // feed if (empty($params['vars']) && $this->_config->get('fix_feed', 0)) { $params = $this->_parseFeedUrl($params); } // redirect to correct url if ($this->_config->get('redirect', 0)) { $this->_checkRedirect($params); } // set new params $event->setReturnValue($params); $this->_jbdebug->mark('jbzoo-sef::sefParseRoute::finish'); }