/** * 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()); }
/** * @inheritdoc */ public function rules() { return [[['productListingSortId'], 'integer'], ['productListingSortId', 'default', 'value' => 1], ['productListingSortId', 'in', 'range' => array_keys(ProductListingSort::enabledSorts())], ['listViewType', 'default', 'value' => Yii::$app->getModule('shop')->listViewType], ['listViewType', 'in', 'range' => ['listView', 'blockView'], 'strict' => true], ['productsPerPage', 'default', 'value' => Yii::$app->getModule('shop')->productsPerPage], ['productsPerPage', 'integer', 'max' => 50], ['userCurrency', 'default', 'value' => CurrencyHelper::getMainCurrency()->iso_code], ['userCurrency', 'in', 'range' => Currency::getIsoCodes(), 'strict' => true]]; }
/** * @param array $products * @return array */ private function productsModelsToArray($products) { return array_reduce($products, function ($res, $item) { /** @var Product $model */ $model = $item['model']; $i = ['id' => $model->id, 'name' => $model->name, 'price' => CurrencyHelper::convertToMainCurrency($model->price, $model->currency), 'currency' => CurrencyHelper::getMainCurrency()->iso_code]; if (isset($item['quantity'])) { $i['quantity'] = $item['quantity']; } $res[] = $i; return $res; }, []); }