protected static function getPrice(Product $model, $mainCurrency, $price) { return number_format(CurrencyHelper::convertCurrencies($price, $model->currency, $mainCurrency), 2, '.', '') . ' ' . $mainCurrency->iso_code; }
/** * */ public static function handlePurchase() { if (null === ($order = Order::getOrder())) { return; } /** @var Currency $currency */ $currency = static::$currency; $ya = ['action' => 'purchase', 'currency' => $currency->iso_code, 'orderId' => $order->id, 'products' => []]; foreach ($order->items as $item) { $ya['products'][] = ['id' => $item->product->id, 'name' => $item->product->name, 'category' => self::getCategories($item->product), 'price' => CurrencyHelper::convertCurrencies($item->product->price, $item->product->currency, $currency), 'quantity' => $item->quantity]; } $js = 'window.DotPlantParams = window.DotPlantParams || {};'; $js .= 'window.DotPlantParams.ecYandex = ' . Json::encode($ya) . ';'; \Yii::$app->getView()->registerJs($js, View::POS_BEGIN); }
/** * @param YmlModel $config * @param Product $model * @return OfferTag|null */ private function offerSimplified(YmlModel $config, Product $model) { $offer = new OfferTag('offer', [], ['id' => $model->id, 'available' => 'true']); $price = static::getOfferValue($config, 'offer_price', $model, 0); $price = CurrencyHelper::convertCurrencies($price, $model->currency, $this->currency); if ($price <= 0 || $price >= 1000000000) { return null; } $values = []; $name = static::getOfferValue($config, 'offer_name', $model, null); if (true === empty($name)) { return null; } if (mb_strlen($name) > 120) { $name = mb_substr($name, 0, 120); $name = mb_substr($name, 0, mb_strrpos($name, ' ')); } $values[] = new OfferTag('name', htmlspecialchars(trim(strip_tags($name)))); $values[] = new OfferTag('price', $price); $values[] = new OfferTag('currencyId', $this->currency->iso_code); /** @var Category $category */ if (null === ($category = $model->category)) { return null; } $values[] = new OfferTag('categoryId', $category->id); $values[] = new OfferTag('url', Url::toRoute(['@product', 'model' => $model, 'category_group_id' => $category->category_group_id], true)); $picture = static::getOfferValue($config, 'offer_picture', $model, static::$_noImg); if (static::$_noImg !== $picture) { $picture = htmlspecialchars(trim($picture, '/')); $picture = implode('/', array_map('rawurlencode', explode('/', $picture))); $values[] = new OfferTag('picture', trim($config->shop_url, '/') . '/' . $picture); } $description = static::getOfferValue($config, 'offer_description', $model, null); if (false === empty($description)) { if (mb_strlen($description) > 175) { $description = mb_substr($description, 0, 175); $description = mb_substr($description, 0, mb_strrpos($description, ' ')); } $values[] = new OfferTag('description', htmlspecialchars(trim(strip_tags($description)))); } if (static::USE_OFFER_PARAM == $config->offer_param) { foreach (static::getOfferParams($model) as $k => $v) { $values[] = new OfferTag('param', $v['value'], ['name' => $k, 'unit' => $v['unit']]); } } return $offer->setValue($values); }