Skip to content

Commit

Permalink
Merge pull request #330 from angoliar/yml
Browse files Browse the repository at this point in the history
Yml wip
  • Loading branch information
bethrezen authored Feb 16, 2020
2 parents c3ef8e9 + 9b47d58 commit 87728f0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions application/messages/ru/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@
'Offer delivery' => 'Доставка',
'Offer description' => 'Описание',
'Offer name' => 'Наименование',
'Offer old price' => 'Старая цена',
'Offer pickup' => 'Самовывоз',
'Offer picture' => 'Изображение',
'Offer price' => 'Цена',
Expand Down
22 changes: 15 additions & 7 deletions application/modules/shop/components/yml/Yml.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use yii\helpers\Json;
use yii\helpers\Url;
use yii\web\View;
use app\modules\image\models\Image;

class Yml extends Component
{
Expand Down Expand Up @@ -119,7 +120,7 @@ public function generate()
$output = $view->renderFile($this->viewFile, $outputParams);

$fileName = Yii::getAlias('@webroot') . '/' . $config->general_yml_filename;
$result = static::USE_GZIP === $config->use_gzip
$result = static::USE_GZIP == $config->use_gzip
? file_put_contents($fileName . '.gz', gzencode($output), 5)
: file_put_contents($fileName, $output);

Expand Down Expand Up @@ -324,7 +325,8 @@ private function offerSimplified(YmlModel $config, Product $model)
if ($price <= 0 || $price >= 1000000000) {
return null;
}

$oldPrice = static::getOfferValue($config, 'offer_old_price', $model, 0);
$oldPrice = CurrencyHelper::convertCurrencies($oldPrice, $model->currency, $this->currency);
$values = [];

$name = static::getOfferValue($config, 'offer_name', $model, null);
Expand All @@ -337,6 +339,9 @@ private function offerSimplified(YmlModel $config, Product $model)
}
$values[] = new OfferTag('name', htmlspecialchars(trim(strip_tags($name))));
$values[] = new OfferTag('price', $price);
if ($oldPrice > 0 && $oldPrice < 1000000000) {
$values[] = new OfferTag('oldprice', $oldPrice);
}
$values[] = new OfferTag('currencyId', $this->currency->iso_code);

/** @var Category $category */
Expand All @@ -350,11 +355,14 @@ private function offerSimplified(YmlModel $config, Product $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);
/** @var Image[] $model->images */
foreach ($model->images as $image) {
$picture = $image->file;
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);
Expand Down
5 changes: 5 additions & 0 deletions application/modules/shop/models/Yml.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function rules()
'currency_id',
'offer_name',
'offer_price',
'offer_old_price',
'offer_category',
'offer_picture',
'general_yml_filename',
Expand Down Expand Up @@ -64,6 +65,7 @@ public function attributes()
'currency_id',
'offer_name',
'offer_price',
'offer_old_price',
'offer_category',
'offer_picture',
'offer_description',
Expand All @@ -90,6 +92,7 @@ public function attributeLabels()
'currency_id' => Yii::t('app', 'Main currency'),
'offer_name' => Yii::t('app', 'Offer name'),
'offer_price' => Yii::t('app', 'Offer price'),
'offer_old_price' => Yii::t('app', 'Offer old price'),
'offer_picture' => Yii::t('app', 'Offer picture'),
'offer_description' => Yii::t('app', 'Offer description'),
'offer_category' => Yii::t('app', 'Offer category'),
Expand Down Expand Up @@ -127,6 +130,7 @@ public function init()
'currency_id' => 'RUR',
'offer_name' => ['type' => 'field', 'key' => 'name'],
'offer_price' => ['type' => 'field', 'key' => 'price'],
'offer_old_price' => ['type' => 'field', 'key' => 'old_price'],
'offer_category' => ['type' => 'field', 'key' => 'main_category_id'],
'offer_picture' => ['type' => 'relation', 'key' => 'getImage', 'value' => 'file'],
'offer_description' => ['type' => 'field', 'key' => 'content'],
Expand Down Expand Up @@ -176,6 +180,7 @@ public function getOfferElements()
return [
'offer_name',
'offer_price',
'offer_old_price',
'offer_category',
'offer_picture',
'offer_description',
Expand Down

0 comments on commit 87728f0

Please # to comment.