/** * Install handlers */ public static function installHandlers(ActionEvent $event) { $currency = \Yii::$app->getModule('seo')->analytics['ecYandex']['currency']; if (AnalyticsHandler::CURRENCY_MAIN === intval($currency)) { static::$currency = CurrencyHelper::getMainCurrency(); } elseif (AnalyticsHandler::CURRENCY_USER === intval($currency)) { static::$currency = CurrencyHelper::getUserCurrency(); } else { static::$currency = CurrencyHelper::findCurrencyByIso($currency); } $route = implode('/', [$event->action->controller->module->id, $event->action->controller->id, $event->action->id]); Event::on(CartController::className(), CartController::EVENT_ACTION_ADD, [self::className(), 'handleCartAdd'], false); Event::on(CartController::className(), CartController::EVENT_ACTION_REMOVE, [self::className(), 'handleRemoveFromCart'], false); Event::on(CartController::className(), CartController::EVENT_ACTION_QUANTITY, [self::className(), 'handleChangeQuantity'], false); Event::on(CartController::className(), CartController::EVENT_ACTION_CLEAR, [self::className(), 'handleClearCart'], false); Event::on(Controller::className(), Controller::EVENT_PRE_DECORATOR, [self::className(), 'handleProductShow']); if ('shop/cart/index' === $route) { self::handleCartIndex(); } YandexAnalyticsAssets::register(\Yii::$app->getView()); }
/** * Fill $app->controllerMap property for auto run action classes */ private function fillControllerMap() { $modulesPath = \Yii::getAlias("@app/modules"); $modulesDir = new \DirectoryIterator($modulesPath); foreach ($modulesDir as $moduleDir) { if ($moduleDir->isDir() && !$moduleDir->isDot()) { $moduleId = $moduleDir->getBasename(); $controllersPath = $modulesPath . '/' . $moduleId . '/controllers'; $controllersDir = new \DirectoryIterator($controllersPath); foreach ($controllersDir as $controllerDir) { if ($controllerDir->isDir() && !$controllerDir->isDot()) { $controllerId = $controllerDir->getBasename(); $pathOfDefinedController = $controllersPath . '/' . ucfirst($controllerId) . 'Controller'; $namespaceOfDefinedController = "app\\modules\\{$moduleId}\\controllers\\" . ucfirst($controllerId) . 'Controller'; $modulesConfig = $this->application->modules; $modulesConfig[$moduleId]['controllerMap'][$controllerId] = file_exists($pathOfDefinedController) ? $namespaceOfDefinedController : Controller::className(); $this->application->modules = $modulesConfig; } } } } }