Compare View

switch
from
...
to
 
Commits (4)
Showing 596 changed files   Show diff stats

Too many changes.

To preserve performance only 100 of 596 files are displayed.

.gitignore
... ... @@ -33,7 +33,6 @@ phpunit.phar
33 33  
34 34 # vagrant runtime
35 35 /.vagrant
36   -/artweb/
37 36 /storage
38 37 /common/config/settings.php
39 38  
... ...
artweb/artbox-catalog/CHANGELOG.md 0 → 100755
  1 +# Change Log
  2 +All notable changes to this project will be documented in this file.
  3 +
  4 +## 1.0.0 - 2017-03-21
  5 +### Added
  6 +- This CHANGELOG file to hopefully serve as an evolving example of a standardized open source project CHANGELOG.
  7 +- Added initial Artbox Core extension.
0 8 \ No newline at end of file
... ...
artweb/artbox-catalog/LICENSE.md 0 → 100755
  1 +The Yii framework is free software. It is released under the terms of
  2 +the following BSD License.
  3 +
  4 +Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)
  5 +All rights reserved.
  6 +
  7 +Redistribution and use in source and binary forms, with or without
  8 +modification, are permitted provided that the following conditions
  9 +are met:
  10 +
  11 + * Redistributions of source code must retain the above copyright
  12 + notice, this list of conditions and the following disclaimer.
  13 + * Redistributions in binary form must reproduce the above copyright
  14 + notice, this list of conditions and the following disclaimer in
  15 + the documentation and/or other materials provided with the
  16 + distribution.
  17 + * Neither the name of Yii Software LLC nor the names of its
  18 + contributors may be used to endorse or promote products derived
  19 + from this software without specific prior written permission.
  20 +
  21 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24 +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25 +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27 +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28 +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29 +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30 +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31 +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32 +POSSIBILITY OF SUCH DAMAGE.
... ...
artweb/artbox-catalog/README.md 0 → 100755
  1 +Artbox Catalog
  2 +===============================
  3 +
  4 +Artbox Catalog is an extension for working with product catalog developed by Artweb written with [Yii 2 framework](http://www.yiiframework.com/).
  5 +
  6 +Core extension includes functionality for product control, brands, categories and options. This will allow you to connect product with brand, categories and enhance them with particular options.
  7 +
  8 +This extension is enough to develop web catalog, but not full ecommerce. For that purpose you'll need Order extension.
  9 +
  10 +To prepare your application you should run migrations:
  11 +
  12 + php yii migrate --migationPath=vendor/artweb/artbox-catalog/migrations
  13 +
  14 +DIRECTORY STRUCTURE
  15 +-------------------
  16 +
  17 +```
  18 +assets contains AssetBundles
  19 +behaviors contains Behaviors classes
  20 +components contains custom Classes, which don't belong to other groups
  21 +controllers contains controllers for core models
  22 +helpers contains helper classes to manipulate, for example static files
  23 + and HTML
  24 +messages contains translations for core strings
  25 +migrations contains migrations, which should be applied after extension
  26 + installation
  27 +models contains core models
  28 +views contains views files for core controllers
  29 +web contains assets and other files, which should be web available
  30 +widgets contains widgets
  31 +```
... ...
artweb/artbox-catalog/assets/CatalogAsset.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\assets;
  4 +
  5 + use yii\web\AssetBundle;
  6 +
  7 + /**
  8 + * Asset class for artbox-catalog
  9 + */
  10 + class CatalogAsset extends AssetBundle
  11 + {
  12 + /**
  13 + * @inheritdoc
  14 + */
  15 + public $sourcePath = '@artbox/catalog/web';
  16 +
  17 + /**
  18 + * @inheritdoc
  19 + */
  20 + public $js = [
  21 + 'js/script.js',
  22 + ];
  23 +
  24 + /**
  25 + * @inheritdoc
  26 + */
  27 + public $depends = [
  28 + 'yii\web\JqueryAsset',
  29 + ];
  30 + }
0 31 \ No newline at end of file
... ...
artweb/artbox-catalog/behaviors/DefaultVariantBehavior.php 0 → 100755
  1 +<?php
  2 + namespace artbox\catalog\behaviors;
  3 +
  4 + use artbox\catalog\models\Product;
  5 + use artbox\catalog\models\Variant;
  6 + use artbox\catalog\models\VariantLang;
  7 + use artbox\core\models\Language;
  8 + use yii\base\Behavior;
  9 +
  10 + /**
  11 + * Class DefaultVariantBehavior
  12 + *
  13 + * @property Product $owner
  14 + * @see ProductVariant
  15 + */
  16 + class DefaultVariantBehavior extends Behavior
  17 + {
  18 + /**
  19 + * @inheritdoc
  20 + */
  21 + public function events()
  22 + {
  23 + return [
  24 + Product::EVENT_AFTER_INSERT => 'addDefaultVariant',
  25 + ];
  26 + }
  27 +
  28 + /**
  29 + * Creates new default product's variant
  30 + */
  31 + public function addDefaultVariant()
  32 + {
  33 + $defaultVariant = new Variant();
  34 + $defaultVariant->product_id = $this->owner->id;
  35 + $defaultVariant->stock = 1;
  36 + $defaultVariant->sku = 'default';
  37 + $defaultVariant->save(false);
  38 +
  39 + /**
  40 + * Saving languages
  41 + */
  42 + $activeLanguageIds = Language::find()
  43 + ->select('id')
  44 + ->where(
  45 + [
  46 + 'status' => true,
  47 + ]
  48 + )
  49 + ->asArray()
  50 + ->column();
  51 + foreach ($activeLanguageIds as $languageId) {
  52 + $variantLanguage = new VariantLang();
  53 + $variantLanguage->language_id = $languageId;
  54 + $variantLanguage->variant_id = $defaultVariant->id;
  55 + $variantLanguage->title = 'default_' . $languageId;
  56 + $variantLanguage->save(false);
  57 + }
  58 + }
  59 +
  60 + }
  61 +
0 62 \ No newline at end of file
... ...
artweb/artbox-catalog/behaviors/LevelBehavior.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\behaviors;
  4 +
  5 + use yii\base\Behavior;
  6 + use yii\db\ActiveRecord;
  7 +
  8 + /**
  9 + * Class LevelBehavior
  10 + *
  11 + * @package artbox\catalog\behaviors
  12 + */
  13 + class LevelBehavior extends Behavior
  14 + {
  15 + public $levelField = 'level';
  16 +
  17 + public $parentIdField = 'parent_id';
  18 +
  19 + /**
  20 + * @inheritdoc
  21 + */
  22 + public function events()
  23 + {
  24 + return [
  25 + ActiveRecord::EVENT_BEFORE_INSERT => 'beforeSave',
  26 + ActiveRecord::EVENT_BEFORE_UPDATE => 'beforeSave',
  27 + ];
  28 + }
  29 +
  30 + public function beforeSave($event)
  31 + {
  32 + /**
  33 + * @var ActiveRecord $owner
  34 + */
  35 + $levelField = $this->levelField;
  36 + $parentIdField = $this->parentIdField;
  37 + $owner = $this->owner;
  38 +
  39 + if (empty($owner->$parentIdField) && $owner->$parentIdField == 0) {
  40 + $owner->$levelField = 0;
  41 + } else {
  42 + $parent = $owner::findOne($owner->$parentIdField);
  43 + $owner->$levelField = (int) $parent->$levelField + 1;
  44 + }
  45 +
  46 + }
  47 + }
0 48 \ No newline at end of file
... ...
artweb/artbox-catalog/behaviors/ManyToManyBehavior.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\behaviors;
  4 +
  5 + use yii\base\Behavior;
  6 + use yii\db\ActiveRecord;
  7 +
  8 + /**
  9 + * Class ManyToManyBehavior
  10 + *
  11 + * @package artbox\catalog\behaviors
  12 + */
  13 + class ManyToManyBehavior extends Behavior
  14 + {
  15 + /**
  16 + * @param string $name
  17 + * @param ActiveRecord[] $models
  18 + * @param array $extraColumns
  19 + */
  20 + public function linkMany(string $name, array $models, array $extraColumns = [])
  21 + {
  22 + /**
  23 + * @var ActiveRecord $owner
  24 + */
  25 + $owner = $this->owner;
  26 +
  27 + $owner->unlinkAll($name, true);
  28 +
  29 + foreach ($models as $model) {
  30 + $owner->link($name, $model, $extraColumns);
  31 + }
  32 + }
  33 + }
0 34 \ No newline at end of file
... ...
artweb/artbox-catalog/components/History.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\components;
  4 +
  5 + use artbox\catalog\models\Variant;
  6 + use yii\base\Object;
  7 + use yii\db\ActiveQuery;
  8 +
  9 + class History extends Object
  10 + {
  11 + /**
  12 + * Add Variant to history
  13 + *
  14 + * @param int $variantId
  15 + */
  16 + public function add(int $variantId)
  17 + {
  18 + $history = $this->get();
  19 + if (!in_array($variantId, $history)) {
  20 + array_push($history, $variantId);
  21 + }
  22 + \Yii::$app->session->set('history', $history);
  23 + }
  24 +
  25 + /**
  26 + * Get variantIds from history
  27 + *
  28 + * @return array
  29 + */
  30 + public function get(): array
  31 + {
  32 + return \Yii::$app->session->get('history', []);
  33 + }
  34 +
  35 + /**
  36 + * Get Variants query from history
  37 + *
  38 + * @return \yii\db\ActiveQuery
  39 + */
  40 + public function getModels(): ActiveQuery
  41 + {
  42 + return Variant::find()
  43 + ->where(
  44 + [
  45 + 'id' => $this->get(),
  46 + 'status' => true,
  47 + ]
  48 + );
  49 + }
  50 + }
0 51 \ No newline at end of file
... ...
artweb/artbox-catalog/composer.json 0 → 100755
  1 +{
  2 + "name": "artweb/artbox-catalog",
  3 + "description": "Artbox catalog extension",
  4 + "license": "BSD-3-Clause",
  5 + "minimum-stability": "dev",
  6 + "type": "yii2-extension",
  7 + "require": {
  8 + "php": ">=7.0",
  9 + "yiisoft/yii2": "~2.0",
  10 + "artweb/artbox-core": "~0.0.1"
  11 + },
  12 + "autoload": {
  13 + "psr-4": {
  14 + "artbox\\catalog\\": ""
  15 + }
  16 + }
  17 +}
0 18 \ No newline at end of file
... ...
artweb/artbox-catalog/console/controllers/ExportXmlController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\console\controllers;
  4 +
  5 + use artbox\catalog\models\Category;
  6 + use artbox\catalog\models\Variant;
  7 + use artbox\core\helpers\ImageHelper;
  8 + use yii\base\Exception;
  9 + use yii\console\Controller;
  10 + use yii\helpers\ArrayHelper;
  11 + use yii\helpers\Console;
  12 + use yii\helpers\Html;
  13 +
  14 + class ExportXmlController extends Controller
  15 + {
  16 + public $nadaviPath = '@frontend/web/nadavi.xml';
  17 + public $hotlinePath = '@frontend/web/hotline.xml';
  18 + public $shopName = 'Artbox';
  19 + public $host = '';
  20 + public $secured = false;
  21 + public $empty = true;
  22 + public $firmName = '';
  23 + public $firmId = 0;
  24 + /**
  25 + * @var \yii\web\UrlManager
  26 + */
  27 + protected $urlManager;
  28 +
  29 + public function options($actionID)
  30 + {
  31 + switch ($actionID) {
  32 + case 'nadavi':
  33 + return [
  34 + 'nadaviPath',
  35 + 'shopName',
  36 + 'host',
  37 + 'secured',
  38 + 'empty',
  39 + ];
  40 + case 'hotline':
  41 + return [
  42 + 'hotlinePath',
  43 + 'host',
  44 + 'secured',
  45 + 'empty',
  46 + 'firmId',
  47 + 'firmName',
  48 + ];
  49 + default:
  50 + return parent::options($actionID);
  51 + }
  52 + }
  53 +
  54 + public function optionAliases()
  55 + {
  56 + return [
  57 + 'np' => 'nadaviPath',
  58 + 'hp' => 'hotlinePath',
  59 + ];
  60 + }
  61 +
  62 + /**
  63 + * Generate price-list for Nadavi
  64 + *
  65 + * @see http://nadavi.net/nadavi.php?idPage_=57&idBookmark_=5
  66 + * @return int
  67 + */
  68 + public function actionNadavi()
  69 + {
  70 + $this->configureUrl();
  71 + $dom = new \DOMDocument('1.0', 'UTF-8');
  72 +
  73 + $dom->formatOutput = true;
  74 +
  75 + $root = $dom->createElement('yml_catalog');
  76 + $root->setAttribute('date', date('Y-m-d H:i'));
  77 + $dom->appendChild($root);
  78 +
  79 + $shop = $root->appendChild($dom->createElement('shop'));
  80 + $shop->appendChild($dom->createElement('name', $this->shopName));
  81 + $shop->appendChild(
  82 + $dom->createElement(
  83 + 'url',
  84 + $this->urlManager->createAbsoluteUrl([ 'site/index' ], $this->secured ? 'https' : 'http')
  85 + )
  86 + );
  87 +
  88 + $currencies = $shop->appendChild($dom->createElement('currencies'));
  89 + $currency = $dom->createElement('currency');
  90 + $currency->setAttribute('id', 'UAH');
  91 + $currency->setAttribute('rate', 1);
  92 + $currencies->appendChild($currency);
  93 +
  94 + $catalog = $shop->appendChild($dom->createElement('catalog'));
  95 +
  96 + /**
  97 + * @var Category[] $categories
  98 + */
  99 + $categories = Category::find()
  100 + ->with('lang')
  101 + ->all();
  102 + foreach ($categories as $category) {
  103 + $categoryElement = $dom->createElement('category', $category->lang->title);
  104 + $categoryElement->setAttribute('id', $category->id);
  105 + if (!empty($category->parent_id)) {
  106 + $categoryElement->setAttribute('parentId', $category->parent_id);
  107 + }
  108 + $catalog->appendChild($categoryElement);
  109 + $this->logSuccess('Category inserted: ' . $category->lang->title);
  110 + }
  111 +
  112 + $items = $shop->appendChild($dom->createElement('items'));
  113 +
  114 + $productQuery = Variant::find()
  115 + ->with(
  116 + [
  117 + 'product' => function ($query) {
  118 + /**
  119 + * @var \yii\db\ActiveQuery $query
  120 + */
  121 + $query->with('brand.lang')
  122 + ->with('image')
  123 + ->with('lang')
  124 + ->with('category');
  125 + },
  126 + ]
  127 + )
  128 + ->with('image')
  129 + ->with('lang');
  130 + if (!$this->empty) {
  131 + $productQuery->andWhere(
  132 + [
  133 + '>',
  134 + 'stock',
  135 + 0,
  136 + ]
  137 + );
  138 + }
  139 + foreach ($productQuery->each() as $variant) {
  140 + /**
  141 + * @var Variant $variant
  142 + */
  143 + if (empty($variant->product->category)) {
  144 + $this->logError('Variant with id ' . $variant->id . ' hasn\'t got category');
  145 + continue;
  146 + }
  147 + if (empty($variant->product->brand)) {
  148 + $this->logError('Variant with id ' . $variant->id . ' hasn\'t got brand');
  149 + continue;
  150 + }
  151 + $item = $dom->createElement('item');
  152 + $item->setAttribute('id', $variant->id);
  153 + try {
  154 + $item->appendChild(
  155 + $dom->createElement(
  156 + 'name',
  157 + htmlentities(
  158 + $variant->product->lang->title . ' (' . $variant->lang->title . ')'
  159 + )
  160 + )
  161 + );
  162 + } catch (Exception $exception) {
  163 + var_dump($variant->product->lang->title, $variant->lang->title);
  164 + die();
  165 + }
  166 + $item->appendChild(
  167 + $dom->createElement(
  168 + 'url',
  169 + $this->urlManager->createAbsoluteUrl(
  170 + [
  171 + 'product/view',
  172 + 'id' => $variant->product->id,
  173 + ],
  174 + $this->secured ? 'https' : 'http'
  175 + )
  176 + )
  177 + );
  178 + $item->appendChild($dom->createElement('price', $variant->price));
  179 + $item->appendChild($dom->createElement('categoryId', $variant->product->category->id));
  180 + $item->appendChild($dom->createElement('vendor', $variant->product->brand->lang->title));
  181 + if (!empty($variant->image)) {
  182 + $imageModel = ImageHelper::set($variant->image->getPath())
  183 + ->setWidth(200);
  184 + $image = $this->urlManager->createAbsoluteUrl(
  185 + $imageModel->render(),
  186 + $this->secured ? 'https' : 'http'
  187 + );
  188 + unset($imageModel);
  189 + } elseif (!empty($variant->product->image)) {
  190 + $imageModel = ImageHelper::set($variant->product->image->getPath())
  191 + ->setWidth(200);
  192 + $image = $this->urlManager->createAbsoluteUrl(
  193 + $imageModel->render(),
  194 + $this->secured ? 'https' : 'http'
  195 + );
  196 + unset($imageModel);
  197 + }
  198 + if (!empty($image)) {
  199 + $item->appendChild($dom->createElement('image', $image));
  200 + unset($image);
  201 + }
  202 + if (!empty($variant->lang->description)) {
  203 + $item->appendChild($dom->createElement('description', Html::encode($variant->lang->description)));
  204 + } elseif (!empty($variant->product->lang->description)) {
  205 + $item->appendChild(
  206 + $dom->createElement('description', Html::encode($variant->product->lang->description))
  207 + );
  208 + }
  209 + $items->appendChild($item);
  210 + $this->logSuccess(
  211 + 'Product inserted: ' . $variant->product->lang->title . ' (' . $variant->lang->title . ')'
  212 + );
  213 + }
  214 +
  215 + file_put_contents(\Yii::getAlias($this->nadaviPath), $dom->saveXML());
  216 + return 0;
  217 + }
  218 +
  219 + /**
  220 + * Generate price-list for Hotline
  221 + *
  222 + * @see http://hotline.ua/about/pricelists_specs/
  223 + * @return int
  224 + */
  225 + public function actionHotline()
  226 + {
  227 + $this->configureUrl();
  228 + $dom = new \DOMDocument('1.0', 'UTF-8');
  229 +
  230 + $dom->formatOutput = true;
  231 + $price = $dom->appendChild($dom->createElement('price'));
  232 +
  233 + $price->appendChild($dom->createElement('date', date('Y-m-d H:i')));
  234 + if (!empty($this->firmName)) {
  235 + $price->appendChild($dom->createElement('firmName', $this->firmName));
  236 + }
  237 + if (!empty($this->firmId)) {
  238 + $price->appendChild($dom->createElement('firmId', $this->firmId));
  239 + }
  240 +
  241 + $categoriesNode = $price->appendChild($dom->createElement('categories'));
  242 + /**
  243 + * @var Category[] $categories
  244 + */
  245 + $categories = Category::find()
  246 + ->with('lang')
  247 + ->all();
  248 + foreach ($categories as $category) {
  249 + if (empty($category->lang)) {
  250 + $this->logError('Category with id ' . $category->id . ' has no Lang');
  251 + continue;
  252 + }
  253 + $categoryElement = $dom->createElement('category');
  254 + $categoryElement->appendChild($dom->createElement('id', $category->id));
  255 + $categoryElement->appendChild($dom->createElement('name', $category->lang->title));
  256 + if (!empty($category->parent_id)) {
  257 + $categoryElement->appendChild($dom->createElement('parentId', $category->parent_id));
  258 + }
  259 + $categoriesNode->appendChild($categoryElement);
  260 + $this->logSuccess('Category inserted: ' . $category->lang->title);
  261 + }
  262 + $items = $price->appendChild($dom->createElement('items'));
  263 + $productQuery = Variant::find()
  264 + ->with(
  265 + [
  266 + 'product' => function ($query) {
  267 + /**
  268 + * @var \yii\db\ActiveQuery $query
  269 + */
  270 + $query->with('brand.lang')
  271 + ->with('image')
  272 + ->with('lang')
  273 + ->with('category');
  274 + },
  275 + ]
  276 + )
  277 + ->with('image')
  278 + ->with('lang');
  279 + if (!$this->empty) {
  280 + $productQuery->andWhere(
  281 + [
  282 + '>',
  283 + 'stock',
  284 + 0,
  285 + ]
  286 + );
  287 + }
  288 + foreach ($productQuery->each() as $variant) {
  289 + /**
  290 + * @var Variant $variant
  291 + */
  292 + if (empty($variant->product->category)) {
  293 + $this->logError('Variant with id ' . $variant->id . ' hasn\'t got category');
  294 + continue;
  295 + }
  296 + if (empty($variant->product->brand)) {
  297 + $this->logError('Variant with id ' . $variant->id . ' hasn\'t got brand');
  298 + continue;
  299 + }
  300 + $item = $dom->createElement('item');
  301 + $item->appendChild(
  302 + $dom->createElement('id', $variant->id)
  303 + );
  304 + $item->appendChild($dom->createElement('categoryId', $variant->product->category->id));
  305 + $item->appendChild(
  306 + $dom->createElement('code', $variant->sku)
  307 + );
  308 + $item->appendChild($dom->createElement('vendor', $variant->product->brand->lang->title));
  309 + $item->appendChild(
  310 + $dom->createElement(
  311 + 'name',
  312 + htmlentities(
  313 + $variant->product->lang->title . ' (' . $variant->lang->title . ')'
  314 + )
  315 + )
  316 + );
  317 + if (!empty($variant->lang->description)) {
  318 + $item->appendChild($dom->createElement('description', Html::encode($variant->lang->description)));
  319 + } elseif (!empty($variant->product->lang->description)) {
  320 + $item->appendChild(
  321 + $dom->createElement('description', Html::encode($variant->product->lang->description))
  322 + );
  323 + }
  324 + $item->appendChild(
  325 + $dom->createElement(
  326 + 'url',
  327 + $this->urlManager->createAbsoluteUrl(
  328 + [
  329 + 'product/view',
  330 + 'id' => $variant->product->id,
  331 + ],
  332 + $this->secured ? 'https' : 'http'
  333 + )
  334 + )
  335 + );
  336 + if (!empty($variant->image)) {
  337 + $image = $this->urlManager->hostInfo . ImageHelper::set(
  338 + $variant->image->getPath()
  339 + )
  340 + ->setWidth(200)
  341 + ->render();
  342 + } elseif (!empty($variant->product->image)) {
  343 + $image = $this->urlManager->hostInfo . ImageHelper::set(
  344 + $variant->product->image->getPath()
  345 + )
  346 + ->setWidth(200)
  347 + ->render();
  348 + }
  349 + if (!empty($image)) {
  350 + $item->appendChild($dom->createElement('image', $image));
  351 + unset($image);
  352 + }
  353 + $item->appendChild($dom->createElement('priceRUAH', $variant->price));
  354 + if (!empty($variant->price_old)) {
  355 + $item->appendChild($dom->createElement('oldprice', $variant->price_old));
  356 + }
  357 + if ($variant->stock) {
  358 + $item->appendChild($dom->createElement('stock', 'В наличии'));
  359 + } else {
  360 + $item->appendChild($dom->createElement('stock', 'Под заказ'));
  361 + }
  362 + $items->appendChild($item);
  363 + $this->logSuccess(
  364 + 'Product inserted: ' . $variant->product->lang->title . ' (' . $variant->lang->title . ')'
  365 + );
  366 + }
  367 +
  368 + file_put_contents(\Yii::getAlias($this->hotlinePath), $dom->saveXML());
  369 + return 0;
  370 + }
  371 +
  372 + protected function configureUrl()
  373 + {
  374 + $config = ArrayHelper::merge(
  375 + require \Yii::getAlias('@frontend/config/main.php'),
  376 + require \Yii::getAlias('@common/config/main.php')
  377 + );
  378 + if (!empty($config[ 'components' ]) && !empty($config[ 'components' ][ 'urlManager' ])) {
  379 + $urlManagerConfig = $config[ 'components' ][ 'urlManager' ];
  380 + } else {
  381 + die('Param error');
  382 + }
  383 + if (empty($this->host)) {
  384 + $root = dirname(\Yii::getAlias('@common'));
  385 + if (preg_match('/([^\/]*)$/', $root, $matches)) {
  386 + if ($this->secured) {
  387 + $urlManagerConfig[ 'hostInfo' ] = 'https://' . $matches[ 1 ];
  388 + } else {
  389 + $urlManagerConfig[ 'hostInfo' ] = 'http://' . $matches[ 1 ];
  390 + }
  391 + } else {
  392 + die('Host not set and cannot be gained automatically.');
  393 + }
  394 + } else {
  395 + if (substr($this->host, 0, 4) == 'http') {
  396 + $urlManagerConfig[ 'hostInfo' ] = $this->host;
  397 + } else {
  398 + if ($this->secured) {
  399 + $urlManagerConfig[ 'hostInfo' ] = 'https://' . $this->host;
  400 + } else {
  401 + $urlManagerConfig[ 'hostInfo' ] = 'http://' . $this->host;
  402 + }
  403 + }
  404 + }
  405 + $this->urlManager = \Yii::createObject($urlManagerConfig);
  406 + }
  407 +
  408 + protected function logSuccess(string $msg)
  409 + {
  410 + $this->stdout($msg . "\n", Console::FG_GREEN, Console::BOLD);
  411 + }
  412 +
  413 + protected function logError(string $msg)
  414 + {
  415 + $this->stderr($msg . "\n", Console::FG_RED, Console::BOLD);
  416 + }
  417 + }
0 418 \ No newline at end of file
... ...
artweb/artbox-catalog/controllers/BrandController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\controllers;
  4 +
  5 + use Yii;
  6 + use artbox\catalog\models\Brand;
  7 + use artbox\catalog\models\BrandSearch;
  8 + use yii\filters\AccessControl;
  9 + use yii\web\Controller;
  10 + use yii\web\NotFoundHttpException;
  11 + use yii\filters\VerbFilter;
  12 + use yii\web\Response;
  13 +
  14 + /**
  15 + * BrandController implements the CRUD actions for Brand model.
  16 + */
  17 + class BrandController extends Controller
  18 + {
  19 + /**
  20 + * @inheritdoc
  21 + */
  22 + public function getViewPath()
  23 + {
  24 + return '@artbox/catalog/views/brand';
  25 + }
  26 +
  27 + /**
  28 + * @inheritdoc
  29 + */
  30 + public function behaviors()
  31 + {
  32 + return [
  33 + 'access' => [
  34 + 'class' => AccessControl::className(),
  35 + 'rules' => [
  36 + [
  37 + 'actions' => [
  38 + 'login',
  39 + 'error',
  40 + ],
  41 + 'allow' => true,
  42 + ],
  43 + [
  44 + 'allow' => true,
  45 + 'roles' => [ '@' ],
  46 + ],
  47 + ],
  48 + ],
  49 + 'verbs' => [
  50 + 'class' => VerbFilter::className(),
  51 + 'actions' => [
  52 + 'delete' => [ 'POST' ],
  53 + ],
  54 + ],
  55 + ];
  56 + }
  57 +
  58 + /**
  59 + * Lists all Brand models.
  60 + *
  61 + * @return mixed
  62 + */
  63 + public function actionIndex()
  64 + {
  65 + $searchModel = new BrandSearch();
  66 + $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  67 +
  68 + return $this->render(
  69 + 'index',
  70 + [
  71 + 'searchModel' => $searchModel,
  72 + 'dataProvider' => $dataProvider,
  73 + ]
  74 + );
  75 + }
  76 +
  77 + /**
  78 + * Displays a single Brand model.
  79 + *
  80 + * @param integer $id
  81 + *
  82 + * @return mixed
  83 + */
  84 + public function actionView($id)
  85 + {
  86 + return $this->render(
  87 + 'view',
  88 + [
  89 + 'model' => $this->findModel($id),
  90 + ]
  91 + );
  92 + }
  93 +
  94 + /**
  95 + * Creates a new Brand model.
  96 + * If creation is successful, the browser will be redirected to the 'view' page.
  97 + *
  98 + * @return mixed
  99 + */
  100 + public function actionCreate()
  101 + {
  102 + $model = new Brand();
  103 + $model->generateLangs();
  104 + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) {
  105 + return $this->redirect(
  106 + [
  107 + 'view',
  108 + 'id' => $model->id,
  109 + ]
  110 + );
  111 + }
  112 + return $this->render(
  113 + 'create',
  114 + [
  115 + 'model' => $model,
  116 + 'modelLangs' => $model->modelLangs,
  117 + ]
  118 + );
  119 + }
  120 +
  121 + /**
  122 + * Updates an existing Brand model.
  123 + * If update is successful, the browser will be redirected to the 'view' page.
  124 + *
  125 + * @param integer $id
  126 + *
  127 + * @return mixed
  128 + */
  129 + public function actionUpdate($id)
  130 + {
  131 + $model = $this->findModel($id);
  132 + $model->generateLangs();
  133 +
  134 + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) {
  135 + return $this->redirect(
  136 + [
  137 + 'view',
  138 + 'id' => $model->id,
  139 + ]
  140 + );
  141 + }
  142 + return $this->render(
  143 + 'update',
  144 + [
  145 + 'model' => $model,
  146 + 'modelLangs' => $model->modelLangs,
  147 + ]
  148 + );
  149 + }
  150 +
  151 + /**
  152 + * Deletes an existing Brand model.
  153 + * If deletion is successful, the browser will be redirected to the 'index' page.
  154 + *
  155 + * @param integer $id
  156 + *
  157 + * @return mixed
  158 + */
  159 + public function actionDelete($id)
  160 + {
  161 + $this->findModel($id)
  162 + ->delete();
  163 +
  164 + return $this->redirect([ 'index' ]);
  165 + }
  166 +
  167 + /**
  168 + * Returnes an array of matched brands,
  169 + * response must be in format:
  170 + * $out = [
  171 + * 'results' => [
  172 + * [
  173 + * 'id' => 1,
  174 + * 'text' => 'First',
  175 + * ],
  176 + * [
  177 + * 'id' => 2,
  178 + * 'text' => 'Second'
  179 + * ],
  180 + * ],
  181 + * ];
  182 + * ! array key must be 'id' and 'text' !
  183 + *
  184 + * @param null $q
  185 + * @param int $limit
  186 + *
  187 + * @return array
  188 + * @internal param null $id
  189 + *
  190 + */
  191 + public function actionList($q = null, $limit = 20)
  192 + {
  193 + \Yii::$app->response->format = Response::FORMAT_JSON;
  194 + $out = [
  195 + 'results' => [
  196 + [
  197 + 'id' => '',
  198 + 'text' => '',
  199 + ],
  200 + ],
  201 + ];
  202 + if (!is_null($q)) {
  203 + $brands = Brand::find()
  204 + ->joinWith('lang')
  205 + ->select(
  206 + [
  207 + 'id',
  208 + 'text' => 'brand_lang.title',
  209 + ]
  210 + )
  211 + ->andFilterWhere(
  212 + [
  213 + 'like',
  214 + 'brand_lang.title',
  215 + $q,
  216 + ]
  217 + )
  218 + ->limit($limit)
  219 + ->asArray()
  220 + ->all();
  221 +
  222 + if (!empty( $brands )) {
  223 + $out[ 'results' ] = $brands;
  224 + }
  225 + }
  226 +
  227 + return $out;
  228 + }
  229 +
  230 + /**
  231 + * Finds the Brand model based on its primary key value.
  232 + * If the model is not found, a 404 HTTP exception will be thrown.
  233 + *
  234 + * @param integer $id
  235 + *
  236 + * @return Brand the loaded model
  237 + * @throws NotFoundHttpException if the model cannot be found
  238 + */
  239 + protected function findModel($id)
  240 + {
  241 + if (( $model = Brand::findOne($id) ) !== null) {
  242 + return $model;
  243 + } else {
  244 + throw new NotFoundHttpException('The requested page does not exist.');
  245 + }
  246 + }
  247 + }
... ...
artweb/artbox-catalog/controllers/CategoryController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\controllers;
  4 +
  5 + use Yii;
  6 + use artbox\catalog\models\Category;
  7 + use artbox\catalog\models\CategorySearch;
  8 + use yii\filters\AccessControl;
  9 + use yii\web\Controller;
  10 + use yii\web\NotFoundHttpException;
  11 + use yii\filters\VerbFilter;
  12 + use yii\web\Response;
  13 +
  14 + /**
  15 + * CategoryController implements the CRUD actions for Category model.
  16 + */
  17 + class CategoryController extends Controller
  18 + {
  19 + /**
  20 + * @inheritdoc
  21 + */
  22 + public function getViewPath()
  23 + {
  24 + return '@artbox/catalog/views/category';
  25 + }
  26 +
  27 + /**
  28 + * @inheritdoc
  29 + */
  30 + public function behaviors()
  31 + {
  32 + return [
  33 + 'verbs' => [
  34 + 'class' => VerbFilter::className(),
  35 + 'actions' => [
  36 + 'delete' => [ 'POST' ],
  37 + ],
  38 + ],
  39 + 'access' => [
  40 + 'class' => AccessControl::className(),
  41 + 'rules' => [
  42 + [
  43 + 'actions' => [
  44 + 'login',
  45 + 'error',
  46 + ],
  47 + 'allow' => true,
  48 + ],
  49 + [
  50 + 'allow' => true,
  51 + 'roles' => [ '@' ],
  52 + ],
  53 + ],
  54 + ],
  55 + ];
  56 + }
  57 +
  58 + /**
  59 + * Lists all Category models.
  60 + *
  61 + * @return mixed
  62 + */
  63 + public function actionIndex()
  64 + {
  65 + $searchModel = new CategorySearch();
  66 + $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  67 +
  68 + return $this->render(
  69 + 'index',
  70 + [
  71 + 'searchModel' => $searchModel,
  72 + 'dataProvider' => $dataProvider,
  73 + ]
  74 + );
  75 + }
  76 +
  77 + /**
  78 + * Displays a single Category model.
  79 + *
  80 + * @param integer $id
  81 + *
  82 + * @return mixed
  83 + */
  84 + public function actionView($id)
  85 + {
  86 + return $this->render(
  87 + 'view',
  88 + [
  89 + 'model' => $this->findModel($id),
  90 + ]
  91 + );
  92 + }
  93 +
  94 + /**
  95 + * Creates a new Category model.
  96 + * If creation is successful, the browser will be redirected to the 'view' page.
  97 + *
  98 + * @return mixed
  99 + */
  100 + public function actionCreate()
  101 + {
  102 + $model = new Category();
  103 + $model->generateLangs();
  104 + if ($model->loadWithLangs(\Yii::$app->request)) {
  105 + if ($model->saveWithLangs()) {
  106 + return $this->redirect(
  107 + [
  108 + 'view',
  109 + 'id' => $model->id,
  110 + ]
  111 + );
  112 + }
  113 + }
  114 + return $this->render(
  115 + 'create',
  116 + [
  117 + 'model' => $model,
  118 + 'modelLangs' => $model->modelLangs,
  119 + ]
  120 + );
  121 + }
  122 +
  123 + /**
  124 + * Updates an existing Category model.
  125 + * If update is successful, the browser will be redirected to the 'view' page.
  126 + *
  127 + * @param integer $id
  128 + *
  129 + * @return mixed
  130 + */
  131 + public function actionUpdate($id)
  132 + {
  133 + $model = $this->findModel($id);
  134 +
  135 + $model->generateLangs();
  136 +
  137 + if ($model->loadWithLangs(\Yii::$app->request)) {
  138 + if ($model->saveWithLangs()) {
  139 + return $this->redirect(
  140 + [
  141 + 'view',
  142 + 'id' => $model->id,
  143 + ]
  144 + );
  145 + }
  146 + }
  147 + return $this->render(
  148 + 'update',
  149 + [
  150 + 'model' => $model,
  151 + 'modelLangs' => $model->modelLangs,
  152 + ]
  153 + );
  154 + }
  155 +
  156 + /**
  157 + * Deletes an existing Category model.
  158 + * If deletion is successful, the browser will be redirected to the 'index' page.
  159 + *
  160 + * @param integer $id
  161 + *
  162 + * @return mixed
  163 + */
  164 + public function actionDelete($id)
  165 + {
  166 + $this->findModel($id)
  167 + ->delete();
  168 +
  169 + return $this->redirect([ 'index' ]);
  170 + }
  171 +
  172 + /**
  173 + * Returnes an array of matched categories,
  174 + * response must be in format:
  175 + * $out = [
  176 + * 'results' => [
  177 + * [
  178 + * 'id' => 1,
  179 + * 'text' => 'First',
  180 + * ],
  181 + * [
  182 + * 'id' => 2,
  183 + * 'text' => 'Second'
  184 + * ],
  185 + * ],
  186 + * ];
  187 + * ! array key must be 'id' and 'text' !
  188 + *
  189 + * @param null $q
  190 + * @param null $id
  191 + *
  192 + * @return array
  193 + */
  194 + public function actionList($q = null, $id = null)
  195 + {
  196 + \Yii::$app->response->format = Response::FORMAT_JSON;
  197 + $out = [
  198 + 'results' => [
  199 + [
  200 + 'id' => '',
  201 + 'text' => '',
  202 + ],
  203 + ],
  204 + ];
  205 + if (!is_null($q)) {
  206 + $categories = Category::find()
  207 + ->joinWith('lang')
  208 + ->select(
  209 + [
  210 + 'id',
  211 + 'text' => 'category_lang.title',
  212 + ]
  213 + )
  214 + ->filterWhere(
  215 + [
  216 + '!=',
  217 + 'id',
  218 + $id,
  219 + ]
  220 + )
  221 + ->andFilterWhere(
  222 + [
  223 + 'like',
  224 + 'category_lang.title',
  225 + $q,
  226 + ]
  227 + )
  228 + ->andFilterWhere(
  229 + [
  230 + '!=',
  231 + 'parent_id',
  232 + $id,
  233 + ]
  234 + )
  235 + ->limit(20)
  236 + ->asArray()
  237 + ->all();
  238 +
  239 + if (!empty($categories)) {
  240 + $out[ 'results' ] = $categories;
  241 + }
  242 + }
  243 +
  244 + return $out;
  245 + }
  246 +
  247 + /**
  248 + * Finds the Category model based on its primary key value.
  249 + * If the model is not found, a 404 HTTP exception will be thrown.
  250 + *
  251 + * @param integer $id
  252 + *
  253 + * @return Category the loaded model
  254 + * @throws NotFoundHttpException if the model cannot be found
  255 + */
  256 + protected function findModel($id)
  257 + {
  258 + if (( $model = Category::findOne($id) ) !== null) {
  259 + return $model;
  260 + } else {
  261 + throw new NotFoundHttpException('The requested page does not exist.');
  262 + }
  263 + }
  264 + }
... ...
artweb/artbox-catalog/controllers/ExportController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\controllers;
  4 +
  5 + use artbox\catalog\models\Product;
  6 + use common\models\ExportLog;
  7 + use yii\db\ActiveQuery;
  8 + use yii\filters\AccessControl;
  9 + use yii\web\Controller;
  10 + use PHPExcel;
  11 + use PHPExcel_Writer_Excel2007;
  12 +
  13 + /**
  14 + * Class ExportController is web wrapper for console ExportXmlController
  15 + */
  16 + class ExportController extends Controller
  17 + {
  18 + /**
  19 + * @inheritdoc
  20 + */
  21 + public function getViewPath()
  22 + {
  23 + return '@artbox/catalog/views/export';
  24 + }
  25 +
  26 + public function actionTest()
  27 + {
  28 + $exportLog = ExportLog::findOne(1);
  29 +
  30 + $products = Product::find()
  31 + ->with(
  32 + [
  33 + 'variant.lang',
  34 + 'lang',
  35 + 'brand.lang',
  36 + 'category.lang',
  37 + 'productOptionExcls' => function (ActiveQuery $query) {
  38 + $query->with(
  39 + [
  40 + 'lang',
  41 + 'group.lang',
  42 + ]
  43 + );
  44 + },
  45 + ]
  46 + );
  47 + $data = [];
  48 + $j = 0;
  49 + $exportLog->message = 'Staeted';
  50 + $exportLog->percent = '';
  51 + $exportLog->is_running = true;
  52 + foreach ($products->batch(1000) as $productsBatch) {
  53 + foreach ($productsBatch as $product) {
  54 + $j++;
  55 + if (empty($product->variant) || empty($product->category) || empty($product->brand)) {
  56 + continue;
  57 + }
  58 + $filters = [];
  59 +
  60 + foreach ($product->productOptionExcls as $optionExcl) {
  61 + $filters[] = trim($optionExcl->group->lang->title, ':') . ':' . $optionExcl->lang->value;
  62 + }
  63 +
  64 + $data[] = [
  65 + 'A' => $product->category->lang->title,
  66 + //1
  67 + 'B' => $product->brand->lang->title,
  68 + //2
  69 + 'C' => $product->lang->title,
  70 + //3
  71 + 'D' => $product->variant->sku,
  72 + //4
  73 + 'E' => $product->lang->description,
  74 + //5
  75 + 'F' => $product->variant->price,
  76 + //6
  77 + 'G' => $product->variant->price_old,
  78 + //7
  79 + 'H' => '',
  80 + //8
  81 + 'I' => '',
  82 + //9
  83 + 'J' => '',
  84 + //10
  85 + 'K' => '',
  86 + //11
  87 + 'L' => '',
  88 + //12
  89 + 'M' => $product->variant->stock,
  90 + //13
  91 + 'N' => implode('*', $filters),
  92 + //14
  93 + ];
  94 + }
  95 + }
  96 +
  97 + $objPHPExcel = new PHPExcel();
  98 +
  99 + $objPHPExcel->getProperties()
  100 + ->setCreator("Runnable.com");
  101 + $objPHPExcel->getProperties()
  102 + ->setLastModifiedBy("Runnable.com");
  103 + $objPHPExcel->getProperties()
  104 + ->setTitle("Office 2007 XLSX Test Document");
  105 + $objPHPExcel->getProperties()
  106 + ->setSubject("Office 2007 XLSX Test Document");
  107 + $objPHPExcel->getProperties()
  108 + ->setDescription(
  109 + "Test document for Office 2007 XLSX, generated using PHP classes."
  110 + );
  111 +
  112 + $objPHPExcel->setActiveSheetIndex(0);
  113 + $i = 1;
  114 + foreach ($data as $values) {
  115 + foreach ($values as $key => $value) {
  116 + $objPHPExcel->getActiveSheet()
  117 + ->SetCellValue($key . $i, $value);
  118 + }
  119 + $i++;
  120 + }
  121 +
  122 + $objPHPExcel->getActiveSheet()
  123 + ->setTitle('Simple');
  124 +
  125 + $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
  126 + $objWriter->save(\Yii::getAlias('@storage/test2.xlsx'));
  127 + }
  128 +
  129 + /**
  130 + * @inheritdoc
  131 + */
  132 + public function behaviors()
  133 + {
  134 + return [
  135 + 'access' => [
  136 + 'class' => AccessControl::className(),
  137 + 'rules' => [
  138 + [
  139 + 'actions' => [
  140 + 'login',
  141 + 'error',
  142 + ],
  143 + 'allow' => true,
  144 + ],
  145 + [
  146 + 'allow' => true,
  147 + 'roles' => [ '@' ],
  148 + ],
  149 + ],
  150 + ],
  151 + ];
  152 + }
  153 +
  154 + public function actionIndex()
  155 + {
  156 + return $this->render('index');
  157 + }
  158 +
  159 + public function actionHotline()
  160 + {
  161 + $response = \Yii::$app->response;
  162 + $response->format = $response::FORMAT_JSON;
  163 + $rootDir = dirname(\Yii::getAlias('@common'));
  164 + exec("cd $rootDir && php yii export-xml/hotline", $output);
  165 + if (count($output) === 1) {
  166 + return [
  167 + 'error' => true,
  168 + 'output' => $output[ 0 ],
  169 + ];
  170 + } else {
  171 + return [
  172 + 'success' => true,
  173 + 'output' => $output,
  174 + ];
  175 + }
  176 + }
  177 +
  178 + public function actionNadavi()
  179 + {
  180 + $response = \Yii::$app->response;
  181 + $response->format = $response::FORMAT_JSON;
  182 + $rootDir = dirname(\Yii::getAlias('@common'));
  183 + exec("cd $rootDir && php yii export-xml/nadavi", $output);
  184 + if (count($output) === 1) {
  185 + return [
  186 + 'error' => true,
  187 + 'output' => $output[ 0 ],
  188 + ];
  189 + } else {
  190 + return [
  191 + 'success' => true,
  192 + 'output' => $output,
  193 + ];
  194 + }
  195 + }
  196 + }
0 197 \ No newline at end of file
... ...
artweb/artbox-catalog/controllers/ImportController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\controllers;
  4 +
  5 + use artbox\catalog\models\Brand;
  6 + use artbox\catalog\models\Category;
  7 + use artbox\catalog\models\Import;
  8 + use artbox\catalog\models\Product;
  9 + use artbox\catalog\models\ProductOptionExcl;
  10 + use artbox\catalog\models\ProductOptionExclLang;
  11 + use artbox\catalog\models\ProductOptionGroupExcl;
  12 + use artbox\catalog\models\ProductOptionGroupExclLang;
  13 + use artbox\catalog\models\ProductToCategory;
  14 + use artbox\catalog\models\ProductToProductOptionExcl;
  15 + use artbox\catalog\models\Variant;
  16 + use artbox\core\models\Image;
  17 + use artbox\core\models\Language;
  18 + use yii\web\Controller;
  19 + use PHPExcel_IOFactory;
  20 + use yii\web\Response;
  21 + use yii\filters\AccessControl;
  22 +
  23 + /**
  24 + * Class ImportController
  25 + *
  26 + * @package artbox\catalog\controllers
  27 + */
  28 + class ImportController extends Controller
  29 + {
  30 + protected $addedCategories = [];
  31 +
  32 + protected $addedBrands = [];
  33 +
  34 + public function getViewPath()
  35 + {
  36 + return '@artbox/catalog/views/import';
  37 + }
  38 + public function behaviors()
  39 + {
  40 + return [
  41 + 'access' => [
  42 + 'class' => AccessControl::className(),
  43 + 'rules' => [
  44 + [
  45 + 'actions' => [
  46 + 'login',
  47 + 'error',
  48 + ],
  49 + 'allow' => true,
  50 + ],
  51 + [
  52 + 'allow' => true,
  53 + 'roles' => [ '@' ],
  54 + ],
  55 + ],
  56 + ],
  57 + ];
  58 + }
  59 +
  60 + public function actionIndex()
  61 + {
  62 + return $this->render('index');
  63 + }
  64 +
  65 + public function actionImport($id)
  66 + {
  67 + \Yii::$app->response->format = Response::FORMAT_JSON;
  68 +
  69 + /**
  70 + * @var Import[] $importModels
  71 + */
  72 + $importModels = Import::find()
  73 + ->offset($id * 10)
  74 + ->limit(10)
  75 + ->with(
  76 + [
  77 + 'variant.product',
  78 + 'categoryLang.category',
  79 + 'brandLang.brand',
  80 + 'image',
  81 + ]
  82 + )
  83 + ->all();
  84 +
  85 + if (empty($importModels)) {
  86 + return [
  87 + 'percent' => 100,
  88 + 'finish' => true,
  89 + ];
  90 + }
  91 +
  92 + $percent = 0;
  93 + foreach ($importModels as $model) {
  94 + $category = $this->resolveCategory($model);
  95 + $brand = $this->resolveBrand($model);
  96 + $this->resolveImage($model);
  97 +
  98 + if (!empty($category)) {
  99 + $model->groups = $this->parseOptions($model);
  100 + }
  101 +
  102 + if (empty($model->variant)) {
  103 + $this->createRecord($model);
  104 + } else {
  105 + $this->updateRecord($model);
  106 + }
  107 +
  108 + $percent = \Yii::$app->formatter->asDecimal(
  109 + ( ( $id + 1 ) * 1000 / Import::find()
  110 + ->count() ),
  111 + 2
  112 + );
  113 +
  114 + }
  115 +
  116 + return [
  117 + 'percent' => $percent,
  118 + 'finish' => false,
  119 + ];
  120 + }
  121 +
  122 + public function actionUpload()
  123 + {
  124 + \Yii::$app->response->format = Response::FORMAT_JSON;
  125 +
  126 + $error = false;
  127 + $files = [];
  128 +
  129 + $uploaddir = \Yii::getAlias('@storage/');
  130 + foreach ($_FILES as $file) {
  131 + if (move_uploaded_file($file[ 'tmp_name' ], $uploaddir . 'import.xlsx')) {
  132 + $files[] = $uploaddir . $file[ 'name' ];
  133 + } else {
  134 + $error = true;
  135 + }
  136 + }
  137 +
  138 + $data = ( $error ) ? [ 'error' => 'There was an error uploading your files' ] : [ 'files' => $files ];
  139 +
  140 + $this->populateImportTable();
  141 +
  142 + return $data;
  143 + }
  144 +
  145 + protected function populateImportTable()
  146 + {
  147 + $xlsx = PHPExcel_IOFactory::load(\Yii::getAlias('@storage/import.xlsx'));
  148 +
  149 + $xlsx->setActiveSheetIndex(0);
  150 + $sheet = $xlsx->getActiveSheet();
  151 + $rowIterator = $sheet->getRowIterator();
  152 + $j = 0;
  153 +
  154 + $insert = [];
  155 + foreach ($rowIterator as $row) {
  156 + $j++;
  157 + $cellIterator = $row->getCellIterator();
  158 + $row = [];
  159 + $i = 0;
  160 + foreach ($cellIterator as $cell) {
  161 + /**
  162 + * @var \PHPExcel_Cell $cell
  163 + */
  164 + $i++;
  165 + $row[ $i ] = $cell->getValue();
  166 + if ($i > 14) {
  167 + break;
  168 + }
  169 + }
  170 +
  171 + /**
  172 + * Getting needed cells
  173 + */
  174 + $insert[] = [
  175 + $row[ 1 ],
  176 + $row[ 2 ],
  177 + $row[ 3 ],
  178 + $row[ 4 ],
  179 + $row[ 5 ],
  180 + $row[ 6 ],
  181 + $row[ 7 ],
  182 + $row[ 9 ] * 1 + $row[ 8 ] * 2 + $row[ 10 ] * 4,
  183 + $row[ 11 ],
  184 + basename($row[ 11 ]),
  185 + $row[ 12 ],
  186 + $row[ 13 ],
  187 + isset($row[ 14 ]) ? $row[ 14 ] : '',
  188 + ];
  189 +
  190 + /**
  191 + * Stops when hitting bottom line
  192 + */
  193 + if (empty($row[ 3 ])) {
  194 + break;
  195 + }
  196 +
  197 + }
  198 +
  199 + $db = \Yii::$app->db;
  200 +
  201 + $db->createCommand()
  202 + ->truncateTable('import')
  203 + ->execute();
  204 + $db->createCommand()
  205 + ->batchInsert(
  206 + 'import',
  207 + [
  208 + 'category_name',
  209 + 'brand_name',
  210 + 'product_name',
  211 + 'sku',
  212 + 'description',
  213 + 'price',
  214 + 'price_old',
  215 + 'mask',
  216 + 'image_link',
  217 + 'image_name',
  218 + 'video',
  219 + 'stock',
  220 + 'characteristics',
  221 + ],
  222 + $insert
  223 + )
  224 + ->execute();
  225 + }
  226 +
  227 + protected function resolveCategory(Import $import)
  228 + {
  229 + if (empty($import->categoryLang)) {
  230 + if (!empty($import->category_name)) {
  231 +
  232 + if (array_key_exists($import->category_name, $this->addedCategories)) {
  233 + $import->categoryId = $this->addedCategories[ $import->category_name ]->id;
  234 + return $this->addedCategories[ $import->category_name ];
  235 + }
  236 +
  237 + $category = new Category();
  238 + $category->generateLangs();
  239 + foreach ($category->modelLangs as $categoryLang) {
  240 + $categoryLang->title = $import->category_name;
  241 + }
  242 + $category->saveWithLangs();
  243 + $this->addedCategories[ $import->category_name ] = $category;
  244 + $import->categoryId = $category->id;
  245 + return $category;
  246 + }
  247 + } else {
  248 + $import->categoryId = $import->categoryLang->category->id;
  249 + return $import->categoryLang->category;
  250 + }
  251 + return null;
  252 + }
  253 + protected function resolveBrand(Import $import)
  254 + {
  255 + if (empty($import->brandLang)) {
  256 + if (!empty($import->brand_name)) {
  257 +
  258 + if (array_key_exists($import->brand_name, $this->addedBrands)) {
  259 + $import->brandId = $this->addedBrands[ $import->brand_name ]->id;
  260 + return $this->addedBrands[ $import->brand_name ];
  261 + }
  262 +
  263 + $brand = new Brand();
  264 + $brand->generateLangs();
  265 + foreach ($brand->modelLangs as $brandLang) {
  266 + $brandLang->title = $import->brand_name;
  267 + }
  268 + $brand->saveWithLangs();
  269 +
  270 + $this->addedBrands[ $import->brand_name ] = $brand;
  271 +
  272 + $import->brandId = $brand->id;
  273 + return $brand;
  274 + }
  275 + } else {
  276 + $import->brandId = $import->brandLang->brand->id;
  277 + return $import->brandLang->brand;
  278 + }
  279 + return null;
  280 + }
  281 + protected function resolveImage(Import $import)
  282 + {
  283 + if (empty($import->image)) {
  284 + if (!empty($import->image_link)) {
  285 + $image = new Image();
  286 + $image->fileName = $import->image_name;
  287 + $image->fileHash = \Yii::$app->getSecurity()
  288 + ->generateRandomString(32);
  289 +
  290 + if ($image->save()) {
  291 + $saveFileName = $image->id . "_" . $image->fileHash . "." . pathinfo(
  292 + $import->image_name,
  293 + PATHINFO_EXTENSION
  294 + );
  295 + file_put_contents(
  296 + \Yii::getAlias('@storage/') . $saveFileName,
  297 + file_get_contents($import->image_link)
  298 + );
  299 + $import->imageId = $image->id;
  300 + }
  301 + }
  302 + } else {
  303 + $import->imageId = $import->image->id;
  304 + }
  305 + }
  306 +
  307 + protected function parseOptions(Import $import): array
  308 + {
  309 + $result = [];
  310 + if (!empty($import->characteristics)) {
  311 + $items = explode(';', $import->characteristics);
  312 + foreach ($items as $item) {
  313 + $data = explode(':', $item);
  314 + if (!empty($data[ 0 ]) && !empty($data[ 1 ])) {
  315 + $group = $data[ 0 ];
  316 + $options = explode('~', $data[ 1 ]);
  317 + if (!empty($options)) {
  318 + $result[ $group ] = $options;
  319 + }
  320 + }
  321 + }
  322 + }
  323 + return $result;
  324 + }
  325 +
  326 + protected function updateRecord(Import $import)
  327 + {
  328 + /**
  329 + * @var Variant $variant
  330 + */
  331 + $variant = $import->variant;
  332 + $variant->price = $import->price;
  333 + $variant->price_old = $import->price_old;
  334 + $variant->stock = $import->stock;
  335 + $variant->save();
  336 +
  337 + $product = $variant->product;
  338 + $product->mask = $import->mask;
  339 + $product->image_id = $import->imageId;
  340 + $product->brand_id = $import->brandId;
  341 + $product->video = $import->video;
  342 + $product->save();
  343 + foreach ($product->langs as $productLang) {
  344 + $productLang->title = $import->product_name;
  345 + $productLang->description = $import->description;
  346 + $productLang->save();
  347 + }
  348 +
  349 + $product->unlinkAll('categories', true);
  350 + if (!empty($import->categoryId)) {
  351 + $productToCategory = new ProductToCategory();
  352 + $productToCategory->category_id = $import->categoryId;
  353 + $productToCategory->product_id = $product->id;
  354 + $productToCategory->save();
  355 + if (!empty($import->groups)) {
  356 + $this->processGroups($import, $product);
  357 + }
  358 + }
  359 + }
  360 +
  361 + protected function processGroups(Import $import, Product $product)
  362 + {
  363 + $optionIds = $this->saveGroups($import, $import->categoryId);
  364 + if (!empty($optionIds)) {
  365 + ProductToProductOptionExcl::deleteAll(
  366 + [
  367 + 'product_id' => $product->id,
  368 + ]
  369 + );
  370 + }
  371 + $batch = [];
  372 + foreach ($optionIds as $optionId) {
  373 + $batch[] = [
  374 + $product->id,
  375 + $optionId,
  376 + ];
  377 + }
  378 + if (!empty($batch)) {
  379 + \Yii::$app->db->createCommand()
  380 + ->batchInsert(
  381 + 'product_to_product_option_excl',
  382 + [
  383 + 'product_id',
  384 + 'product_option_excl_id',
  385 + ],
  386 + $batch
  387 + )
  388 + ->execute();
  389 + }
  390 + }
  391 +
  392 + protected function createRecord(Import $import)
  393 + {
  394 + $product = new Product();
  395 + $product->detachBehavior('defaultVariant');
  396 + $product->generateLangs();
  397 +
  398 + foreach ($product->modelLangs as $modelLang) {
  399 + $modelLang->title = $import->product_name;
  400 + $modelLang->description = $import->description;
  401 + }
  402 +
  403 + $product->mask = $import->mask;
  404 + $product->image_id = $import->imageId;
  405 + $product->brand_id = $import->brandId;
  406 + $product->video = $import->video;
  407 + $product->saveWithLangs();
  408 +
  409 + $variant = new Variant();
  410 + $variant->product_id = $product->id;
  411 + $variant->generateLangs();
  412 +
  413 + $variant->sku = $import->sku;
  414 +
  415 + $variant->price = $import->price;
  416 + $variant->price_old = $import->price_old;
  417 + $variant->stock = $import->stock;
  418 + foreach ($variant->modelLangs as $lang) {
  419 + $lang->title = $import->sku;
  420 + }
  421 + $variant->saveWithLangs();
  422 +
  423 + if (!empty($import->categoryId)) {
  424 + $productToCategory = new ProductToCategory();
  425 + $productToCategory->category_id = $import->categoryId;
  426 + $productToCategory->product_id = $product->id;
  427 + $productToCategory->save();
  428 +
  429 + if (!empty($import->groups)) {
  430 + $this->processGroups($import, $product);
  431 + }
  432 + }
  433 + }
  434 +
  435 + protected function saveGroups(Import $import, int $categoryId)
  436 + {
  437 + /**
  438 + * @var ProductOptionGroupExcl[] $groups
  439 + */
  440 + $groups = ProductOptionGroupExcl::find()
  441 + ->joinWith('lang')
  442 + ->joinWith('categories')
  443 + ->andWhere(
  444 + [
  445 + 'category_id' => $categoryId,
  446 + 'title' => array_keys($import->groups),
  447 + ]
  448 + )
  449 + ->indexBy(
  450 + function ($row) {
  451 + /**
  452 + * @var ProductOptionGroupExcl $row
  453 + */
  454 + return $row->lang->title;
  455 + }
  456 + )
  457 + ->all();
  458 + $groupMap = array_fill_keys(array_keys($import->groups), null);
  459 + foreach ($groups as $group) {
  460 + $groupMap[ $group->lang->title ] = $group->id;
  461 + }
  462 + $forInsert = [];
  463 + foreach ($groupMap as $title => $group) {
  464 + if (!$group) {
  465 + $forInsert[] = $title;
  466 + }
  467 + }
  468 + $activeLanguageIds = Language::find()
  469 + ->where([ 'status' => true ])
  470 + ->column();
  471 + if (!empty($forInsert)) {
  472 + $forInsertItems = [];
  473 + foreach ($forInsert as $index => $title) {
  474 + $forInsertItems[] = [ true ];
  475 + }
  476 + $result = \Yii::$app->db->createCommand()
  477 + ->batchInsert(
  478 + 'product_option_group_excl',
  479 + [
  480 + 'is_filter',
  481 + ],
  482 + $forInsertItems
  483 + );
  484 + $result->setSql($result->getSql() . ' RETURNING id');
  485 + $groupIds = $result->queryColumn();
  486 + // $forInsertItems = [];
  487 + $forInsertCategories = [];
  488 + foreach ($groupIds as $index => $groupId) {
  489 + $forInsertCategories[] = [
  490 + $categoryId,
  491 + $groupId,
  492 + ];
  493 + foreach ($activeLanguageIds as $activeLanguageId) {
  494 + $groupMap[ $forInsert[ $index ] ] = $groupId;
  495 + // $forInsertItems[] = [
  496 + // $groupId,
  497 + // $forInsert[ $index ],
  498 + // $activeLanguageId,
  499 + // ];
  500 + ( new ProductOptionGroupExclLang(
  501 + [
  502 + 'product_option_group_excl_id' => $groupId,
  503 + 'language_id' => $activeLanguageId,
  504 + 'title' => $forInsert[ $index ],
  505 + ]
  506 + ) )->save(false);
  507 + }
  508 + }
  509 + \Yii::$app->db->createCommand()
  510 + ->batchInsert(
  511 + 'product_option_group_excl_to_category',
  512 + [
  513 + 'category_id',
  514 + 'product_option_group_excl_id',
  515 + ],
  516 + $forInsertCategories
  517 + )
  518 + ->execute();
  519 + // \Yii::$app->db->createCommand()
  520 + // ->batchInsert(
  521 + // 'product_option_group_excl_lang',
  522 + // [
  523 + // 'product_option_group_excl_id',
  524 + // 'title',
  525 + // 'language_id',
  526 + // ],
  527 + // $forInsertItems
  528 + // )
  529 + // ->execute();
  530 + }
  531 + return $this->saveOptions($import, $groupMap, $activeLanguageIds);
  532 + }
  533 +
  534 + /**
  535 + * $groupMap has following array:
  536 + * groupName => groupId
  537 + *
  538 + * @param \artbox\catalog\models\Import $import
  539 + * @param array $groupMap
  540 + * @param array $activeLanguageIds
  541 + *
  542 + * @return array
  543 + */
  544 + protected function saveOptions(Import $import, array $groupMap, array $activeLanguageIds): array
  545 + {
  546 + $optionModelsQuery = ProductOptionExcl::find()
  547 + ->joinWith('lang');
  548 + $i = 0;
  549 + foreach ($import->groups as $group => $options) {
  550 + if ($i) {
  551 + $optionModelsQuery->orWhere(
  552 + [
  553 + 'product_option_group_excl_id' => $groupMap[ $group ],
  554 + 'value' => $options,
  555 + ]
  556 + );
  557 + } else {
  558 + $optionModelsQuery->andWhere(
  559 + [
  560 + 'product_option_group_excl_id' => $groupMap[ $group ],
  561 + 'value' => $options,
  562 + ]
  563 + );
  564 + }
  565 + $i++;
  566 + }
  567 + $optionModelsQuery->indexBy(
  568 + function ($row) {
  569 + /**
  570 + * @var ProductOptionExcl $row
  571 + */
  572 + return $row->lang->value;
  573 + }
  574 + );
  575 + /**
  576 + * @var ProductOptionExcl[] $optionModels
  577 + */
  578 + $optionModels = $optionModelsQuery->all();
  579 + if (!empty($import->groups)) {
  580 + $forInsert = [];
  581 + $optionIds = [];
  582 + $forInsertItems = [];
  583 + foreach ($import->groups as $group => $options) {
  584 + foreach ($options as $option) {
  585 + if (array_key_exists(
  586 + $option,
  587 + $optionModels
  588 + ) && $optionModels[ $option ]->groupId == $groupMap[ $group ]
  589 + ) {
  590 + $optionIds[] = $optionModels[ $option ]->id;
  591 + } else {
  592 + $forInsert[] = $option;
  593 + $forInsertItems[] = [
  594 + $groupMap[ $group ],
  595 + true,
  596 + ];
  597 + }
  598 + }
  599 + }
  600 + if (!empty($forInsertItems)) {
  601 + $result = \Yii::$app->db->createCommand()
  602 + ->batchInsert(
  603 + 'product_option_excl',
  604 + [
  605 + 'product_option_group_excl_id',
  606 + 'status',
  607 + ],
  608 + $forInsertItems
  609 + );
  610 + $result->setSql($result->getSql() . ' RETURNING id');
  611 + $resultIds = $result->queryColumn();
  612 + // $forInsertItems = [];
  613 + foreach ($resultIds as $index => $resultId) {
  614 + foreach ($activeLanguageIds as $activeLanguageId) {
  615 + // $forInsertItems[] = [
  616 + // $resultId,
  617 + // $forInsert[ $index ],
  618 + // $activeLanguageId,
  619 + // ];
  620 + ( new ProductOptionExclLang(
  621 + [
  622 + 'product_option_excl_id' => $resultId,
  623 + 'value' => $forInsert[ $index ],
  624 + 'language_id' => $activeLanguageId,
  625 + ]
  626 + ) )->save(false);
  627 + }
  628 + }
  629 + // if (!empty($forInsertItems)) {
  630 + // \Yii::$app->db->createCommand()
  631 + // ->batchInsert(
  632 + // 'product_option_excl_lang',
  633 + // [
  634 + // 'product_option_excl_id',
  635 + // 'value',
  636 + // 'language_id',
  637 + // ],
  638 + // $forInsertItems
  639 + // )
  640 + // ->execute();
  641 + // }
  642 + }
  643 + if (!empty($resultIds)) {
  644 + $optionIds = array_merge($optionIds, $resultIds);
  645 + }
  646 + return $optionIds;
  647 + }
  648 + return [];
  649 + }
  650 +
  651 + public function actionTest($id)
  652 + {
  653 + \Yii::$app->response->format = Response::FORMAT_JSON;
  654 +
  655 + $array = [
  656 + [
  657 + 'percent' => 10,
  658 + 'finish' => false,
  659 + ],
  660 + [
  661 + 'percent' => 17,
  662 + 'finish' => false,
  663 + ],
  664 + [
  665 + 'percent' => 31,
  666 + 'finish' => false,
  667 + ],
  668 + [
  669 + 'percent' => 44,
  670 + 'finish' => false,
  671 + ],
  672 + [
  673 + 'percent' => 67,
  674 + 'finish' => false,
  675 + ],
  676 + [
  677 + 'percent' => 80,
  678 + 'finish' => false,
  679 + ],
  680 + [
  681 + 'percent' => 100,
  682 + 'finish' => true,
  683 + ],
  684 + ];
  685 +
  686 + return $array[ $id ];
  687 + }
  688 +
  689 +
  690 + public function actionPrice()
  691 + {
  692 + return $this->render('price');
  693 + }
  694 + public function actionPriceUpload(){
  695 + \Yii::$app->response->format = Response::FORMAT_JSON;
  696 +
  697 + $error = false;
  698 + $files = [];
  699 +
  700 + $uploaddir = \Yii::getAlias('@storage/');
  701 + foreach ($_FILES as $file) {
  702 + if (move_uploaded_file($file[ 'tmp_name' ], $uploaddir . 'price_import.xlsx')) {
  703 + $files[] = $uploaddir . $file[ 'name' ];
  704 + } else {
  705 + $error = true;
  706 + }
  707 + }
  708 +
  709 + $data = ( $error ) ? [ 'error' => 'There was an error uploading your files' ] : [ 'files' => $files ];
  710 +
  711 + $this->ImportPrice();
  712 +
  713 + return $data;
  714 + }
  715 +
  716 + // document structure sku price_old price
  717 + public function ImportPrice(){
  718 + $xlsx = PHPExcel_IOFactory::load(\Yii::getAlias('@storage/price_import.xlsx'));
  719 + $xlsx->setActiveSheetIndex(0);
  720 + $sheet = $xlsx->getActiveSheet();
  721 + $rowIterator = $sheet->getRowIterator();
  722 + $j = 0;
  723 + $insert = [];
  724 +
  725 + foreach ($rowIterator as $row) {
  726 + $j++;
  727 + $cellIterator = $row->getCellIterator();
  728 + $row = [];
  729 + $i = 0;
  730 + foreach ($cellIterator as $cell) {
  731 + /**
  732 + * @var \PHPExcel_Cell $cell
  733 + */
  734 + $i++;
  735 + $row[ $i ] = $cell->getValue();
  736 + if ($i > 2) {
  737 + break;
  738 + }
  739 + }
  740 + $insert[] = $row;
  741 +
  742 +
  743 + if (empty($row[ 1 ])) {
  744 + break;
  745 + }
  746 +
  747 + }
  748 + \Yii::$app->db->createCommand()->truncateTable('price_upload')->execute();
  749 + \Yii::$app->db->createCommand()->batchInsert('price_upload',['sku', 'price_old', 'price'], $insert)->execute();
  750 +
  751 + $transaction = \Yii::$app->db->beginTransaction();
  752 + try {
  753 + \Yii::$app->db->createCommand(
  754 + 'UPDATE variant SET price=pu.price
  755 + , price_old=pu.price_old
  756 + FROM (
  757 + SELECT * FROM price_upload
  758 + ) pu
  759 + WHERE variant.sku = pu.sku'
  760 + )
  761 + ->execute();
  762 + $transaction->commit();
  763 + } catch (\Exception $e) {
  764 + $transaction->rollBack();
  765 + throw $e;
  766 + } catch (\Throwable $e) {
  767 + $transaction->rollBack();
  768 + }
  769 +
  770 + // print_r($insert);
  771 + }
  772 + }
0 773 \ No newline at end of file
... ...
artweb/artbox-catalog/controllers/OptionController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\controllers;
  4 +
  5 + use artbox\catalog\models\Option;
  6 + use artbox\catalog\models\OptionGroup;
  7 + use artbox\catalog\models\OptionSearch;
  8 + use Yii;
  9 + use yii\filters\AccessControl;
  10 + use yii\web\Controller;
  11 + use yii\web\NotFoundHttpException;
  12 + use yii\filters\VerbFilter;
  13 +
  14 + /**
  15 + * Abstract OptionController implements the CRUD actions Option models.
  16 + */
  17 + abstract class OptionController extends Controller
  18 + {
  19 + /**
  20 + * @inheritdoc
  21 + */
  22 + public function behaviors()
  23 + {
  24 + return [
  25 + 'access' => [
  26 + 'class' => AccessControl::className(),
  27 + 'rules' => [
  28 + [
  29 + 'actions' => [
  30 + 'login',
  31 + 'error',
  32 + ],
  33 + 'allow' => true,
  34 + ],
  35 + [
  36 + 'allow' => true,
  37 + 'roles' => [ '@' ],
  38 + ],
  39 + ],
  40 + ],
  41 + 'verbs' => [
  42 + 'class' => VerbFilter::className(),
  43 + 'actions' => [
  44 + 'delete' => [ 'POST' ],
  45 + ],
  46 + ],
  47 + ];
  48 + }
  49 +
  50 + /**
  51 + * Lists all Option models.
  52 + *
  53 + * @param int $group_id
  54 + *
  55 + * @return mixed
  56 + */
  57 + public function actionIndex($group_id)
  58 + {
  59 + $group = $this->findGroup($group_id);
  60 + $searchModel = $this->createSearchModel();
  61 + $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $group);
  62 +
  63 + return $this->render(
  64 + 'index',
  65 + [
  66 + 'searchModel' => $searchModel,
  67 + 'dataProvider' => $dataProvider,
  68 + 'group' => $group,
  69 + ]
  70 + );
  71 + }
  72 +
  73 + /**
  74 + * Displays a single Option model.
  75 + *
  76 + * @param integer $id
  77 + *
  78 + * @return mixed
  79 + */
  80 + public function actionView($id)
  81 + {
  82 + return $this->render(
  83 + 'view',
  84 + [
  85 + 'model' => $this->findModel($id),
  86 + ]
  87 + );
  88 + }
  89 +
  90 + /**
  91 + * Creates a new Option model.
  92 + * If creation is successful, the browser will be redirected to the 'view' page.
  93 + *
  94 + * @param int $group_id
  95 + *
  96 + * @return mixed
  97 + */
  98 + public function actionCreate($group_id)
  99 + {
  100 + $group = $this->findGroup($group_id);
  101 + $model = $this->createModel();
  102 + $model->setGroupId($group_id);
  103 + $model->generateLangs();
  104 + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) {
  105 + return $this->redirect(
  106 + [
  107 + 'view',
  108 + 'id' => $model->id,
  109 + ]
  110 + );
  111 + }
  112 + return $this->render(
  113 + 'create',
  114 + [
  115 + 'model' => $model,
  116 + 'modelLangs' => $model->modelLangs,
  117 + 'group' => $group,
  118 + ]
  119 + );
  120 + }
  121 +
  122 + /**
  123 + * Updates an existing Option model.
  124 + * If update is successful, the browser will be redirected to the 'view' page.
  125 + *
  126 + * @param integer $id
  127 + *
  128 + * @return mixed
  129 + */
  130 + public function actionUpdate($id)
  131 + {
  132 + $model = $this->findModel($id);
  133 + $model->generateLangs();
  134 +
  135 + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) {
  136 + return $this->redirect(
  137 + [
  138 + 'view',
  139 + 'id' => $model->id,
  140 + ]
  141 + );
  142 + }
  143 + return $this->render(
  144 + 'update',
  145 + [
  146 + 'model' => $model,
  147 + 'modelLangs' => $model->modelLangs,
  148 + ]
  149 + );
  150 + }
  151 +
  152 + /**
  153 + * Deletes an existing Option model.
  154 + * If deletion is successful, the browser will be redirected to the 'index' page.
  155 + *
  156 + * @param integer $id
  157 + *
  158 + * @return mixed
  159 + */
  160 + public function actionDelete($id)
  161 + {
  162 + $model = $this->findModel($id);
  163 + $groupId = $model->groupId;
  164 + $model->delete();
  165 +
  166 + return $this->redirect(
  167 + [
  168 + 'index',
  169 + 'group_id' => $groupId,
  170 + ]
  171 + );
  172 + }
  173 +
  174 + /**
  175 + * Finds the Option model based on its primary key value.
  176 + * If the model is not found, a 404 HTTP exception will be thrown.
  177 + *
  178 + * @param integer $id
  179 + *
  180 + * @return Option the loaded model
  181 + * @throws NotFoundHttpException if the model cannot be found
  182 + */
  183 + protected function findModel($id): Option
  184 + {
  185 + if (( $model = $this->findOne($id) ) !== null) {
  186 + return $model;
  187 + } else {
  188 + throw new NotFoundHttpException('The requested page does not exist.');
  189 + }
  190 + }
  191 +
  192 + /**
  193 + * Finds the OptionGroup model based on its primary key value.
  194 + * If the model is not found, a 404 HTTP exception will be thrown.
  195 + *
  196 + * @param integer $id
  197 + *
  198 + * @return OptionGroup the loaded model
  199 + * @throws NotFoundHttpException if the model cannot be found
  200 + */
  201 + protected function findGroup($id): OptionGroup
  202 + {
  203 + if (( $model = $this->findOneGroup($id) ) !== null) {
  204 + return $model;
  205 + } else {
  206 + throw new NotFoundHttpException('The requested page does not exist.');
  207 + }
  208 + }
  209 +
  210 + /**
  211 + * Create exact model
  212 + *
  213 + * @return Option
  214 + */
  215 + protected abstract function createModel(): Option;
  216 +
  217 + /**
  218 + * Create exact search model
  219 + *
  220 + * @return OptionSearch
  221 + */
  222 + protected abstract function createSearchModel(): OptionSearch;
  223 +
  224 + /**
  225 + * Find exact model
  226 + *
  227 + * @param $id
  228 + *
  229 + * @return Option|null
  230 + */
  231 + protected abstract function findOne($id);
  232 +
  233 + /**
  234 + * Find exact group
  235 + *
  236 + * @param $id
  237 + *
  238 + * @return OptionGroup|null
  239 + */
  240 + protected abstract function findOneGroup($id);
  241 + }
... ...
artweb/artbox-catalog/controllers/OptionGroupController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\controllers;
  4 +
  5 + use artbox\catalog\models\Category;
  6 + use artbox\catalog\models\OptionGroup;
  7 + use artbox\catalog\models\OptionGroupSearch;
  8 + use Yii;
  9 + use yii\filters\AccessControl;
  10 + use yii\helpers\ArrayHelper;
  11 + use yii\helpers\Html;
  12 + use yii\web\Controller;
  13 + use yii\web\NotFoundHttpException;
  14 + use yii\filters\VerbFilter;
  15 +
  16 + /**
  17 + * Abstract OptionGroupController implements the CRUD actions OptionGroup models.
  18 + */
  19 + abstract class OptionGroupController extends Controller
  20 + {
  21 + /**
  22 + * @inheritdoc
  23 + */
  24 + public function behaviors()
  25 + {
  26 + return [
  27 + 'access' => [
  28 + 'class' => AccessControl::className(),
  29 + 'rules' => [
  30 + [
  31 + 'actions' => [
  32 + 'login',
  33 + 'error',
  34 + ],
  35 + 'allow' => true,
  36 + ],
  37 + [
  38 + 'allow' => true,
  39 + 'roles' => [ '@' ],
  40 + ],
  41 + ],
  42 + ],
  43 + 'verbs' => [
  44 + 'class' => VerbFilter::className(),
  45 + 'actions' => [
  46 + 'delete' => [ 'POST' ],
  47 + ],
  48 + ],
  49 + ];
  50 + }
  51 +
  52 + /**
  53 + * Lists all OptionGroup models.
  54 + *
  55 + * @return mixed
  56 + */
  57 + public function actionIndex()
  58 + {
  59 + $searchModel = $this->createSearchModel();
  60 + $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  61 +
  62 + return $this->render(
  63 + 'index',
  64 + [
  65 + 'searchModel' => $searchModel,
  66 + 'dataProvider' => $dataProvider,
  67 + ]
  68 + );
  69 + }
  70 +
  71 + /**
  72 + * Displays a single ProductOptionGroupCompl model.
  73 + *
  74 + * @param integer $id
  75 + *
  76 + * @return mixed
  77 + */
  78 + public function actionView($id)
  79 + {
  80 + return $this->render(
  81 + 'view',
  82 + [
  83 + 'model' => $this->findModel($id),
  84 + ]
  85 + );
  86 + }
  87 +
  88 + /**
  89 + * Creates a new OptionGroup model.
  90 + * If creation is successful, the browser will be redirected to the 'view' page.
  91 + *
  92 + * @return mixed
  93 + */
  94 + public function actionCreate()
  95 + {
  96 + $model = $this->createModel();
  97 + $model->generateLangs();
  98 + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) {
  99 + $categories = Category::find()
  100 + ->where([ 'id' => \Yii::$app->request->post('categoryIds') ])
  101 + ->all();
  102 + $model->linkMany('categories', $categories);
  103 + return $this->redirect(
  104 + [
  105 + 'view',
  106 + 'id' => $model->id,
  107 + ]
  108 + );
  109 + }
  110 + return $this->render(
  111 + 'create',
  112 + [
  113 + 'model' => $model,
  114 + 'modelLangs' => $model->modelLangs,
  115 + ]
  116 + );
  117 + }
  118 +
  119 + /**
  120 + * Updates an existing OptionGroup model.
  121 + * If update is successful, the browser will be redirected to the 'view' page.
  122 + *
  123 + * @param integer $id
  124 + *
  125 + * @return mixed
  126 + */
  127 + public function actionUpdate($id)
  128 + {
  129 + // var_dump(\Yii::$app->request->post('Categories'));die();
  130 + $model = $this->findModel($id);
  131 + $model->generateLangs();
  132 +
  133 + $model->categoryIds = ArrayHelper::map(
  134 + $model->categories,
  135 + 'id',
  136 + 'lang.title'
  137 + );
  138 +
  139 + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) {
  140 + $categories = \Yii::$app->request->post('Categories') ?? [];
  141 + $this->saveCategories($model, $categories);
  142 +
  143 + return $this->redirect(
  144 + [
  145 + 'view',
  146 + 'id' => $model->id,
  147 + ]
  148 + );
  149 + }
  150 + return $this->render(
  151 + 'update',
  152 + [
  153 + 'model' => $model,
  154 + 'modelLangs' => $model->modelLangs,
  155 + ]
  156 + );
  157 + }
  158 +
  159 + /**
  160 + * Deletes an existing OptionGroup model.
  161 + * If deletion is successful, the browser will be redirected to the 'index' page.
  162 + *
  163 + * @param integer $id
  164 + *
  165 + * @return mixed
  166 + */
  167 + public function actionDelete($id)
  168 + {
  169 + $this->findModel($id)
  170 + ->delete();
  171 +
  172 + return $this->redirect([ 'index' ]);
  173 + }
  174 +
  175 + /**
  176 + * Finds the OptionGroup model based on its primary key value.
  177 + * If the model is not found, a 404 HTTP exception will be thrown.
  178 + *
  179 + * @param integer $id
  180 + *
  181 + * @return OptionGroup the loaded model
  182 + * @throws NotFoundHttpException if the model cannot be found
  183 + */
  184 + protected function findModel($id): OptionGroup
  185 + {
  186 + if (( $model = $this->findOne($id) ) !== null) {
  187 + return $model;
  188 + } else {
  189 + throw new NotFoundHttpException('The requested page does not exist.');
  190 + }
  191 + }
  192 +
  193 + /**
  194 + * @param \artbox\catalog\models\OptionGroup $model
  195 + * @param array $categories
  196 + */
  197 + protected function saveCategories(OptionGroup $model, array $categories)
  198 + {
  199 + $batch = [];
  200 + foreach ($categories as $id => $category) {
  201 + $batch[] = [
  202 + $model->id,
  203 + $id,
  204 + $category[ 'sort' ] ?? null,
  205 + $category[ 'status' ] ?? false,
  206 + $category[ 'in_menu' ] ?? false,
  207 + $category[ 'is_filter' ] ?? false,
  208 + ];
  209 + }
  210 + // var_dump($batch);die();
  211 + $transaction = \Yii::$app->db->beginTransaction();
  212 + try {
  213 + $model->unlinkAll('categories', true);
  214 + $model->insertCategories($batch);
  215 +
  216 + $transaction->commit();
  217 + } catch (\Exception $exception) {
  218 + $transaction->rollBack();
  219 + die('error');
  220 + }
  221 + }
  222 +
  223 + /**
  224 + * Create exact model
  225 + *
  226 + * @return OptionGroup
  227 + */
  228 + protected abstract function createModel(): OptionGroup;
  229 +
  230 + /**
  231 + * Create exact search model
  232 + *
  233 + * @return OptionGroupSearch
  234 + */
  235 + protected abstract function createSearchModel(): OptionGroupSearch;
  236 +
  237 + /**
  238 + * Find exact model
  239 + *
  240 + * @param $id
  241 + *
  242 + * @return OptionGroup|null
  243 + */
  244 + protected abstract function findOne($id);
  245 +
  246 + /**
  247 + * Return new row for group-to-category table
  248 + *
  249 + * @return string
  250 + */
  251 + public function actionGetRow()
  252 + {
  253 + $id = \Yii::$app->request->post('id');
  254 + $title = \Yii::$app->request->post('title');
  255 +
  256 + if (empty($id) || empty($title)) {
  257 + return '';
  258 + }
  259 +
  260 + $row = Html::beginTag('tr');
  261 + $row .= Html::tag('td', $title);
  262 + $row .= Html::tag(
  263 + 'td',
  264 + Html::input(
  265 + 'number',
  266 + 'Categories[' . $id . '][sort]',
  267 + null,
  268 + [
  269 + 'class' => 'form-control',
  270 + ]
  271 + )
  272 + );
  273 + $row .= Html::tag(
  274 + 'td',
  275 + Html::checkbox(
  276 + 'Categories[' . $id . '][status]',
  277 + null,
  278 + [
  279 + 'class' => 'flat',
  280 + ]
  281 + )
  282 + );
  283 + $row .= Html::tag(
  284 + 'td',
  285 + Html::checkbox(
  286 + 'Categories[' . $id . '][in_menu]',
  287 + null,
  288 + [
  289 + 'class' => 'flat',
  290 + ]
  291 + )
  292 + );
  293 + $row .= Html::tag(
  294 + 'td',
  295 + Html::checkbox(
  296 + 'Categories[' . $id . '][is_filter]',
  297 + null,
  298 + [
  299 + 'class' => 'flat',
  300 + ]
  301 + )
  302 + );
  303 + $row .= Html::tag(
  304 + 'td',
  305 + Html::a(
  306 + '<span class="fa fa-trash"></span>',
  307 + '#',
  308 + [
  309 + 'class' => 'delete-row',
  310 + ]
  311 + )
  312 + );
  313 + $row .= Html::endTag('tr');
  314 +
  315 + return $row;
  316 + }
  317 + }
... ...
artweb/artbox-catalog/controllers/ProductController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\controllers;
  4 +
  5 + use artbox\catalog\models\Category;
  6 + use artbox\catalog\models\ProductOptionCompl;
  7 + use artbox\catalog\models\ProductOptionExcl;
  8 + use artbox\catalog\models\ProductOptionGroupCompl;
  9 + use artbox\catalog\models\ProductOptionGroupExcl;
  10 + use artbox\catalog\models\ProductToImage;
  11 + use Yii;
  12 + use artbox\catalog\models\Product;
  13 + use artbox\catalog\models\ProductSearch;
  14 + use yii\filters\AccessControl;
  15 + use yii\helpers\ArrayHelper;
  16 + use yii\web\Controller;
  17 + use yii\web\NotFoundHttpException;
  18 + use yii\filters\VerbFilter;
  19 + use yii\web\Response;
  20 +
  21 + /**
  22 + * ProductController implements the CRUD actions for Product model.
  23 + */
  24 + class ProductController extends Controller
  25 + {
  26 + /**
  27 + * @inheritdoc
  28 + */
  29 + public function getViewPath()
  30 + {
  31 + return '@artbox/catalog/views/product';
  32 + }
  33 +
  34 + /**
  35 + * @inheritdoc
  36 + */
  37 + public function behaviors()
  38 + {
  39 + return [
  40 + 'access' => [
  41 + 'class' => AccessControl::className(),
  42 + 'rules' => [
  43 + [
  44 + 'actions' => [
  45 + 'login',
  46 + 'error',
  47 + ],
  48 + 'allow' => true,
  49 + ],
  50 + [
  51 + 'allow' => true,
  52 + 'roles' => [ '@' ],
  53 + ],
  54 + ],
  55 + ],
  56 + 'verbs' => [
  57 + 'class' => VerbFilter::className(),
  58 + 'actions' => [
  59 + 'delete' => [ 'POST' ],
  60 + 'delete-multiple' => [ 'POST' ],
  61 + ],
  62 + ],
  63 + ];
  64 + }
  65 +
  66 + /**
  67 + * Lists all Product models.
  68 + *
  69 + * @return mixed
  70 + */
  71 + public function actionIndex()
  72 + {
  73 + $searchModel = new ProductSearch();
  74 + $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  75 +
  76 + return $this->render(
  77 + 'index',
  78 + [
  79 + 'searchModel' => $searchModel,
  80 + 'dataProvider' => $dataProvider,
  81 + ]
  82 + );
  83 + }
  84 +
  85 + /**
  86 + * Displays a single Product model.
  87 + *
  88 + * @param integer $id
  89 + *
  90 + * @return mixed
  91 + */
  92 + public function actionView($id)
  93 + {
  94 + return $this->render(
  95 + 'view',
  96 + [
  97 + 'model' => $this->findModel($id),
  98 + ]
  99 + );
  100 + }
  101 +
  102 + /**
  103 + * Creates a new Product model.
  104 + * If creation is successful, the browser will be redirected to the 'view' page.
  105 + *
  106 + * @return mixed
  107 + */
  108 + public function actionCreate()
  109 + {
  110 + $model = new Product();
  111 + $model->generateLangs();
  112 + $groups_compl = [];
  113 + $groups_excl = [];
  114 + $model->categoryIds = [];
  115 +
  116 + $model->recommendIds = [];
  117 +
  118 + $model->loadMask(\Yii::$app->request);
  119 +
  120 + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) {
  121 + $categories = Category::find()
  122 + ->where([ 'id' => \Yii::$app->request->post('categoryIds') ])
  123 + ->all();
  124 +
  125 + $model->linkMany('categories', $categories);
  126 +
  127 + $products = Product::find()
  128 + ->where([ 'id' => \Yii::$app->request->post('recommendIds') ])
  129 + ->all();
  130 +
  131 + $model->linkMany('recommendedProducts', $products);
  132 +
  133 + $model->saveImages(\Yii::$app->request->post());
  134 +
  135 + return $this->redirect(
  136 + [
  137 + 'view',
  138 + 'id' => $model->id,
  139 + ]
  140 + );
  141 + }
  142 + return $this->render(
  143 + 'create',
  144 + [
  145 + 'model' => $model,
  146 + 'modelLangs' => $model->modelLangs,
  147 + 'groups_compl' => $groups_compl,
  148 + 'groups_excl' => $groups_excl,
  149 + ]
  150 + );
  151 + }
  152 +
  153 + /**
  154 + * Updates an existing Product model.
  155 + * If update is successful, the browser will be redirected to the 'view' page.
  156 + *
  157 + * @param integer $id
  158 + *
  159 + * @return mixed
  160 + */
  161 + public function actionUpdate($id)
  162 + {
  163 + $model = $this->findModel($id);
  164 + $model->generateLangs();
  165 +
  166 + $model->categoryIds = ArrayHelper::map(
  167 + $model->categories,
  168 + 'id',
  169 + 'lang.title'
  170 + );
  171 +
  172 + $model->recommendIds = ArrayHelper::map(
  173 + $model->recommendedProducts,
  174 + 'id',
  175 + 'lang.title'
  176 + );
  177 +
  178 + $groups_compl = [];
  179 + $groups_excl = [];
  180 + if (!empty($model->categories)) {
  181 + $groups_compl = ProductOptionGroupCompl::find()
  182 + ->innerJoin(
  183 + 'product_option_group_compl_to_category',
  184 + 'product_option_group_compl_to_category.product_option_group_compl_id = product_option_group_compl.id'
  185 + )
  186 + ->where(
  187 + [
  188 + 'product_option_group_compl_to_category.category_id' => ArrayHelper::getColumn(
  189 + $model->categories,
  190 + 'id'
  191 + ),
  192 + ]
  193 + )
  194 + ->with('options.lang')
  195 + ->all();
  196 + $groups_excl = ProductOptionGroupExcl::find()
  197 + ->innerJoin(
  198 + 'product_option_group_excl_to_category',
  199 + 'product_option_group_excl_to_category.product_option_group_excl_id = product_option_group_excl.id'
  200 + )
  201 + ->where(
  202 + [
  203 + 'product_option_group_excl_to_category.category_id' => ArrayHelper::getColumn(
  204 + $model->categories,
  205 + 'id'
  206 + ),
  207 + ]
  208 + )
  209 + ->with('options.lang')
  210 + ->all();
  211 + }
  212 +
  213 + $model->loadMask(\Yii::$app->request);
  214 +
  215 + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) {
  216 + $categories = Category::find()
  217 + ->where([ 'id' => \Yii::$app->request->post('categoryIds') ])
  218 + ->all();
  219 +
  220 + $model->linkMany('categories', $categories);
  221 + $products = Product::find()
  222 + ->where([ 'id' => \Yii::$app->request->post('recommendIds') ])
  223 + ->all();
  224 +
  225 + $model->linkMany('recommendedProducts', $products);
  226 +// if (!empty(\Yii::$app->request->post('Product')[ 'productOptionCompls' ])) {
  227 +// $options = ProductOptionCompl::findAll($model->productOptionCompls);
  228 +// $model->linkMany('productOptionCompls', $options);
  229 +// } else {
  230 +// $model->unlinkAll('productOptionCompls', true);
  231 +// }
  232 +// if (!empty(\Yii::$app->request->post('Product')[ 'productOptionExcls' ])) {
  233 +// $options = ProductOptionExcl::findAll($model->productOptionExcls);
  234 +// $model->linkMany('productOptionExcls', $options);
  235 +// } else {
  236 +// $model->unlinkAll('productOptionExcls', true);
  237 +// }
  238 +
  239 + $model->saveImages(\Yii::$app->request->post());
  240 +
  241 + return $this->redirect(
  242 + [
  243 + 'view',
  244 + 'id' => $model->id,
  245 + ]
  246 + );
  247 + }
  248 + return $this->render(
  249 + 'update',
  250 + [
  251 + 'model' => $model,
  252 + 'modelLangs' => $model->modelLangs,
  253 + 'groups_compl' => $groups_compl,
  254 + 'groups_excl' => $groups_excl,
  255 + ]
  256 + );
  257 + }
  258 +
  259 + /**
  260 + * Deletes an existing Product model.
  261 + * If deletion is successful, the browser will be redirected to the 'index' page.
  262 + *
  263 + * @param integer $id
  264 + *
  265 + * @return mixed
  266 + */
  267 + public function actionDelete($id)
  268 + {
  269 + $this->findModel($id)
  270 + ->delete();
  271 +
  272 + return $this->redirect([ 'index' ]);
  273 + }
  274 +
  275 + public function actionDeleteMultiple($ids)
  276 + {
  277 + $response = \Yii::$app->response;
  278 + $response->format = $response::FORMAT_JSON;
  279 + $ids = explode(',', $ids);
  280 + if (!empty($ids)) {
  281 + if (Product::deleteAll(
  282 + [
  283 + 'id' => $ids,
  284 + ]
  285 + )
  286 + ) {
  287 + return [
  288 + 'success' => true,
  289 + ];
  290 + }
  291 + }
  292 + return [
  293 + 'failed' => true,
  294 + ];
  295 + }
  296 +
  297 + /**
  298 + * Finds the Product model based on its primary key value.
  299 + * If the model is not found, a 404 HTTP exception will be thrown.
  300 + *
  301 + * @param integer $id
  302 + *
  303 + * @return Product the loaded model
  304 + * @throws NotFoundHttpException if the model cannot be found
  305 + */
  306 + protected function findModel($id)
  307 + {
  308 + if (( $model = Product::find()
  309 + ->with('categories.lang')
  310 + ->where([ 'id' => $id ])
  311 + ->one() ) !== null
  312 + ) {
  313 + return $model;
  314 + } else {
  315 + throw new NotFoundHttpException('The requested page does not exist.');
  316 + }
  317 + }
  318 +
  319 + protected function saveImages(Product $model)
  320 + {
  321 + $model->unlinkAll('images', true);
  322 +
  323 + if (!empty(\Yii::$app->request->post('images'))) {
  324 + if (is_array(\Yii::$app->request->post('images'))) {
  325 + foreach (\Yii::$app->request->post('images') as $image_id) {
  326 + $m = new ProductToImage();
  327 + $m->image_id = $image_id;
  328 + $m->product_id = $model->id;
  329 + $m->save();
  330 + }
  331 + } else {
  332 + $m = new ProductToImage();
  333 + $m->image_id = \Yii::$app->request->post('images');
  334 + $m->product_id = $model->id;
  335 + $m->save();
  336 + }
  337 + }
  338 + }
  339 +
  340 + /**
  341 + * @param string $q
  342 + * @param int|null $id
  343 + *
  344 + * @return array
  345 + */
  346 + public function actionList(string $q = null, int $id = null)
  347 + {
  348 + \Yii::$app->response->format = Response::FORMAT_JSON;
  349 + $out = [
  350 + 'results' => [
  351 + 'id' => '',
  352 + 'text' => '',
  353 + ],
  354 + ];
  355 + if (!is_null($q)) {
  356 + $out[ 'results' ] = Product::find()
  357 + ->joinWith('lang')
  358 + ->select(
  359 + [
  360 + 'product.id as id',
  361 + 'product_lang.title as text',
  362 + ]
  363 + )
  364 + ->where(
  365 + [
  366 + 'like',
  367 + 'product_lang.title',
  368 + $q,
  369 + ]
  370 + )
  371 + ->andFilterWhere(
  372 + [
  373 + '!=',
  374 + 'product.id',
  375 + $id,
  376 + ]
  377 + )
  378 + ->limit(20)
  379 + ->asArray()
  380 + ->all();
  381 + }
  382 + return $out;
  383 + }
  384 + }
... ...
artweb/artbox-catalog/controllers/ProductOptionComplController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\controllers;
  4 +
  5 + use artbox\catalog\models\Option;
  6 + use artbox\catalog\models\OptionGroup;
  7 + use artbox\catalog\models\OptionSearch;
  8 + use artbox\catalog\models\ProductOptionCompl;
  9 + use artbox\catalog\models\ProductOptionComplSearch;
  10 + use artbox\catalog\models\ProductOptionGroupCompl;
  11 + use yii\filters\AccessControl;
  12 +
  13 + /**
  14 + * ProductOptionComplController implements the CRUD actions for ProductOptionCompl model.
  15 + */
  16 + class ProductOptionComplController extends OptionController
  17 + {
  18 + /**
  19 + * @inheritdoc
  20 + */
  21 + public function getViewPath()
  22 + {
  23 + return '@artbox/catalog/views/product-option-compl';
  24 + }
  25 + public function behaviors()
  26 + {
  27 + return [
  28 + 'access' => [
  29 + 'class' => AccessControl::className(),
  30 + 'rules' => [
  31 + [
  32 + 'actions' => [
  33 + 'login',
  34 + 'error',
  35 + ],
  36 + 'allow' => true,
  37 + ],
  38 + [
  39 + 'allow' => true,
  40 + 'roles' => [ '@' ],
  41 + ],
  42 + ],
  43 + ],
  44 + ];
  45 + }
  46 +
  47 + /**
  48 + * Create exact model
  49 + *
  50 + * @return Option
  51 + */
  52 + protected function createModel(): Option
  53 + {
  54 + return new ProductOptionCompl();
  55 + }
  56 + /**
  57 + * Create exact search model
  58 + *
  59 + * @return OptionSearch
  60 + */
  61 + protected function createSearchModel(): OptionSearch
  62 + {
  63 + return new ProductOptionComplSearch();
  64 + }
  65 + /**
  66 + * Find exact model
  67 + *
  68 + * @param $id
  69 + *
  70 + * @return Option|null
  71 + */
  72 + protected function findOne($id)
  73 + {
  74 + return ProductOptionCompl::findOne($id);
  75 + }
  76 + /**
  77 + * Find exact group
  78 + *
  79 + * @param $id
  80 + *
  81 + * @return OptionGroup|null
  82 + */
  83 + protected function findOneGroup($id)
  84 + {
  85 + return ProductOptionGroupCompl::findOne($id);
  86 + }
  87 + }
... ...
artweb/artbox-catalog/controllers/ProductOptionExclController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\controllers;
  4 +
  5 + use artbox\catalog\models\Option;
  6 + use artbox\catalog\models\OptionGroup;
  7 + use artbox\catalog\models\OptionSearch;
  8 + use artbox\catalog\models\ProductOptionExcl;
  9 + use artbox\catalog\models\ProductOptionExclSearch;
  10 + use artbox\catalog\models\ProductOptionGroupExcl;
  11 + use yii\filters\AccessControl;
  12 +
  13 + /**
  14 + * ProductOptionExclController implements the CRUD actions for ProductOptionExcl model.
  15 + */
  16 + class ProductOptionExclController extends OptionController
  17 + {
  18 + /**
  19 + * @inheritdoc
  20 + */
  21 + public function getViewPath()
  22 + {
  23 + return '@artbox/catalog/views/product-option-excl';
  24 + }
  25 + public function behaviors()
  26 + {
  27 + return [
  28 + 'access' => [
  29 + 'class' => AccessControl::className(),
  30 + 'rules' => [
  31 + [
  32 + 'actions' => [
  33 + 'login',
  34 + 'error',
  35 + ],
  36 + 'allow' => true,
  37 + ],
  38 + [
  39 + 'allow' => true,
  40 + 'roles' => [ '@' ],
  41 + ],
  42 + ],
  43 + ],
  44 + ];
  45 + }
  46 + /**
  47 + * Create exact model
  48 + *
  49 + * @return Option
  50 + */
  51 + protected function createModel(): Option
  52 + {
  53 + return new ProductOptionExcl();
  54 + }
  55 + /**
  56 + * Create exact search model
  57 + *
  58 + * @return OptionSearch
  59 + */
  60 + protected function createSearchModel(): OptionSearch
  61 + {
  62 + return new ProductOptionExclSearch();
  63 + }
  64 + /**
  65 + * Find exact model
  66 + *
  67 + * @param $id
  68 + *
  69 + * @return Option|null
  70 + */
  71 + protected function findOne($id)
  72 + {
  73 + return ProductOptionExcl::findOne($id);
  74 + }
  75 + /**
  76 + * Find exact group
  77 + *
  78 + * @param $id
  79 + *
  80 + * @return OptionGroup|null
  81 + */
  82 + protected function findOneGroup($id)
  83 + {
  84 + return ProductOptionGroupExcl::findOne($id);
  85 + }
  86 + }
... ...
artweb/artbox-catalog/controllers/ProductOptionGroupComplController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\controllers;
  4 +
  5 + use artbox\catalog\models\OptionGroup;
  6 + use artbox\catalog\models\OptionGroupSearch;
  7 + use artbox\catalog\models\ProductOptionGroupCompl;
  8 + use artbox\catalog\models\ProductOptionGroupComplSearch;
  9 + use yii\filters\AccessControl;
  10 +
  11 + /**
  12 + * ProductOptionGroupComplController implements the CRUD actions for ProductOptionGroupCompl model.
  13 + */
  14 + class ProductOptionGroupComplController extends OptionGroupController
  15 + {
  16 + /**
  17 + * @inheritdoc
  18 + */
  19 + public function getViewPath()
  20 + {
  21 + return '@artbox/catalog/views/product-option-group-compl';
  22 + }
  23 + public function behaviors()
  24 + {
  25 + return [
  26 + 'access' => [
  27 + 'class' => AccessControl::className(),
  28 + 'rules' => [
  29 + [
  30 + 'actions' => [
  31 + 'login',
  32 + 'error',
  33 + ],
  34 + 'allow' => true,
  35 + ],
  36 + [
  37 + 'allow' => true,
  38 + 'roles' => [ '@' ],
  39 + ],
  40 + ],
  41 + ],
  42 + ];
  43 + }
  44 + /**
  45 + * @inheritdoc
  46 + */
  47 + protected function createModel(): OptionGroup
  48 + {
  49 + return new ProductOptionGroupCompl();
  50 + }
  51 +
  52 + /**
  53 + * @inheritdoc
  54 + */
  55 + protected function createSearchModel(): OptionGroupSearch
  56 + {
  57 + return new ProductOptionGroupComplSearch();
  58 + }
  59 +
  60 + /**
  61 + * @inheritdoc
  62 + */
  63 + protected function findOne($id)
  64 + {
  65 + return ProductOptionGroupCompl::findOne($id);
  66 + }
  67 + }
... ...
artweb/artbox-catalog/controllers/ProductOptionGroupExclController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\controllers;
  4 +
  5 + use artbox\catalog\models\OptionGroup;
  6 + use artbox\catalog\models\OptionGroupSearch;
  7 + use artbox\catalog\models\ProductOptionGroupExcl;
  8 + use artbox\catalog\models\ProductOptionGroupExclSearch;
  9 + use yii\filters\AccessControl;
  10 +
  11 + /**
  12 + * ProductOptionGroupExclController implements the CRUD actions for ProductOptionGroupExcl model.
  13 + */
  14 + class ProductOptionGroupExclController extends OptionGroupController
  15 + {
  16 + /**
  17 + * @inheritdoc
  18 + */
  19 + public function getViewPath()
  20 + {
  21 + return '@artbox/catalog/views/product-option-group-excl';
  22 + }
  23 + public function behaviors()
  24 + {
  25 + return [
  26 + 'access' => [
  27 + 'class' => AccessControl::className(),
  28 + 'rules' => [
  29 + [
  30 + 'actions' => [
  31 + 'login',
  32 + 'error',
  33 + ],
  34 + 'allow' => true,
  35 + ],
  36 + [
  37 + 'allow' => true,
  38 + 'roles' => [ '@' ],
  39 + ],
  40 + ],
  41 + ],
  42 + ];
  43 + }
  44 +
  45 + /**
  46 + * @inheritdoc
  47 + */
  48 + protected function createModel(): OptionGroup
  49 + {
  50 + return new ProductOptionGroupExcl();
  51 + }
  52 +
  53 + /**
  54 + * @inheritdoc
  55 + */
  56 + protected function createSearchModel(): OptionGroupSearch
  57 + {
  58 + return new ProductOptionGroupExclSearch();
  59 + }
  60 +
  61 + /**
  62 + * @inheritdoc
  63 + */
  64 + protected function findOne($id)
  65 + {
  66 + return ProductOptionGroupExcl::findOne($id);
  67 + }
  68 + }
... ...
artweb/artbox-catalog/controllers/UnloadController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\controllers;
  4 +
  5 + use Yii;
  6 + use yii\filters\AccessControl;
  7 + use yii\web\Controller;
  8 +
  9 + /**
  10 + * UnloadController implements unloading of catalog to different services.
  11 + */
  12 + class UnloadController extends Controller
  13 + {
  14 + /**
  15 + * @inheritdoc
  16 + */
  17 + public function getViewPath()
  18 + {
  19 + return '@backend/views/unload';
  20 + }
  21 +
  22 + /**
  23 + * @inheritdoc
  24 + */
  25 + public function behaviors()
  26 + {
  27 + return [
  28 + 'access' => [
  29 + 'class' => AccessControl::className(),
  30 + 'rules' => [
  31 + [
  32 + 'actions' => [
  33 + 'login',
  34 + 'error',
  35 + ],
  36 + 'allow' => true,
  37 + ],
  38 + [
  39 + 'allow' => true,
  40 + 'roles' => [ '@' ],
  41 + ],
  42 + ],
  43 + ],
  44 + ];
  45 + }
  46 +
  47 + /**
  48 + * Unload prompt page.
  49 + *
  50 + * @return mixed
  51 + */
  52 + public function actionIndex()
  53 + {
  54 + return $this->render('index');
  55 + }
  56 +
  57 +// public function actionHotline()
  58 +// {
  59 +// exec('cd ../../; php yii export-xml/hotline;');
  60 +// }
  61 +//
  62 +// public function actionNadavi()
  63 +// {
  64 +// exec('cd ../../; php yii export-xml/nadavi;');
  65 +// }
  66 + }
... ...
artweb/artbox-catalog/controllers/VariantController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\controllers;
  4 +
  5 + use artbox\catalog\models\Product;
  6 + use artbox\catalog\models\VariantOptionCompl;
  7 + use artbox\catalog\models\VariantOptionExcl;
  8 + use artbox\catalog\models\VariantOptionGroupCompl;
  9 + use artbox\catalog\models\VariantOptionGroupExcl;
  10 + use artbox\stock\models\VariantToShop;
  11 + use Yii;
  12 + use artbox\catalog\models\Variant;
  13 + use artbox\catalog\models\VariantSearch;
  14 + use yii\filters\AccessControl;
  15 + use yii\helpers\ArrayHelper;
  16 + use yii\web\Controller;
  17 + use yii\web\NotFoundHttpException;
  18 + use yii\filters\VerbFilter;
  19 +
  20 + /**
  21 + * VariantController implements the CRUD actions for Variant model.
  22 + */
  23 + class VariantController extends Controller
  24 + {
  25 +
  26 + /**
  27 + * @inheritdoc
  28 + */
  29 + public function getViewPath()
  30 + {
  31 + return '@artbox/catalog/views/variant';
  32 + }
  33 +
  34 + /**
  35 + * @inheritdoc
  36 + */
  37 + public function behaviors()
  38 + {
  39 + return [
  40 + 'access' => [
  41 + 'class' => AccessControl::className(),
  42 + 'rules' => [
  43 + [
  44 + 'actions' => [
  45 + 'login',
  46 + 'error',
  47 + ],
  48 + 'allow' => true,
  49 + ],
  50 + [
  51 + 'allow' => true,
  52 + 'roles' => [ '@' ],
  53 + ],
  54 + ],
  55 + ],
  56 + 'verbs' => [
  57 + 'class' => VerbFilter::className(),
  58 + 'actions' => [
  59 + 'delete' => [ 'POST' ],
  60 + ],
  61 + ],
  62 + ];
  63 + }
  64 +
  65 + /**
  66 + * Lists all Variant models.
  67 + *
  68 + * @param $product_id
  69 + *
  70 + * @return mixed
  71 + */
  72 + public function actionIndex($product_id)
  73 + {
  74 + $product = $this->findProduct($product_id);
  75 + $searchModel = new VariantSearch(
  76 + [
  77 + 'product_id' => $product_id,
  78 + ]
  79 + );
  80 + $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  81 +
  82 + return $this->render(
  83 + 'index',
  84 + [
  85 + 'searchModel' => $searchModel,
  86 + 'dataProvider' => $dataProvider,
  87 + 'product' => $product,
  88 + ]
  89 + );
  90 + }
  91 +
  92 + /**
  93 + * Displays a single Variant model.
  94 + *
  95 + * @param integer $id
  96 + *
  97 + * @return mixed
  98 + */
  99 + public function actionView($id)
  100 + {
  101 + return $this->render(
  102 + 'view',
  103 + [
  104 + 'model' => $this->findModel($id),
  105 + ]
  106 + );
  107 + }
  108 +
  109 + /**
  110 + * Creates a new Variant model.
  111 + * If creation is successful, the browser will be redirected to the 'view' page.
  112 + *
  113 + * @param $product_id
  114 + *
  115 + * @return mixed
  116 + */
  117 + public function actionCreate($product_id)
  118 + {
  119 + /**
  120 + * @var \yii\db\ActiveQuery $findShop
  121 + */
  122 + if (class_exists('\artbox\stock\models\Shop')){
  123 + $findShop = call_user_func('\artbox\stock\models\Shop::find');
  124 + $shops = $findShop->with('lang')->all();
  125 + }else{
  126 + $shops = null;
  127 + }
  128 +
  129 +
  130 + $product = $this->findProduct($product_id);
  131 + $model = new Variant(
  132 + [
  133 + 'product_id' => $product_id,
  134 + ]
  135 + );
  136 + $model->generateLangs();
  137 + $groups_compl = [];
  138 + $groups_excl = [];
  139 + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) {
  140 + $counts = \Yii::$app->request->post('counts');
  141 + print_r($counts);
  142 + $insert = [];
  143 + foreach ($counts as $key => $item){
  144 +
  145 + if (!empty($item) or $item === '0'){
  146 + $insert[] = [$model->id, $key, $item];
  147 + }
  148 + }
  149 + VariantToShop::deleteAll(['variant_id' => $model->id]);
  150 + \Yii::$app->db->createCommand()->batchInsert('variant_to_shop', ['variant_id', 'shop_id', 'count'],$insert)->execute();
  151 + return $this->redirect(
  152 + [
  153 + 'view',
  154 + 'id' => $model->id,
  155 + ]
  156 + );
  157 + }
  158 + return $this->render(
  159 + 'create',
  160 + [
  161 + 'model' => $model,
  162 + 'modelLangs' => $model->modelLangs,
  163 + 'product' => $product,
  164 + 'groups_compl' => $groups_compl,
  165 + 'groups_excl' => $groups_excl,
  166 + 'shops' => $shops,
  167 + ]
  168 + );
  169 + }
  170 +
  171 + /**
  172 + * Updates an existing Variant model.
  173 + * If update is successful, the browser will be redirected to the 'view' page.
  174 + *
  175 + * @param integer $id
  176 + *
  177 + * @return mixed
  178 + */
  179 + public function actionUpdate($id)
  180 + {
  181 + $model = $this->findModel($id);
  182 + $model->generateLangs();
  183 +
  184 + if (class_exists('\artbox\stock\models\Shop')){
  185 + $findShop = call_user_func('\artbox\stock\models\Shop::find');
  186 + $shops = $findShop->with('lang')->all();
  187 + }else{
  188 + $shops = null;
  189 + }
  190 +
  191 + $groups_compl = [];
  192 + $groups_excl = [];
  193 + if (!empty( $model->product->categories )) {
  194 + $groups_compl = VariantOptionGroupCompl::find()
  195 + ->innerJoin(
  196 + 'variant_option_group_compl_to_category',
  197 + 'variant_option_group_compl_to_category.variant_option_group_compl_id = variant_option_group_compl.id'
  198 + )
  199 + ->where(
  200 + [
  201 + 'variant_option_group_compl_to_category.category_id' => ArrayHelper::getColumn(
  202 + $model->product->categories,
  203 + 'id'
  204 + ),
  205 + ]
  206 + )
  207 + ->with('options.lang')
  208 + ->all();
  209 + $groups_excl = VariantOptionGroupExcl::find()
  210 + ->innerJoin(
  211 + 'variant_option_group_excl_to_category',
  212 + 'variant_option_group_excl_to_category.variant_option_group_excl_id = variant_option_group_excl.id'
  213 + )
  214 + ->where(
  215 + [
  216 + 'variant_option_group_excl_to_category.category_id' => ArrayHelper::getColumn(
  217 + $model->product->categories,
  218 + 'id'
  219 + ),
  220 + ]
  221 + )
  222 + ->with('options.lang')
  223 + ->all();
  224 + }
  225 +
  226 + if ($model->loadWithLangs(\Yii::$app->request) && $model->saveWithLangs()) {
  227 + if (!empty( \Yii::$app->request->post('Variant')[ 'variantOptionCompls' ] )) {
  228 + $options = VariantOptionCompl::findAll($model->variantOptionCompls);
  229 + $model->linkMany('variantOptionCompls', $options);
  230 + } else {
  231 + $model->unlinkAll('variantOptionCompls', true);
  232 + }
  233 + if (!empty( \Yii::$app->request->post('Variant')[ 'variantOptionExcls' ] )) {
  234 + $options = VariantOptionExcl::findAll($model->variantOptionExcls);
  235 + $model->linkMany('variantOptionExcls', $options);
  236 + } else {
  237 + $model->unlinkAll('variantOptionExcls', true);
  238 + }
  239 + if (class_exists('\artbox\stock\models\VariantToShop')) {
  240 + $counts = \Yii::$app->request->post('counts');
  241 +
  242 + $insert = [];
  243 + foreach ($counts as $key => $item){
  244 +
  245 + if (!empty($item) or $item === '0'){
  246 + $insert[] = [$model->id, $key, $item];
  247 + }
  248 + }
  249 + VariantToShop::deleteAll(['variant_id' => $model->id]);
  250 + \Yii::$app->db->createCommand()->batchInsert('variant_to_shop', ['variant_id', 'shop_id', 'count'],$insert)->execute();
  251 + }
  252 + return $this->redirect(
  253 + [
  254 + 'view',
  255 + 'id' => $model->id,
  256 + ]
  257 + );
  258 + }
  259 + return $this->render(
  260 + 'update',
  261 + [
  262 + 'model' => $model,
  263 + 'modelLangs' => $model->modelLangs,
  264 + 'groups_compl' => $groups_compl,
  265 + 'groups_excl' => $groups_excl,
  266 + 'shops' => $shops,
  267 +
  268 + ]
  269 + );
  270 + }
  271 +
  272 + /**
  273 + * Deletes an existing Variant model.
  274 + * If deletion is successful, the browser will be redirected to the 'index' page.
  275 + *
  276 + * @param integer $id
  277 + *
  278 + * @return mixed
  279 + */
  280 + public function actionDelete($id)
  281 + {
  282 + $model = $this->findModel($id);
  283 + $product_id = $model->product_id;
  284 + $model->delete();
  285 +
  286 + return $this->redirect(
  287 + [
  288 + 'index',
  289 + 'product_id' => $product_id,
  290 + ]
  291 + );
  292 + }
  293 +
  294 + /**
  295 + * Finds the Variant model based on its primary key value.
  296 + * If the model is not found, a 404 HTTP exception will be thrown.
  297 + *
  298 + * @param integer $id
  299 + *
  300 + * @return Variant the loaded model
  301 + * @throws NotFoundHttpException if the model cannot be found
  302 + */
  303 + protected function findModel($id)
  304 + {
  305 + if (( $model = Variant::findOne($id) ) !== null) {
  306 + return $model;
  307 + } else {
  308 + throw new NotFoundHttpException('The requested page does not exist.');
  309 + }
  310 + }
  311 +
  312 + /**
  313 + * Finds Product by $id
  314 + *
  315 + * @param $id
  316 + *
  317 + * @return Product
  318 + * @throws \yii\web\NotFoundHttpException
  319 + */
  320 + protected function findProduct($id)
  321 + {
  322 + if (( $model = Product::findOne($id) ) !== null) {
  323 + return $model;
  324 + } else {
  325 + throw new NotFoundHttpException('The requested page not exist');
  326 + }
  327 + }
  328 +
  329 + }
... ...
artweb/artbox-catalog/controllers/VariantOptionComplController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\controllers;
  4 +
  5 + use artbox\catalog\models\Option;
  6 + use artbox\catalog\models\OptionGroup;
  7 + use artbox\catalog\models\OptionSearch;
  8 + use artbox\catalog\models\VariantOptionCompl;
  9 + use artbox\catalog\models\VariantOptionComplSearch;
  10 + use artbox\catalog\models\VariantOptionGroupCompl;
  11 + use yii\filters\AccessControl;
  12 +
  13 + /**
  14 + * VariantOptionComplController implements the CRUD actions for VariantOptionCompl model.
  15 + */
  16 + class VariantOptionComplController extends OptionController
  17 + {
  18 + /**
  19 + * @inheritdoc
  20 + */
  21 + public function getViewPath()
  22 + {
  23 + return '@artbox/catalog/views/variant-option-compl';
  24 + }
  25 + public function behaviors()
  26 + {
  27 + return [
  28 + 'access' => [
  29 + 'class' => AccessControl::className(),
  30 + 'rules' => [
  31 + [
  32 + 'actions' => [
  33 + 'login',
  34 + 'error',
  35 + ],
  36 + 'allow' => true,
  37 + ],
  38 + [
  39 + 'allow' => true,
  40 + 'roles' => [ '@' ],
  41 + ],
  42 + ],
  43 + ],
  44 + ];
  45 + }
  46 +
  47 + /**
  48 + * Create exact model
  49 + *
  50 + * @return Option
  51 + */
  52 + protected function createModel(): Option
  53 + {
  54 + return new VariantOptionCompl();
  55 + }
  56 + /**
  57 + * Create exact search model
  58 + *
  59 + * @return OptionSearch
  60 + */
  61 + protected function createSearchModel(): OptionSearch
  62 + {
  63 + return new VariantOptionComplSearch();
  64 + }
  65 + /**
  66 + * Find exact model
  67 + *
  68 + * @param $id
  69 + *
  70 + * @return Option|null
  71 + */
  72 + protected function findOne($id)
  73 + {
  74 + return VariantOptionCompl::findOne($id);
  75 + }
  76 + /**
  77 + * Find exact group
  78 + *
  79 + * @param $id
  80 + *
  81 + * @return OptionGroup|null
  82 + */
  83 + protected function findOneGroup($id)
  84 + {
  85 + return VariantOptionGroupCompl::findOne($id);
  86 + }
  87 + }
... ...
artweb/artbox-catalog/controllers/VariantOptionExclController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\controllers;
  4 +
  5 + use artbox\catalog\models\Option;
  6 + use artbox\catalog\models\OptionGroup;
  7 + use artbox\catalog\models\OptionSearch;
  8 + use artbox\catalog\models\VariantOptionExcl;
  9 + use artbox\catalog\models\VariantOptionExclSearch;
  10 + use artbox\catalog\models\VariantOptionGroupExcl;
  11 + use yii\filters\AccessControl;
  12 + /**
  13 + * VariantOptionExclController implements the CRUD actions for VariantOptionExcl model.
  14 + */
  15 + class VariantOptionExclController extends OptionController
  16 + {
  17 + /**
  18 + * @inheritdoc
  19 + */
  20 + public function getViewPath()
  21 + {
  22 + return '@artbox/catalog/views/variant-option-excl';
  23 + }
  24 + public function behaviors()
  25 + {
  26 + return [
  27 + 'access' => [
  28 + 'class' => AccessControl::className(),
  29 + 'rules' => [
  30 + [
  31 + 'actions' => [
  32 + 'login',
  33 + 'error',
  34 + ],
  35 + 'allow' => true,
  36 + ],
  37 + [
  38 + 'allow' => true,
  39 + 'roles' => [ '@' ],
  40 + ],
  41 + ],
  42 + ],
  43 + ];
  44 + }
  45 +
  46 + /**
  47 + * Create exact model
  48 + *
  49 + * @return Option
  50 + */
  51 + protected function createModel(): Option
  52 + {
  53 + return new VariantOptionExcl();
  54 + }
  55 + /**
  56 + * Create exact search model
  57 + *
  58 + * @return OptionSearch
  59 + */
  60 + protected function createSearchModel(): OptionSearch
  61 + {
  62 + return new VariantOptionExclSearch();
  63 + }
  64 + /**
  65 + * Find exact model
  66 + *
  67 + * @param $id
  68 + *
  69 + * @return Option|null
  70 + */
  71 + protected function findOne($id)
  72 + {
  73 + return VariantOptionExcl::findOne($id);
  74 + }
  75 + /**
  76 + * Find exact group
  77 + *
  78 + * @param $id
  79 + *
  80 + * @return OptionGroup|null
  81 + */
  82 + protected function findOneGroup($id)
  83 + {
  84 + return VariantOptionGroupExcl::findOne($id);
  85 + }
  86 + }
... ...
artweb/artbox-catalog/controllers/VariantOptionGroupComplController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\controllers;
  4 +
  5 + use artbox\catalog\models\OptionGroup;
  6 + use artbox\catalog\models\OptionGroupSearch;
  7 + use artbox\catalog\models\VariantOptionGroupCompl;
  8 + use artbox\catalog\models\VariantOptionGroupComplSearch;
  9 + use yii\filters\AccessControl;
  10 +
  11 + /**
  12 + * VariantOptionGroupComplController implements the CRUD actions for VariantOptionGroupCompl model.
  13 + */
  14 + class VariantOptionGroupComplController extends OptionGroupController
  15 + {
  16 + /**
  17 + * @inheritdoc
  18 + */
  19 + public function getViewPath()
  20 + {
  21 + return '@artbox/catalog/views/variant-option-group-compl';
  22 + }
  23 + public function behaviors()
  24 + {
  25 + return [
  26 + 'access' => [
  27 + 'class' => AccessControl::className(),
  28 + 'rules' => [
  29 + [
  30 + 'actions' => [
  31 + 'login',
  32 + 'error',
  33 + ],
  34 + 'allow' => true,
  35 + ],
  36 + [
  37 + 'allow' => true,
  38 + 'roles' => [ '@' ],
  39 + ],
  40 + ],
  41 + ],
  42 + ];
  43 + }
  44 +
  45 + /**
  46 + * @inheritdoc
  47 + */
  48 + protected function createModel(): OptionGroup
  49 + {
  50 + return new VariantOptionGroupCompl();
  51 + }
  52 +
  53 + /**
  54 + * @inheritdoc
  55 + */
  56 + protected function createSearchModel(): OptionGroupSearch
  57 + {
  58 + return new VariantOptionGroupComplSearch();
  59 + }
  60 +
  61 + /**
  62 + * @inheritdoc
  63 + */
  64 + protected function findOne($id)
  65 + {
  66 + return VariantOptionGroupCompl::findOne($id);
  67 + }
  68 + }
... ...
artweb/artbox-catalog/controllers/VariantOptionGroupExclController.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\controllers;
  4 +
  5 + use artbox\catalog\models\OptionGroup;
  6 + use artbox\catalog\models\OptionGroupSearch;
  7 + use artbox\catalog\models\VariantOptionGroupExcl;
  8 + use artbox\catalog\models\VariantOptionGroupExclSearch;
  9 + use yii\filters\AccessControl;
  10 +
  11 + /**
  12 + * VariantOptionGroupExclController implements the CRUD actions for VariantOptionGroupExcl model.
  13 + */
  14 + class VariantOptionGroupExclController extends OptionGroupController
  15 + {
  16 + /**
  17 + * @inheritdoc
  18 + */
  19 + public function getViewPath()
  20 + {
  21 + return '@artbox/catalog/views/variant-option-group-excl';
  22 + }
  23 + public function behaviors()
  24 + {
  25 + return [
  26 + 'access' => [
  27 + 'class' => AccessControl::className(),
  28 + 'rules' => [
  29 + [
  30 + 'actions' => [
  31 + 'login',
  32 + 'error',
  33 + ],
  34 + 'allow' => true,
  35 + ],
  36 + [
  37 + 'allow' => true,
  38 + 'roles' => [ '@' ],
  39 + ],
  40 + ],
  41 + ],
  42 + ];
  43 + }
  44 +
  45 + /**
  46 + * @inheritdoc
  47 + */
  48 + protected function createModel(): OptionGroup
  49 + {
  50 + return new VariantOptionGroupExcl();
  51 + }
  52 +
  53 + /**
  54 + * @inheritdoc
  55 + */
  56 + protected function createSearchModel(): OptionGroupSearch
  57 + {
  58 + return new VariantOptionGroupExclSearch();
  59 + }
  60 +
  61 + /**
  62 + * @inheritdoc
  63 + */
  64 + protected function findOne($id)
  65 + {
  66 + return VariantOptionGroupExcl::findOne($id);
  67 + }
  68 + }
... ...
artweb/artbox-catalog/helpers/FilterHelper.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\helpers;
  4 +
  5 + use artbox\catalog\models\Brand;
  6 + use artbox\catalog\models\BrandLang;
  7 + use artbox\catalog\models\Category;
  8 + use artbox\catalog\models\Filter;
  9 + use artbox\catalog\models\Product;
  10 + use artbox\catalog\models\ProductOptionCompl;
  11 + use artbox\catalog\models\ProductOptionComplLang;
  12 + use artbox\catalog\models\ProductOptionExcl;
  13 + use artbox\catalog\models\ProductOptionExclLang;
  14 + use artbox\catalog\models\VariantOptionCompl;
  15 + use artbox\catalog\models\VariantOptionComplLang;
  16 + use artbox\catalog\models\VariantOptionExcl;
  17 + use artbox\catalog\models\VariantOptionExclLang;
  18 + use artbox\core\models\Alias;
  19 + use yii\base\InvalidConfigException;
  20 + use yii\base\Object;
  21 + use yii\db\ActiveQuery;
  22 + use yii\db\ActiveRecord;
  23 + use yii\helpers\ArrayHelper;
  24 + use yii\helpers\Json;
  25 +
  26 + /**
  27 + * Class FilterHelper able to work with filters: building query for products and generate filter links.
  28 + */
  29 + class FilterHelper extends Object
  30 + {
  31 + /**
  32 + * Object with stored rewrote filters and methods to replace theme
  33 + *
  34 + * @var Filter
  35 + */
  36 + public $filterObj;
  37 +
  38 + /**
  39 + * Whether filter is loaded
  40 + *
  41 + * @var bool
  42 + */
  43 + protected $loaded = false;
  44 +
  45 + /**
  46 + * Filter string value
  47 + *
  48 + * @var string
  49 + */
  50 + protected $filter = '';
  51 +
  52 + /**
  53 + * Array of active aliases
  54 + *
  55 + * @var array
  56 + */
  57 + protected $activeAliases = [];
  58 +
  59 + /**
  60 + * Filter ids grouped by model classnames
  61 + *
  62 + * @var array
  63 + */
  64 + protected $groupFilters = [];
  65 +
  66 + /**
  67 + * Filter models grouped by model classnames
  68 + *
  69 + * @var array
  70 + */
  71 + protected $groupModels = [];
  72 +
  73 + /**
  74 + * @inheritdoc
  75 + */
  76 + public function init()
  77 + {
  78 + $this->filterObj = \Yii::createObject(Filter::className());
  79 + }
  80 +
  81 + /**
  82 + * Getter for $groupModels
  83 + *
  84 + * @return array
  85 + */
  86 + public function getGroupModels(): array
  87 + {
  88 + return $this->groupModels;
  89 + }
  90 +
  91 + /**
  92 + * Getter for $loaded
  93 + *
  94 + * @return bool
  95 + */
  96 + public function getLoaded(): bool
  97 + {
  98 + return $this->loaded;
  99 + }
  100 +
  101 + /**
  102 + * Set filter value and makes further actions, can only be performed once
  103 + *
  104 + * @param string $filter
  105 + *
  106 + * @throws \yii\base\InvalidConfigException
  107 + */
  108 + public function setFilter(string $filter)
  109 + {
  110 + if (empty($this->filter)) {
  111 + $this->loaded = true;
  112 + $this->filter = $filter;
  113 + $this->groupModels($this->groupFilters($filter));
  114 + $this->getPrices($filter);
  115 + } else {
  116 + throw new InvalidConfigException(\Yii::t('catalog', 'Filter can be initiated only once'));
  117 + }
  118 + }
  119 +
  120 + /**
  121 + * Getter for $filter
  122 + *
  123 + * @return string
  124 + */
  125 + public function getFilter(): string
  126 + {
  127 + return $this->filter;
  128 + }
  129 +
  130 + /**
  131 + * Getter for $groupFilters
  132 + *
  133 + * @return array
  134 + */
  135 + public function getGroupFilters(): array
  136 + {
  137 + return $this->groupFilters;
  138 + }
  139 +
  140 + public function getActiveAliases(): array
  141 + {
  142 + return $this->activeAliases;
  143 + }
  144 +
  145 + /**
  146 + * Explode filter string into filter array
  147 + *
  148 + * @param string $filter
  149 + *
  150 + * @return array
  151 + */
  152 + protected function parseFilter(string $filter)
  153 + {
  154 + return explode('_', $filter);
  155 + }
  156 +
  157 + /**
  158 + * Get array of aliases for filter
  159 + *
  160 + * @param string $filter
  161 + *
  162 + * @return Alias[]
  163 + */
  164 + protected function getAliases(string $filter): array
  165 + {
  166 + $filters = $this->parseFilter($filter);
  167 + $aliases = Alias::find()
  168 + ->where([ 'value' => $filters ])
  169 + ->all();
  170 + $this->activeAliases = $aliases;
  171 + return $aliases;
  172 + }
  173 +
  174 + /**
  175 + * Group filter ids by classname
  176 + *
  177 + * @param string $filter
  178 + *
  179 + * @return array
  180 + */
  181 + protected function groupFilters(string $filter)
  182 + {
  183 + $aliases = $this->getAliases($filter);
  184 + $result = [];
  185 + foreach ($aliases as $alias) {
  186 + if (in_array(
  187 + $alias->entity,
  188 + [
  189 + BrandLang::className(),
  190 + ProductOptionComplLang::className(),
  191 + ProductOptionExclLang::className(),
  192 + VariantOptionExclLang::className(),
  193 + VariantOptionComplLang::className(),
  194 + ]
  195 + )) {
  196 + $id = $this->getIdFromRoute($alias->route);
  197 + if ($id) {
  198 + if (preg_match("/^([\w-\\\\]*\\\\\w+)Lang$/", $alias->entity, $matches)) {
  199 + $result[ $matches[ 1 ] ][] = $id;
  200 + } else {
  201 + $result[ $alias->entity ][] = $id;
  202 + }
  203 + }
  204 + }
  205 + }
  206 + $this->groupFilters = $result;
  207 + return $result;
  208 + }
  209 +
  210 + /**
  211 + * Group filter models by classname.
  212 + *
  213 + * @param array $filter
  214 + *
  215 + * @return array
  216 + */
  217 + protected function groupModels(array $filter)
  218 + {
  219 + $result = [];
  220 + foreach ($filter as $model => $ids) {
  221 + switch ($model) {
  222 + case Brand::className():
  223 + $result[ $model ] = Brand::find()
  224 + ->where([ 'id' => $ids ])
  225 + ->joinWith('lang', false)
  226 + ->orderBy(
  227 + [
  228 + 'brand.sort' => SORT_ASC,
  229 + 'brand_lang.title' => SORT_ASC,
  230 + ]
  231 + )
  232 + ->all();
  233 + break;
  234 + case ProductOptionCompl::className():
  235 + $result[ $model ] = ProductOptionCompl::find()
  236 + ->where([ 'product_option_compl.id' => $ids ])
  237 + ->joinWith('lang.alias', true)
  238 + ->joinWith('group', true)
  239 + ->orderBy(
  240 + [
  241 + 'product_option_group_compl.sort' => SORT_ASC,
  242 + 'product_option_group_compl.id' => SORT_ASC,
  243 + 'product_option_compl.sort' => SORT_ASC,
  244 + 'product_option_compl_lang.value' => SORT_ASC,
  245 +
  246 + ]
  247 + )
  248 + ->all();
  249 + break;
  250 + case ProductOptionExcl::className():
  251 + $result[ $model ] = ProductOptionExcl::find()
  252 + ->where([ 'product_option_excl.id' => $ids ])
  253 + ->joinWith('lang.alias', true)
  254 + ->joinWith('group', true)
  255 + ->orderBy(
  256 + [
  257 + 'product_option_group_excl.sort' => SORT_ASC,
  258 + 'product_option_group_excl.id' => SORT_ASC,
  259 + 'product_option_excl.sort' => SORT_ASC,
  260 + 'product_option_excl_lang.value' => SORT_ASC,
  261 +
  262 + ]
  263 + )
  264 + ->all();
  265 + break;
  266 + case VariantOptionCompl::className():
  267 + $result[ $model ] = VariantOptionCompl::find()
  268 + ->where([ 'variant_option_compl.id' => $ids ])
  269 + ->joinWith('lang.alias', true)
  270 + ->joinWith('group', true)
  271 + ->orderBy(
  272 + [
  273 + 'variant_option_group_compl.sort' => SORT_ASC,
  274 + 'variant_option_group_compl.id' => SORT_ASC,
  275 + 'variant_option_compl.sort' => SORT_ASC,
  276 + 'variant_option_compl_lang.value' => SORT_ASC,
  277 +
  278 + ]
  279 + )
  280 + ->all();
  281 + break;
  282 + case VariantOptionExcl::className():
  283 + $result[ $model ] = VariantOptionExcl::find()
  284 + ->where([ 'variant_option_excl.id' => $ids ])
  285 + ->joinWith('lang.alias', true)
  286 + ->joinWith('group', true)
  287 + ->orderBy(
  288 + [
  289 + 'variant_option_group_excl.sort' => SORT_ASC,
  290 + 'variant_option_group_excl.id' => SORT_ASC,
  291 + 'variant_option_excl.sort' => SORT_ASC,
  292 + 'variant_option_excl_lang.value' => SORT_ASC,
  293 +
  294 + ]
  295 + )
  296 + ->all();
  297 + break;
  298 + }
  299 + }
  300 + $this->groupModels = $result;
  301 + return $result;
  302 + }
  303 +
  304 + /**
  305 + * Get Id from Alias route column
  306 + *
  307 + * @param string $json
  308 + *
  309 + * @return int|null
  310 + */
  311 + public function getIdFromRoute(string $json)
  312 + {
  313 + $route = Json::decode($json);
  314 + return empty($route[ 'id' ]) ? null : (int) $route[ 'id' ];
  315 + }
  316 +
  317 + /**
  318 + * Build query to retrieve Products according to current filter
  319 + *
  320 + * @param string|null $productClass
  321 + * @param bool $eagerload
  322 + *
  323 + * @return \yii\db\ActiveQuery
  324 + */
  325 + public function buildQuery(string $productClass = null, bool $eagerload = false): ActiveQuery
  326 + {
  327 + if (!$productClass) {
  328 + $productClass = Product::className();
  329 + }
  330 + $groups = $this->groupFilters;
  331 + $query = call_user_func(
  332 + [
  333 + $productClass,
  334 + 'find',
  335 + ]
  336 + );
  337 + foreach ($groups as $group => $ids) {
  338 + switch ($group) {
  339 + case Brand::className():
  340 + $this->buildBrand($ids, $query);
  341 + break;
  342 + case ProductOptionCompl::className():
  343 + $this->buildProductCompl($ids, $query, $eagerload);
  344 + break;
  345 + case ProductOptionExcl::className():
  346 + $this->buildProductExcl($ids, $query, $eagerload);
  347 + break;
  348 + case VariantOptionCompl::className():
  349 + $this->buildVariantCompl($ids, $query, $eagerload);
  350 + break;
  351 + case VariantOptionExcl::className():
  352 + $this->buildVariantExcl($ids, $query, $eagerload);
  353 + break;
  354 + case 'prices':
  355 + $this->buildPrices($ids, $query, $eagerload);
  356 + break;
  357 + }
  358 + }
  359 + return $query;
  360 + }
  361 +
  362 + /**
  363 + * Get brands for provided Category
  364 + *
  365 + * @param \artbox\catalog\models\Category $category
  366 + *
  367 + * @return array
  368 + */
  369 + public function getBrands(Category $category): array
  370 + {
  371 + $brands = [];
  372 + foreach ($category->products as $product) {
  373 + /**
  374 + * @var Product $product
  375 + */
  376 + if (!empty($product->brand_id) && !array_key_exists($product->brand_id, $brands)) {
  377 + $brands[ $product->brand_id ] = $product->brand;
  378 + }
  379 + }
  380 + return $brands;
  381 + }
  382 +
  383 + protected function buildBrand(array $ids, ActiveQuery $query)
  384 + {
  385 + $query->andWhere([ 'product.brand_id' => $ids ]);
  386 + }
  387 +
  388 + protected function buildProductCompl(array $ids, ActiveQuery $query, bool $eagerload = false)
  389 + {
  390 + foreach ($ids as $id) {
  391 + $query->innerJoinWith([ "productToProductOptionCompls poc$id" ], $eagerload)
  392 + ->andWhere([ "poc$id.product_option_compl_id" => $id ]);
  393 + }
  394 + }
  395 +
  396 + protected function buildProductExcl(array $ids, ActiveQuery $query, bool $eagerload = false)
  397 + {
  398 + $query->innerJoinWith('productToProductOptionExcls', $eagerload)
  399 + ->andWhere([ 'product_to_product_option_excl.product_option_excl_id' => $ids ]);
  400 + }
  401 +
  402 + protected function buildVariantCompl(array $ids, ActiveQuery $query, bool $eagerload = false)
  403 + {
  404 + foreach ($ids as $id) {
  405 + $query->innerJoinWith("variants.variantToVariantOptionCompls voc$id", $eagerload)
  406 + ->andWhere([ "voc$id.variant_option_compl_id" => $ids ]);
  407 + }
  408 + }
  409 +
  410 + protected function buildVariantExcl(array $ids, ActiveQuery $query, bool $eagerload = false)
  411 + {
  412 + $query->innerJoinWith('variants.variantToVariantOptionExcls', $eagerload)
  413 + ->andWhere([ 'variant_to_variant_option_excl.variant_option_excl_id' => $ids ]);
  414 + }
  415 +
  416 + protected function buildPrices(array $ids, ActiveQuery $query, bool $eagerload = false)
  417 + {
  418 + $query->innerJoinWith('variants', $eagerload)
  419 + ->andWhere(
  420 + [
  421 + 'between',
  422 + 'variant.price',
  423 + (float) $ids[ 0 ],
  424 + (float) $ids[ 1 ],
  425 + ]
  426 + );
  427 + }
  428 +
  429 + /**
  430 + * Build link for filter including or excluding (if already set) provided $model
  431 + *
  432 + * @param \yii\db\ActiveRecord $model
  433 + *
  434 + * @return string
  435 + */
  436 + public function buildLink(ActiveRecord $model = null)
  437 + {
  438 + $groups = $this->groupModels;
  439 + $groupsFilter = $this->groupFilters;
  440 + $link = '';
  441 + $skip = false;
  442 + if (!empty($model)) {
  443 + switch ($model::className()) {
  444 + case Brand::className():
  445 + if (!empty($groups[ Brand::className() ])) {
  446 + foreach ($groups[ Brand::className() ] as $index => $object) {
  447 + /**
  448 + * @var Brand $object
  449 + * @var Brand $model
  450 + */
  451 + if ($object->lang->alias->value == $model->lang->alias->value) {
  452 + unset($groups[ Brand::className() ][ $index ]);
  453 + $skip = true;
  454 + break;
  455 + }
  456 + }
  457 + }
  458 + if (!$skip) {
  459 + $groups[ Brand::className() ][] = $model;
  460 + usort(
  461 + $groups[ Brand::className() ],
  462 + function ($a, $b) {
  463 + /**
  464 + * @var Brand $a
  465 + * @var Brand $b
  466 + */
  467 + if ($a->sort > $b->sort) {
  468 + return 1;
  469 + } elseif ($a->sort < $b->sort) {
  470 + return -1;
  471 + } else {
  472 + return strcmp($a->lang->title, $b->lang->title);
  473 + }
  474 + }
  475 + );
  476 + $link = implode(
  477 + '_',
  478 + ArrayHelper::getColumn($groups[ Brand::className() ], 'lang.alias.value')
  479 + );
  480 + }
  481 + if (!empty($groups[ ProductOptionCompl::className() ])) {
  482 + if (empty($link)) {
  483 + $link = $this->writePOC($groups);
  484 + } else {
  485 + $link .= '_' . $this->writePOC($groups);
  486 + }
  487 + }
  488 + if (!empty($groups[ ProductOptionExcl::className() ])) {
  489 + if (empty($link)) {
  490 + $link = $this->writePOE($groups);
  491 + } else {
  492 + $link .= '_' . $this->writePOE($groups);
  493 + }
  494 + }
  495 + if (!empty($groups[ VariantOptionCompl::className() ])) {
  496 + if (empty($link)) {
  497 + $link = $this->writeVOC($groups);
  498 + } else {
  499 + $link .= '_' . $this->writeVOC($groups);
  500 + }
  501 + }
  502 + if (!empty($groups[ VariantOptionExcl::className() ])) {
  503 + if (empty($link)) {
  504 + $link = $this->writeVOE($groups);
  505 + } else {
  506 + $link .= '_' . $this->writeVOE($groups);
  507 + }
  508 + }
  509 + break;
  510 + case ProductOptionCompl::className():
  511 + if (!empty($groups[ ProductOptionCompl::className() ])) {
  512 + foreach ($groups[ ProductOptionCompl::className() ] as $index => $object) {
  513 + /**
  514 + * @var ProductOptionCompl $object
  515 + * @var ProductOptionCompl $model
  516 + */
  517 + if ($object->lang->alias->value == $model->lang->alias->value) {
  518 + unset($groups[ ProductOptionCompl::className() ][ $index ]);
  519 + $skip = true;
  520 + break;
  521 + }
  522 + }
  523 + }
  524 + if (!$skip) {
  525 + $groups[ ProductOptionCompl::className() ][] = $model;
  526 + usort(
  527 + $groups[ ProductOptionCompl::className() ],
  528 + function ($a, $b) {
  529 + /**
  530 + * @var ProductOptionCompl $a
  531 + * @var ProductOptionCompl $b
  532 + */
  533 + if ($a->group->sort > $b->group->sort) {
  534 + return 1;
  535 + } elseif ($a->group->sort < $b->group->sort) {
  536 + return -1;
  537 + } else {
  538 + if ($a->group->id > $b->group->id) {
  539 + return 1;
  540 + } elseif ($a->group->id < $b->group->id) {
  541 + return -1;
  542 + } else {
  543 + if ($a->sort > $b->sort) {
  544 + return 1;
  545 + } elseif ($a->sort < $b->sort) {
  546 + return -1;
  547 + } else {
  548 + return strcasecmp($a->lang->value, $b->lang->value);
  549 + }
  550 + }
  551 + }
  552 + }
  553 + );
  554 + }
  555 + if (!empty($groups[ Brand::className() ])) {
  556 + $link = $this->writeBrands($groups);
  557 + }
  558 + if (empty($link)) {
  559 + $link = implode(
  560 + '_',
  561 + ArrayHelper::getColumn(
  562 + $groups[ ProductOptionCompl::className() ],
  563 + 'lang.alias.value'
  564 + )
  565 + );
  566 + } else {
  567 + if (!empty(
  568 + ArrayHelper::getColumn(
  569 + $groups[ ProductOptionCompl::className() ],
  570 + 'lang.alias.value'
  571 + )
  572 + )
  573 + ) {
  574 + $link .= '_' . implode(
  575 + '_',
  576 + ArrayHelper::getColumn(
  577 + $groups[ ProductOptionCompl::className() ],
  578 + 'lang.alias.value'
  579 + )
  580 + );
  581 + }
  582 + }
  583 + if (!empty($groups[ ProductOptionExcl::className() ])) {
  584 + $link .= '_' . $this->writePOE($groups);
  585 + }
  586 + if (!empty($groups[ VariantOptionCompl::className() ])) {
  587 + $link .= '_' . $this->writeVOC($groups);
  588 + }
  589 + if (!empty($groups[ VariantOptionExcl::className() ])) {
  590 + $link .= '_' . $this->writeVOE($groups);
  591 + }
  592 + break;
  593 + case ProductOptionExcl::className():
  594 + if (!empty($groups[ ProductOptionExcl::className() ])) {
  595 + foreach ($groups[ ProductOptionExcl::className() ] as $index => $object) {
  596 + /**
  597 + * @var ProductOptionExcl $object
  598 + * @var ProductOptionExcl $model
  599 + */
  600 + if ($object->lang->alias->value == $model->lang->alias->value) {
  601 + unset($groups[ ProductOptionExcl::className() ][ $index ]);
  602 + $skip = true;
  603 + break;
  604 + }
  605 + }
  606 + }
  607 + if (!$skip) {
  608 + $groups[ ProductOptionExcl::className() ][] = $model;
  609 + usort(
  610 + $groups[ ProductOptionExcl::className() ],
  611 + function ($a, $b) {
  612 + /**
  613 + * @var ProductOptionExcl $a
  614 + * @var ProductOptionExcl $b
  615 + */
  616 + if ($a->group->sort > $b->group->sort) {
  617 + return 1;
  618 + } elseif ($a->group->sort < $b->group->sort) {
  619 + return -1;
  620 + } else {
  621 + if ($a->group->id > $b->group->id) {
  622 + return 1;
  623 + } elseif ($a->group->id < $b->group->id) {
  624 + return -1;
  625 + } else {
  626 + if ($a->sort > $b->sort) {
  627 + return 1;
  628 + } elseif ($a->sort < $b->sort) {
  629 + return -1;
  630 + } else {
  631 + return strcasecmp($a->lang->value, $b->lang->value);
  632 + }
  633 + }
  634 + }
  635 + }
  636 + );
  637 + }
  638 + if (!empty($groups[ Brand::className() ])) {
  639 + $link = $this->writeBrands($groups);
  640 + }
  641 + if (!empty($groups[ ProductOptionCompl::className() ])) {
  642 + if (!empty($link)) {
  643 + $link .= '_' . $this->writePOC($groups);
  644 + } else {
  645 + $link = $this->writePOC($groups);
  646 + }
  647 + }
  648 + if (empty($link)) {
  649 + $link = implode(
  650 + '_',
  651 + ArrayHelper::getColumn(
  652 + $groups[ ProductOptionExcl::className() ],
  653 + 'lang.alias.value'
  654 + )
  655 + );
  656 + } else {
  657 + if (!empty(
  658 + ArrayHelper::getColumn(
  659 + $groups[ ProductOptionExcl::className() ],
  660 + 'lang.alias.value'
  661 + )
  662 + )
  663 + ) {
  664 + $link .= '_' . implode(
  665 + '_',
  666 + ArrayHelper::getColumn(
  667 + $groups[ ProductOptionExcl::className() ],
  668 + 'lang.alias.value'
  669 + )
  670 + );
  671 + }
  672 + }
  673 + if (!empty($groups[ VariantOptionCompl::className() ])) {
  674 + if (empty($link)) {
  675 + $link = $this->writeVOC($groups);
  676 + } else {
  677 + $link .= '_' . $this->writeVOC($groups);
  678 + }
  679 + }
  680 + if (!empty($groups[ VariantOptionExcl::className() ])) {
  681 + if (empty($link)) {
  682 + $link = $this->writeVOE($groups);
  683 + } else {
  684 + $link .= '_' . $this->writeVOE($groups);
  685 + }
  686 + }
  687 + break;
  688 + case VariantOptionCompl::className():
  689 + if (!empty($groups[ VariantOptionCompl::className() ])) {
  690 + foreach ($groups[ VariantOptionCompl::className() ] as $index => $object) {
  691 + /**
  692 + * @var VariantOptionCompl $object
  693 + * @var VariantOptionCompl $model
  694 + */
  695 + if ($object->lang->alias->value == $model->lang->alias->value) {
  696 + unset($groups[ VariantOptionCompl::className() ][ $index ]);
  697 + $skip = true;
  698 + break;
  699 + }
  700 + }
  701 + }
  702 + if (!$skip) {
  703 + $groups[ VariantOptionCompl::className() ][] = $model;
  704 + usort(
  705 + $groups[ VariantOptionCompl::className() ],
  706 + function ($a, $b) {
  707 + /**
  708 + * @var VariantOptionCompl $a
  709 + * @var VariantOptionCompl $b
  710 + */
  711 + if ($a->group->sort > $b->group->sort) {
  712 + return 1;
  713 + } elseif ($a->group->sort < $b->group->sort) {
  714 + return -1;
  715 + } else {
  716 + if ($a->group->id > $b->group->id) {
  717 + return 1;
  718 + } elseif ($a->group->id < $b->group->id) {
  719 + return -1;
  720 + } else {
  721 + if ($a->sort > $b->sort) {
  722 + return 1;
  723 + } elseif ($a->sort < $b->sort) {
  724 + return -1;
  725 + } else {
  726 + return strcasecmp($a->lang->value, $b->lang->value);
  727 + }
  728 + }
  729 + }
  730 + }
  731 + );
  732 + }
  733 + if (!empty($groups[ Brand::className() ])) {
  734 + $link = $this->writeBrands($groups);
  735 + }
  736 + if (!empty($groups[ ProductOptionCompl::className() ])) {
  737 + if (!empty($link)) {
  738 + $link .= '_' . $this->writePOC($groups);
  739 + } else {
  740 + $link = $this->writePOC($groups);
  741 + }
  742 + }
  743 + if (!empty($groups[ ProductOptionExcl::className() ])) {
  744 + if (!empty($link)) {
  745 + $link .= '_' . $this->writePOE($groups);
  746 + } else {
  747 + $link = $this->writePOE($groups);
  748 + }
  749 + }
  750 + if (empty($link)) {
  751 + $link = implode(
  752 + '_',
  753 + ArrayHelper::getColumn(
  754 + $groups[ VariantOptionCompl::className() ],
  755 + 'lang.alias.value'
  756 + )
  757 + );
  758 + } else {
  759 + if (!empty(
  760 + ArrayHelper::getColumn(
  761 + $groups[ VariantOptionCompl::className() ],
  762 + 'lang.alias.value'
  763 + )
  764 + )
  765 + ) {
  766 + $link .= '_' . implode(
  767 + '_',
  768 + ArrayHelper::getColumn(
  769 + $groups[ VariantOptionCompl::className() ],
  770 + 'lang.alias.value'
  771 + )
  772 + );
  773 + }
  774 + }
  775 + if (!empty($groups[ VariantOptionExcl::className() ])) {
  776 + if (empty($link)) {
  777 + $link = $this->writeVOC($groups);
  778 + } else {
  779 + $link .= '_' . $this->writeVOE($groups);
  780 + }
  781 + }
  782 + break;
  783 + case VariantOptionExcl::className():
  784 + if (!empty($groups[ VariantOptionExcl::className() ])) {
  785 + foreach ($groups[ VariantOptionExcl::className() ] as $index => $object) {
  786 + /**
  787 + * @var VariantOptionExcl $object
  788 + * @var VariantOptionExcl $model
  789 + */
  790 + if ($object->lang->alias->value == $model->lang->alias->value) {
  791 + unset($groups[ VariantOptionExcl::className() ][ $index ]);
  792 + $skip = true;
  793 + break;
  794 + }
  795 + }
  796 + }
  797 + if (!$skip) {
  798 + $groups[ VariantOptionExcl::className() ][] = $model;
  799 + usort(
  800 + $groups[ VariantOptionExcl::className() ],
  801 + function ($a, $b) {
  802 + /**
  803 + * @var VariantOptionExcl $a
  804 + * @var VariantOptionExcl $b
  805 + */
  806 + if ($a->group->sort > $b->group->sort) {
  807 + return 1;
  808 + } elseif ($a->group->sort < $b->group->sort) {
  809 + return -1;
  810 + } else {
  811 + if ($a->group->id > $b->group->id) {
  812 + return 1;
  813 + } elseif ($a->group->id < $b->group->id) {
  814 + return -1;
  815 + } else {
  816 + if ($a->sort > $b->sort) {
  817 + return 1;
  818 + } elseif ($a->sort < $b->sort) {
  819 + return -1;
  820 + } else {
  821 + return strcasecmp($a->lang->value, $b->lang->value);
  822 + }
  823 + }
  824 + }
  825 + }
  826 + );
  827 + }
  828 + if (!empty($groups[ Brand::className() ])) {
  829 + $link = $this->writeBrands($groups);
  830 + }
  831 + if (!empty($groups[ ProductOptionCompl::className() ])) {
  832 + if (!empty($link)) {
  833 + $link .= '_' . $this->writePOC($groups);
  834 + } else {
  835 + $link = $this->writePOC($groups);
  836 + }
  837 + }
  838 + if (!empty($groups[ ProductOptionExcl::className() ])) {
  839 + if (!empty($link)) {
  840 + $link .= '_' . $this->writePOE($groups);
  841 + } else {
  842 + $link = $this->writePOE($groups);
  843 + }
  844 + }
  845 + if (!empty($groups[ VariantOptionCompl::className() ])) {
  846 + if (!empty($link)) {
  847 + $link .= '_' . $this->writeVOC($groups);
  848 + } else {
  849 + $link = $this->writeVOC($groups);
  850 + }
  851 + }
  852 + if (empty($link)) {
  853 + $link = implode(
  854 + '_',
  855 + ArrayHelper::getColumn(
  856 + $groups[ VariantOptionExcl::className() ],
  857 + 'lang.alias.value'
  858 + )
  859 + );
  860 + } else {
  861 + if (!empty(
  862 + ArrayHelper::getColumn(
  863 + $groups[ VariantOptionExcl::className() ],
  864 + 'lang.alias.value'
  865 + )
  866 + )
  867 + ) {
  868 + $link .= '_' . implode(
  869 + '_',
  870 + ArrayHelper::getColumn(
  871 + $groups[ VariantOptionExcl::className() ],
  872 + 'lang.alias.value'
  873 + )
  874 + );
  875 + }
  876 + }
  877 + break;
  878 + }
  879 + } else {
  880 + if (!empty($groups[ Brand::className() ])) {
  881 + $link = $this->writeBrands($groups);
  882 + }
  883 + if (!empty($groups[ ProductOptionCompl::className() ])) {
  884 + if (empty($link)) {
  885 + $link = $this->writePOC($groups);
  886 + } else {
  887 + $link .= '_' . $this->writePOC($groups);
  888 + }
  889 + }
  890 + if (!empty($groups[ ProductOptionExcl::className() ])) {
  891 + if (empty($link)) {
  892 + $link = $this->writePOE($groups);
  893 + } else {
  894 + $link .= '_' . $this->writePOE($groups);
  895 + }
  896 + }
  897 + if (!empty($groups[ VariantOptionCompl::className() ])) {
  898 + if (empty($link)) {
  899 + $link = $this->writeVOC($groups);
  900 + } else {
  901 + $link .= '_' . $this->writeVOC($groups);
  902 + }
  903 + }
  904 + if (!empty($groups[ VariantOptionExcl::className() ])) {
  905 + if (empty($link)) {
  906 + $link = $this->writeVOE($groups);
  907 + } else {
  908 + $link .= '_' . $this->writeVOE($groups);
  909 + }
  910 + }
  911 + }
  912 + if (!empty($groupsFilter[ 'prices' ])) {
  913 + if (!empty($link)) {
  914 + $link .= '_' . 'price-' . $groupsFilter[ 'prices' ][ 0 ] . '-' . $groupsFilter[ 'prices' ][ 1 ];
  915 + } else {
  916 + $link = 'price-' . $groupsFilter[ 'prices' ][ 0 ] . '-' . $groupsFilter[ 'prices' ][ 1 ];
  917 + }
  918 + }
  919 + return $link;
  920 + }
  921 +
  922 + /**
  923 + * Build link with custom price values
  924 + *
  925 + * @param $min
  926 + * @param $max
  927 + *
  928 + * @return string
  929 + */
  930 + public function buildPrice($min, $max)
  931 + {
  932 + $groupFilter = $this->groupFilters;
  933 + $currentMin = null;
  934 + $currentMax = null;
  935 + if (!empty($groupFilter[ 'prices' ])) {
  936 + $currentMin = $groupFilter[ 'prices' ][ 0 ];
  937 + $currentMax = $groupFilter[ 'prices' ][ 1 ];
  938 + }
  939 + $this->groupFilters[ 'prices' ][ 0 ] = $min;
  940 + $this->groupFilters[ 'prices' ][ 1 ] = $max;
  941 + $link = $this->buildLink();
  942 + if (!empty($currentMin) && !empty($currentMax)) {
  943 + $this->groupFilters[ 'prices' ][ 0 ] = $currentMin;
  944 + $this->groupFilters[ 'prices' ][ 1 ] = $currentMax;
  945 + } else {
  946 + unset ($this->groupFilters[ 'prices' ]);
  947 + }
  948 + return $link;
  949 + }
  950 +
  951 + protected function writeBrands(array $groups)
  952 + {
  953 + usort(
  954 + $groups[ Brand::className() ],
  955 + function ($a, $b) {
  956 + /**
  957 + * @var Brand $a
  958 + * @var Brand $b
  959 + */
  960 + if ($a->sort > $b->sort) {
  961 + return 1;
  962 + } elseif ($a->sort < $b->sort) {
  963 + return -1;
  964 + } else {
  965 + return strcmp($a->lang->title, $b->lang->title);
  966 + }
  967 + }
  968 + );
  969 + return implode('_', ArrayHelper::getColumn($groups[ Brand::className() ], 'lang.alias.value'));
  970 + }
  971 +
  972 + protected function writePOC(array $groups)
  973 + {
  974 + usort(
  975 + $groups[ ProductOptionCompl::className() ],
  976 + function ($a, $b) {
  977 + /**
  978 + * @var ProductOptionCompl $a
  979 + * @var ProductOptionCompl $b
  980 + */
  981 + if ($a->group->sort > $b->group->sort) {
  982 + return 1;
  983 + } elseif ($a->group->sort < $b->group->sort) {
  984 + return -1;
  985 + } else {
  986 + if ($a->group->id > $b->group->id) {
  987 + return 1;
  988 + } elseif ($a->group->id < $b->group->id) {
  989 + return -1;
  990 + } else {
  991 + if ($a->sort > $b->sort) {
  992 + return 1;
  993 + } elseif ($a->sort < $b->sort) {
  994 + return -1;
  995 + } else {
  996 + return strcasecmp($a->lang->value, $b->lang->value);
  997 + }
  998 + }
  999 + }
  1000 + }
  1001 + );
  1002 + return implode(
  1003 + '_',
  1004 + ArrayHelper::getColumn(
  1005 + $groups[ ProductOptionCompl::className() ],
  1006 + 'lang.alias.value'
  1007 + )
  1008 + );
  1009 + }
  1010 +
  1011 + protected function writePOE(array $groups)
  1012 + {
  1013 + usort(
  1014 + $groups[ ProductOptionExcl::className() ],
  1015 + function ($a, $b) {
  1016 + /**
  1017 + * @var ProductOptionExcl $a
  1018 + * @var ProductOptionExcl $b
  1019 + */
  1020 + if ($a->group->sort > $b->group->sort) {
  1021 + return 1;
  1022 + } elseif ($a->group->sort < $b->group->sort) {
  1023 + return -1;
  1024 + } else {
  1025 + if ($a->group->id > $b->group->id) {
  1026 + return 1;
  1027 + } elseif ($a->group->id < $b->group->id) {
  1028 + return -1;
  1029 + } else {
  1030 + if ($a->sort > $b->sort) {
  1031 + return 1;
  1032 + } elseif ($a->sort < $b->sort) {
  1033 + return -1;
  1034 + } else {
  1035 + return strcasecmp($a->lang->value, $b->lang->value);
  1036 + }
  1037 + }
  1038 + }
  1039 + }
  1040 + );
  1041 + return implode(
  1042 + '_',
  1043 + ArrayHelper::getColumn(
  1044 + $groups[ ProductOptionExcl::className() ],
  1045 + 'lang.alias.value'
  1046 + )
  1047 + );
  1048 + }
  1049 +
  1050 + protected function writeVOC(array $groups)
  1051 + {
  1052 + usort(
  1053 + $groups[ VariantOptionCompl::className() ],
  1054 + function ($a, $b) {
  1055 + /**
  1056 + * @var VariantOptionCompl $a
  1057 + * @var VariantOptionCompl $b
  1058 + */
  1059 + if ($a->group->sort > $b->group->sort) {
  1060 + return 1;
  1061 + } elseif ($a->group->sort < $b->group->sort) {
  1062 + return -1;
  1063 + } else {
  1064 + if ($a->group->id > $b->group->id) {
  1065 + return 1;
  1066 + } elseif ($a->group->id < $b->group->id) {
  1067 + return -1;
  1068 + } else {
  1069 + if ($a->sort > $b->sort) {
  1070 + return 1;
  1071 + } elseif ($a->sort < $b->sort) {
  1072 + return -1;
  1073 + } else {
  1074 + return strcasecmp($a->lang->value, $b->lang->value);
  1075 + }
  1076 + }
  1077 + }
  1078 + }
  1079 + );
  1080 + return implode(
  1081 + '_',
  1082 + ArrayHelper::getColumn(
  1083 + $groups[ VariantOptionCompl::className() ],
  1084 + 'lang.alias.value'
  1085 + )
  1086 + );
  1087 + }
  1088 +
  1089 + protected function writeVOE(array $groups)
  1090 + {
  1091 + usort(
  1092 + $groups[ VariantOptionExcl::className() ],
  1093 + function ($a, $b) {
  1094 + /**
  1095 + * @var VariantOptionExcl $a
  1096 + * @var VariantOptionExcl $b
  1097 + */
  1098 + if ($a->group->sort > $b->group->sort) {
  1099 + return 1;
  1100 + } elseif ($a->group->sort < $b->group->sort) {
  1101 + return -1;
  1102 + } else {
  1103 + if ($a->group->id > $b->group->id) {
  1104 + return 1;
  1105 + } elseif ($a->group->id < $b->group->id) {
  1106 + return -1;
  1107 + } else {
  1108 + if ($a->sort > $b->sort) {
  1109 + return 1;
  1110 + } elseif ($a->sort < $b->sort) {
  1111 + return -1;
  1112 + } else {
  1113 + return strcasecmp($a->lang->value, $b->lang->value);
  1114 + }
  1115 + }
  1116 + }
  1117 + }
  1118 + );
  1119 + return implode(
  1120 + '_',
  1121 + ArrayHelper::getColumn(
  1122 + $groups[ VariantOptionExcl::className() ],
  1123 + 'lang.alias.value'
  1124 + )
  1125 + );
  1126 + }
  1127 +
  1128 + protected function getPrices(string $filter)
  1129 + {
  1130 + $filters = $this->parseFilter($filter);
  1131 + foreach ($filters as $item) {
  1132 + if (preg_match('/^price-(\d+)-(\d+)$/', $item, $matches)) {
  1133 + $this->groupFilters[ 'prices' ] = [
  1134 + $matches[ 1 ],
  1135 + $matches[ 2 ],
  1136 + ];
  1137 + }
  1138 + }
  1139 + }
  1140 +
  1141 + public function has(string $alias): bool
  1142 + {
  1143 + $aliases = ArrayHelper::getColumn($this->getActiveAliases(), 'value');
  1144 + return in_array($alias, $aliases);
  1145 + }
  1146 + }
0 1147 \ No newline at end of file
... ...
artweb/artbox-catalog/messages/en/catalog.php 0 → 100755
  1 +<?php
  2 + return [];
0 3 \ No newline at end of file
... ...
artweb/artbox-catalog/messages/ru/catalog.php 0 → 100755
  1 +<?php
  2 + return [
  3 + 'Articles' => 'Статьи',
  4 + 'Categories' => 'Категории',
  5 + 'Tags' => 'Теги',
  6 + 'Brands' => 'Бренды',
  7 + 'Products' => 'Товары',
  8 + 'Import' => 'Импорт',
  9 + 'Save' => 'Сохранить',
  10 + 'Create Category' => 'Создать категорию',
  11 + 'Title' => 'Заголовок',
  12 + 'Search for a category ...' => 'Искать категорию ...',
  13 + 'Waiting for results...' => 'Ожидание результатов',
  14 + 'Create' => 'Создать',
  15 + 'Update' => 'Обновить',
  16 + 'Description' => 'Описание',
  17 + 'Create Brand' => 'Создать бренд',
  18 + 'Create Product' => 'Создать товар',
  19 + 'Upload Document' => 'Загрузить документ',
  20 + 'Send' => 'Отправить',
  21 + 'Generate' => 'Сгенерировать',
  22 + 'Alias Value' => 'Значение псевдонима',
  23 + 'Category' => 'категорию',
  24 + 'Update Category' => 'Обновить категорию',
  25 + 'Image' => 'Изображение',
  26 + 'Brand Title' => 'Заголовок бренда',
  27 + 'Created At' => 'Создано',
  28 + 'Status' => 'Статус',
  29 + 'Sort' => 'Сортировка',
  30 + 'Common' => 'Общее',
  31 + 'Options' => 'Опции',
  32 + 'Gallery' => 'Галерея',
  33 + 'Add' => 'Добавить',
  34 + 'Product option group complementary' => 'Дополнительные группы опций товара',
  35 + 'Is Filter' => 'Является фильтром',
  36 + 'Search for a categories ...' => 'Поиск категорий ..',
  37 + 'Product option group exclude' => 'Исключения группы опций товара',
  38 + 'Variant option group exclude' => 'Исключения группы варианта товара',
  39 + 'Option Groups' => 'Группы опций',
  40 + 'Image Id' => 'ID изображения',
  41 + 'Updated At' => 'Обновлено',
  42 + 'Body' => 'Тело',
  43 + 'Body Preview' => 'Предпросмотр',
  44 + 'Author ID' => 'ID автора',
  45 + 'Parent ID' => 'Родительский ID',
  46 + 'Comments' => 'Комментарии',
  47 + 'Export to' => 'Сделать выгрузку',
  48 + 'Price update' => 'Обновление цен',
  49 + ];
0 50 \ No newline at end of file
... ...
artweb/artbox-catalog/migrations/m170405_000001_brand.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000001_brand extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'brand',
  11 + [
  12 + 'id' => $this->primaryKey(),
  13 + 'image_id' => $this->integer(),
  14 + 'sort' => $this->integer()
  15 + ->defaultValue(0),
  16 + 'status' => $this->boolean()
  17 + ->defaultValue(true),
  18 + 'created_at' => $this->integer(),
  19 + 'updated_at' => $this->integer(),
  20 + ]
  21 + );
  22 +
  23 + $this->addForeignKey(
  24 + 'brand_image_id_to_image_manager_fk',
  25 + 'brand',
  26 + 'image_id',
  27 + 'ImageManager',
  28 + 'id',
  29 + 'SET NULL',
  30 + 'CASCADE'
  31 + );
  32 + }
  33 +
  34 + public function safeDown()
  35 + {
  36 + $this->dropForeignKey(
  37 + 'brand_image_id_to_image_manager_fk',
  38 + 'brand'
  39 + );
  40 + $this->dropTable('brand');
  41 + }
  42 + }
... ...
artweb/artbox-catalog/migrations/m170405_000002_brand_lang.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000002_brand_lang extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'brand_lang',
  11 + [
  12 + 'brand_id' => $this->integer(32)
  13 + ->notNull(),
  14 + 'language_id' => $this->integer(32)
  15 + ->notNull(),
  16 + 'title' => $this->string(255)
  17 + ->notNull(),
  18 + 'alias_id' => $this->integer(),
  19 + 'description' => $this->text(),
  20 + ]
  21 + );
  22 + $this->createIndex('brand_lang_alias_id', 'brand_lang', 'alias_id', true);
  23 + $this->addPrimaryKey(
  24 + 'brand_lang_pk',
  25 + 'brand_lang',
  26 + [
  27 + 'brand_id',
  28 + 'language_id',
  29 + ]
  30 + );
  31 + $this->addForeignKey(
  32 + 'brand_lang_brand_id_to_brand_fk',
  33 + 'brand_lang',
  34 + 'brand_id',
  35 + 'brand',
  36 + 'id',
  37 + 'CASCADE',
  38 + 'CASCADE'
  39 + );
  40 + $this->addForeignKey(
  41 + 'brand_lang_language_id_to_language_fk',
  42 + 'brand_lang',
  43 + 'language_id',
  44 + 'language',
  45 + 'id',
  46 + 'RESTRICT',
  47 + 'CASCADE'
  48 + );
  49 + $this->addForeignKey(
  50 + 'brand_lang_alias_id_to_alias_fk',
  51 + 'brand_lang',
  52 + 'alias_id',
  53 + 'alias',
  54 + 'id',
  55 + 'SET NULL',
  56 + 'CASCADE'
  57 + );
  58 + }
  59 +
  60 + public function safeDown()
  61 + {
  62 + $this->dropForeignKey(
  63 + 'brand_lang_alias_id_to_alias_fk',
  64 + 'brand_lang'
  65 + );
  66 + $this->dropForeignKey(
  67 + 'brand_lang_language_id_to_language_fk',
  68 + 'brand_lang'
  69 + );
  70 + $this->dropForeignKey(
  71 + 'brand_lang_brand_id_to_brand_fk',
  72 + 'brand_lang'
  73 + );
  74 + $this->dropIndex('brand_lang_alias_id', 'brand_lang');
  75 + $this->dropTable('brand_lang');
  76 + }
  77 + }
... ...
artweb/artbox-catalog/migrations/m170405_000003_product.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000003_product extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'product',
  11 + [
  12 + 'id' => $this->primaryKey(),
  13 + 'brand_id' => $this->integer(),
  14 + 'video' => $this->text(),
  15 + 'mask' => $this->integer(),
  16 + 'status' => $this->boolean()
  17 + ->defaultValue(true),
  18 + 'sort' => $this->integer()
  19 + ->defaultValue(0),
  20 + 'created_at' => $this->integer(),
  21 + 'updated_at' => $this->integer(),
  22 + ]
  23 + );
  24 +
  25 + $this->addForeignKey(
  26 + 'product_brand_id_to_brand_fk',
  27 + 'product',
  28 + 'brand_id',
  29 + 'brand',
  30 + 'id',
  31 + 'SET NULL',
  32 + 'CASCADE'
  33 + );
  34 + }
  35 +
  36 + public function safeDown()
  37 + {
  38 + $this->dropForeignKey(
  39 + 'product_brand_id_to_brand_fk',
  40 + 'product'
  41 + );
  42 + $this->dropTable('product');
  43 + }
  44 + }
... ...
artweb/artbox-catalog/migrations/m170405_000004_product_lang.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000004_product_lang extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'product_lang',
  11 + [
  12 + 'product_id' => $this->integer(32)
  13 + ->notNull(),
  14 + 'language_id' => $this->integer(32)
  15 + ->notNull(),
  16 + 'title' => $this->string(255)
  17 + ->notNull(),
  18 + 'alias_id' => $this->integer(),
  19 + 'description' => $this->text(),
  20 + ]
  21 + );
  22 + $this->createIndex('product_lang_alias_id', 'product_lang', 'alias_id', true);
  23 + $this->addPrimaryKey(
  24 + 'product_lang_pk',
  25 + 'product_lang',
  26 + [
  27 + 'product_id',
  28 + 'language_id',
  29 + ]
  30 + );
  31 + $this->addForeignKey(
  32 + 'product_lang_product_id_to_product_fk',
  33 + 'product_lang',
  34 + 'product_id',
  35 + 'product',
  36 + 'id',
  37 + 'CASCADE',
  38 + 'CASCADE'
  39 + );
  40 + $this->addForeignKey(
  41 + 'product_lang_language_id_to_language_fk',
  42 + 'product_lang',
  43 + 'language_id',
  44 + 'language',
  45 + 'id',
  46 + 'RESTRICT',
  47 + 'CASCADE'
  48 + );
  49 + $this->addForeignKey(
  50 + 'product_lang_alias_id_to_alias_fk',
  51 + 'product_lang',
  52 + 'alias_id',
  53 + 'alias',
  54 + 'id',
  55 + 'SET NULL',
  56 + 'CASCADE'
  57 + );
  58 + }
  59 +
  60 + public function safeDown()
  61 + {
  62 + $this->dropForeignKey(
  63 + 'product_lang_alias_id_to_alias_fk',
  64 + 'product_lang'
  65 + );
  66 + $this->dropForeignKey(
  67 + 'product_lang_language_id_to_language_fk',
  68 + 'product_lang'
  69 + );
  70 + $this->dropForeignKey(
  71 + 'product_lang_product_id_to_product_fk',
  72 + 'product_lang'
  73 + );
  74 + $this->dropIndex('product_lang_alias_id', 'product_lang');
  75 + $this->dropTable('product_lang');
  76 + }
  77 + }
... ...
artweb/artbox-catalog/migrations/m170405_000005_category.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000005_category extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'category',
  11 + [
  12 + 'id' => $this->primaryKey(),
  13 + 'image_id' => $this->integer(),
  14 + 'thumb_id' => $this->integer(),
  15 + 'parent_id' => $this->integer(),
  16 + 'level' => $this->integer()
  17 + ->notNull()
  18 + ->defaultValue(0),
  19 + 'sort' => $this->integer()
  20 + ->defaultValue(0),
  21 + 'status' => $this->boolean()
  22 + ->defaultValue(true),
  23 + 'created_at' => $this->integer(),
  24 + 'updated_at' => $this->integer(),
  25 + ]
  26 + );
  27 +
  28 + $this->addForeignKey(
  29 + 'category_image_id_to_image_manager_fk',
  30 + 'category',
  31 + 'image_id',
  32 + 'ImageManager',
  33 + 'id',
  34 + 'SET NULL',
  35 + 'CASCADE'
  36 + );
  37 +
  38 + $this->addForeignKey(
  39 + 'category_thumb_id_to_image_manager_fk',
  40 + 'category',
  41 + 'thumb_id',
  42 + 'ImageManager',
  43 + 'id',
  44 + 'SET NULL',
  45 + 'CASCADE'
  46 + );
  47 +
  48 + $this->addForeignKey(
  49 + 'category_parent_id_to_category_fk',
  50 + 'category',
  51 + 'parent_id',
  52 + 'category',
  53 + 'id',
  54 + 'CASCADE',
  55 + 'CASCADE'
  56 + );
  57 + }
  58 +
  59 + public function safeDown()
  60 + {
  61 + $this->dropForeignKey(
  62 + 'category_image_id_to_image_manager_fk',
  63 + 'category'
  64 + );
  65 + $this->dropForeignKey(
  66 + 'category_thumb_id_to_image_manager_fk',
  67 + 'category'
  68 + );
  69 + $this->dropForeignKey(
  70 + 'category_parent_id_to_category_fk',
  71 + 'category'
  72 + );
  73 + $this->dropTable('category');
  74 + }
  75 + }
... ...
artweb/artbox-catalog/migrations/m170405_000006_category_lang.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000006_category_lang extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'category_lang',
  11 + [
  12 + 'category_id' => $this->integer(32)
  13 + ->notNull(),
  14 + 'language_id' => $this->integer(32)
  15 + ->notNull(),
  16 + 'title' => $this->string(255)
  17 + ->notNull(),
  18 + 'alias_id' => $this->integer(),
  19 + 'description' => $this->text(),
  20 + ]
  21 + );
  22 + $this->createIndex('category_lang_alias_id', 'category_lang', 'alias_id', true);
  23 + $this->addPrimaryKey(
  24 + 'category_lang_pk',
  25 + 'category_lang',
  26 + [
  27 + 'category_id',
  28 + 'language_id',
  29 + ]
  30 + );
  31 + $this->addForeignKey(
  32 + 'category_lang_category_id_to_category_fk',
  33 + 'category_lang',
  34 + 'category_id',
  35 + 'category',
  36 + 'id',
  37 + 'CASCADE',
  38 + 'CASCADE'
  39 + );
  40 + $this->addForeignKey(
  41 + 'category_lang_language_id_to_language_fk',
  42 + 'category_lang',
  43 + 'language_id',
  44 + 'language',
  45 + 'id',
  46 + 'RESTRICT',
  47 + 'CASCADE'
  48 + );
  49 + $this->addForeignKey(
  50 + 'category_lang_alias_id_to_alias_fk',
  51 + 'category_lang',
  52 + 'alias_id',
  53 + 'alias',
  54 + 'id',
  55 + 'SET NULL',
  56 + 'CASCADE'
  57 + );
  58 + }
  59 +
  60 + public function safeDown()
  61 + {
  62 + $this->dropForeignKey(
  63 + 'category_lang_alias_id_to_alias_fk',
  64 + 'category_lang'
  65 + );
  66 + $this->dropForeignKey(
  67 + 'category_lang_language_id_to_language_fk',
  68 + 'category_lang'
  69 + );
  70 + $this->dropForeignKey(
  71 + 'category_lang_category_id_to_category_fk',
  72 + 'category_lang'
  73 + );
  74 + $this->dropIndex('category_lang_alias_id', 'category_lang');
  75 + $this->dropTable('category_lang');
  76 + }
  77 + }
... ...
artweb/artbox-catalog/migrations/m170405_000007_product_to_category.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000007_product_to_category extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'product_to_category',
  11 + [
  12 + 'product_id' => $this->integer()
  13 + ->notNull(),
  14 + 'category_id' => $this->integer()
  15 + ->notNull(),
  16 + ]
  17 + );
  18 +
  19 + $this->addPrimaryKey(
  20 + 'product_to_category_pk',
  21 + 'product_to_category',
  22 + [
  23 + 'product_id',
  24 + 'category_id',
  25 + ]
  26 + );
  27 +
  28 + $this->addForeignKey(
  29 + 'product_to_category_product_id_to_product_fk',
  30 + 'product_to_category',
  31 + 'product_id',
  32 + 'product',
  33 + 'id',
  34 + 'CASCADE',
  35 + 'CASCADE'
  36 + );
  37 +
  38 + $this->addForeignKey(
  39 + 'product_to_category_category_id_to_category_fk',
  40 + 'product_to_category',
  41 + 'category_id',
  42 + 'category',
  43 + 'id',
  44 + 'CASCADE',
  45 + 'CASCADE'
  46 + );
  47 + }
  48 +
  49 + public function safeDown()
  50 + {
  51 + $this->dropForeignKey(
  52 + 'product_to_category_product_id_to_product_fk',
  53 + 'product_to_category'
  54 + );
  55 + $this->dropForeignKey(
  56 + 'product_to_category_category_id_to_category_fk',
  57 + 'product_to_category'
  58 + );
  59 + $this->dropTable('product_to_category');
  60 + }
  61 + }
... ...
artweb/artbox-catalog/migrations/m170405_000008_product_to_image.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000008_product_to_image extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'product_to_image',
  11 + [
  12 + 'product_id' => $this->integer()
  13 + ->notNull(),
  14 + 'image_id' => $this->integer()
  15 + ->notNull(),
  16 + ]
  17 + );
  18 +
  19 + $this->addPrimaryKey(
  20 + 'product_to_image_pk',
  21 + 'product_to_image',
  22 + [
  23 + 'product_id',
  24 + 'image_id',
  25 + ]
  26 + );
  27 +
  28 + $this->addForeignKey(
  29 + 'product_to_image_product_id_to_product_fk',
  30 + 'product_to_image',
  31 + 'product_id',
  32 + 'product',
  33 + 'id',
  34 + 'CASCADE',
  35 + 'CASCADE'
  36 + );
  37 +
  38 + $this->addForeignKey(
  39 + 'product_to_image_image_id_to_image_manager_fk',
  40 + 'product_to_image',
  41 + 'image_id',
  42 + 'ImageManager',
  43 + 'id',
  44 + 'CASCADE',
  45 + 'CASCADE'
  46 + );
  47 + }
  48 +
  49 + public function safeDown()
  50 + {
  51 + $this->dropForeignKey(
  52 + 'product_to_image_product_id_to_product_fk',
  53 + 'product_to_image'
  54 + );
  55 + $this->dropForeignKey(
  56 + 'product_to_image_image_id_to_image_manager_fk',
  57 + 'product_to_image'
  58 + );
  59 + $this->dropTable('product_to_image');
  60 + }
  61 + }
... ...
artweb/artbox-catalog/migrations/m170405_000009_variant.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000009_variant extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'variant',
  11 + [
  12 + 'id' => $this->primaryKey(),
  13 + 'product_id' => $this->integer()
  14 + ->notNull(),
  15 + 'sku' => $this->string()
  16 + ->notNull(),
  17 + 'price' => $this->decimal(),
  18 + 'price_old' => $this->decimal(),
  19 + 'stock' => $this->integer()
  20 + ->notNull()
  21 + ->defaultValue(0),
  22 + 'status' => $this->boolean()
  23 + ->defaultValue(true),
  24 + 'sort' => $this->integer()
  25 + ->defaultValue(0),
  26 + 'created_at' => $this->integer(),
  27 + 'updated_at' => $this->integer(),
  28 + ]
  29 + );
  30 +
  31 + $this->addForeignKey(
  32 + 'variant_product_id_to_product_fk',
  33 + 'variant',
  34 + 'product_id',
  35 + 'product',
  36 + 'id',
  37 + 'CASCADE',
  38 + 'CASCADE'
  39 + );
  40 + }
  41 +
  42 + public function safeDown()
  43 + {
  44 + $this->dropForeignKey(
  45 + 'variant_product_id_to_product_fk',
  46 + 'variant'
  47 + );
  48 + $this->dropTable('variant');
  49 + }
  50 + }
... ...
artweb/artbox-catalog/migrations/m170405_000010_variant_lang.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000010_variant_lang extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'variant_lang',
  11 + [
  12 + 'variant_id' => $this->integer(32)
  13 + ->notNull(),
  14 + 'language_id' => $this->integer(32)
  15 + ->notNull(),
  16 + 'title' => $this->string(255)
  17 + ->notNull(),
  18 + 'alias_id' => $this->integer(),
  19 + 'description' => $this->text(),
  20 + ]
  21 + );
  22 + $this->createIndex('variant_lang_alias_id', 'variant_lang', 'alias_id', true);
  23 + $this->addPrimaryKey(
  24 + 'variant_lang_pk',
  25 + 'variant_lang',
  26 + [
  27 + 'variant_id',
  28 + 'language_id',
  29 + ]
  30 + );
  31 + $this->addForeignKey(
  32 + 'variant_lang_variant_id_to_variant_fk',
  33 + 'variant_lang',
  34 + 'variant_id',
  35 + 'variant',
  36 + 'id',
  37 + 'CASCADE',
  38 + 'CASCADE'
  39 + );
  40 + $this->addForeignKey(
  41 + 'variant_lang_language_id_to_language_fk',
  42 + 'variant_lang',
  43 + 'language_id',
  44 + 'language',
  45 + 'id',
  46 + 'RESTRICT',
  47 + 'CASCADE'
  48 + );
  49 + $this->addForeignKey(
  50 + 'variant_lang_alias_id_to_alias_fk',
  51 + 'variant_lang',
  52 + 'alias_id',
  53 + 'alias',
  54 + 'id',
  55 + 'SET NULL',
  56 + 'CASCADE'
  57 + );
  58 + }
  59 +
  60 + public function safeDown()
  61 + {
  62 + $this->dropForeignKey(
  63 + 'variant_lang_alias_id_to_alias_fk',
  64 + 'variant_lang'
  65 + );
  66 + $this->dropForeignKey(
  67 + 'variant_lang_language_id_to_language_fk',
  68 + 'variant_lang'
  69 + );
  70 + $this->dropForeignKey(
  71 + 'variant_lang_variant_id_to_variant_fk',
  72 + 'variant_lang'
  73 + );
  74 + $this->dropIndex('variant_lang_alias_id', 'variant_lang');
  75 + $this->dropTable('variant_lang');
  76 + }
  77 + }
... ...
artweb/artbox-catalog/migrations/m170405_000011_variant_to_image.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000011_variant_to_image extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'variant_to_image',
  11 + [
  12 + 'variant_id' => $this->integer()
  13 + ->notNull(),
  14 + 'image_id' => $this->integer()
  15 + ->notNull(),
  16 + ]
  17 + );
  18 +
  19 + $this->addPrimaryKey(
  20 + 'variant_to_image_pk',
  21 + 'variant_to_image',
  22 + [
  23 + 'variant_id',
  24 + 'image_id',
  25 + ]
  26 + );
  27 +
  28 + $this->addForeignKey(
  29 + 'variant_to_image_variant_id_to_variant_fk',
  30 + 'variant_to_image',
  31 + 'variant_id',
  32 + 'variant',
  33 + 'id',
  34 + 'CASCADE',
  35 + 'CASCADE'
  36 + );
  37 +
  38 + $this->addForeignKey(
  39 + 'variant_to_image_image_id_to_image_manager_fk',
  40 + 'variant_to_image',
  41 + 'image_id',
  42 + 'ImageManager',
  43 + 'id',
  44 + 'CASCADE',
  45 + 'CASCADE'
  46 + );
  47 + }
  48 +
  49 + public function safeDown()
  50 + {
  51 + $this->dropForeignKey(
  52 + 'variant_to_image_variant_id_to_variant_fk',
  53 + 'variant_to_image'
  54 + );
  55 + $this->dropForeignKey(
  56 + 'variant_to_image_image_id_to_image_manager_fk',
  57 + 'variant_to_image'
  58 + );
  59 + $this->dropTable('variant_to_image');
  60 + }
  61 + }
... ...
artweb/artbox-catalog/migrations/m170405_000012_product_option_group_compl.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000012_product_option_group_compl extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'product_option_group_compl',
  11 + [
  12 + 'id' => $this->primaryKey(),
  13 + 'is_filter' => $this->boolean()
  14 + ->notNull()
  15 + ->defaultValue(false),
  16 + 'sort' => $this->integer()
  17 + ->defaultValue(0),
  18 + 'status' => $this->boolean()
  19 + ->defaultValue(true),
  20 + 'created_at' => $this->integer(),
  21 + 'updated_at' => $this->integer(),
  22 + ]
  23 + );
  24 + }
  25 +
  26 + public function safeDown()
  27 + {
  28 + $this->dropTable('product_option_group_compl');
  29 + }
  30 + }
... ...
artweb/artbox-catalog/migrations/m170405_000013_product_option_group_compl_lang.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000013_product_option_group_compl_lang extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'product_option_group_compl_lang',
  11 + [
  12 + 'product_option_group_compl_id' => $this->integer(32)
  13 + ->notNull(),
  14 + 'language_id' => $this->integer(32)
  15 + ->notNull(),
  16 + 'title' => $this->string(255)
  17 + ->notNull(),
  18 + 'alias_id' => $this->integer(),
  19 + 'description' => $this->text(),
  20 + ]
  21 + );
  22 + $this->createIndex(
  23 + 'product_option_group_compl_lang_alias_id',
  24 + 'product_option_group_compl_lang',
  25 + 'alias_id',
  26 + true
  27 + );
  28 + $this->addPrimaryKey(
  29 + 'product_option_group_compl_lang_pk',
  30 + 'product_option_group_compl_lang',
  31 + [
  32 + 'product_option_group_compl_id',
  33 + 'language_id',
  34 + ]
  35 + );
  36 + $this->addForeignKey(
  37 + 'product_option_group_compl_lang_product_option_group_compl_id_to_brand_fk',
  38 + 'product_option_group_compl_lang',
  39 + 'product_option_group_compl_id',
  40 + 'product_option_group_compl',
  41 + 'id',
  42 + 'CASCADE',
  43 + 'CASCADE'
  44 + );
  45 + $this->addForeignKey(
  46 + 'product_option_group_compl_lang_language_id_to_language_fk',
  47 + 'product_option_group_compl_lang',
  48 + 'language_id',
  49 + 'language',
  50 + 'id',
  51 + 'RESTRICT',
  52 + 'CASCADE'
  53 + );
  54 + $this->addForeignKey(
  55 + 'product_option_group_compl_lang_alias_id_to_alias_fk',
  56 + 'product_option_group_compl_lang',
  57 + 'alias_id',
  58 + 'alias',
  59 + 'id',
  60 + 'SET NULL',
  61 + 'CASCADE'
  62 + );
  63 + }
  64 +
  65 + public function safeDown()
  66 + {
  67 + $this->dropForeignKey(
  68 + 'product_option_group_compl_lang_alias_id_to_alias_fk',
  69 + 'product_option_group_compl_lang'
  70 + );
  71 + $this->dropForeignKey(
  72 + 'product_option_group_compl_lang_language_id_to_language_fk',
  73 + 'product_option_group_compl_lang'
  74 + );
  75 + $this->dropForeignKey(
  76 + 'product_option_group_compl_lang_product_option_group_compl_id_to_brand_fk',
  77 + 'product_option_group_compl_lang'
  78 + );
  79 + $this->dropIndex('product_option_group_compl_lang_alias_id', 'product_option_group_compl_lang');
  80 + $this->dropTable('product_option_group_compl_lang');
  81 + }
  82 + }
... ...
artweb/artbox-catalog/migrations/m170405_000014_product_option_group_excl.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000014_product_option_group_excl extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'product_option_group_excl',
  11 + [
  12 + 'id' => $this->primaryKey(),
  13 + 'is_filter' => $this->boolean()
  14 + ->notNull()
  15 + ->defaultValue(false),
  16 + 'sort' => $this->integer()
  17 + ->defaultValue(0),
  18 + 'status' => $this->boolean()
  19 + ->defaultValue(true),
  20 + 'created_at' => $this->integer(),
  21 + 'updated_at' => $this->integer(),
  22 + ]
  23 + );
  24 + }
  25 +
  26 + public function safeDown()
  27 + {
  28 + $this->dropTable('product_option_group_excl');
  29 + }
  30 + }
... ...
artweb/artbox-catalog/migrations/m170405_000015_product_option_group_excl_lang.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000015_product_option_group_excl_lang extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'product_option_group_excl_lang',
  11 + [
  12 + 'product_option_group_excl_id' => $this->integer(32)
  13 + ->notNull(),
  14 + 'language_id' => $this->integer(32)
  15 + ->notNull(),
  16 + 'title' => $this->string(255)
  17 + ->notNull(),
  18 + 'alias_id' => $this->integer(),
  19 + 'description' => $this->text(),
  20 + ]
  21 + );
  22 + $this->createIndex(
  23 + 'product_option_group_excl_lang_alias_id',
  24 + 'product_option_group_excl_lang',
  25 + 'alias_id',
  26 + true
  27 + );
  28 + $this->addPrimaryKey(
  29 + 'product_option_group_excl_lang_pk',
  30 + 'product_option_group_excl_lang',
  31 + [
  32 + 'product_option_group_excl_id',
  33 + 'language_id',
  34 + ]
  35 + );
  36 + $this->addForeignKey(
  37 + 'product_option_group_excl_lang_product_option_group_excl_id_to_brand_fk',
  38 + 'product_option_group_excl_lang',
  39 + 'product_option_group_excl_id',
  40 + 'product_option_group_excl',
  41 + 'id',
  42 + 'CASCADE',
  43 + 'CASCADE'
  44 + );
  45 + $this->addForeignKey(
  46 + 'product_option_group_excl_lang_language_id_to_language_fk',
  47 + 'product_option_group_excl_lang',
  48 + 'language_id',
  49 + 'language',
  50 + 'id',
  51 + 'RESTRICT',
  52 + 'CASCADE'
  53 + );
  54 + $this->addForeignKey(
  55 + 'product_option_group_excl_lang_alias_id_to_alias_fk',
  56 + 'product_option_group_excl_lang',
  57 + 'alias_id',
  58 + 'alias',
  59 + 'id',
  60 + 'SET NULL',
  61 + 'CASCADE'
  62 + );
  63 + }
  64 +
  65 + public function safeDown()
  66 + {
  67 + $this->dropForeignKey(
  68 + 'product_option_group_excl_lang_alias_id_to_alias_fk',
  69 + 'product_option_group_excl_lang'
  70 + );
  71 + $this->dropForeignKey(
  72 + 'product_option_group_excl_lang_language_id_to_language_fk',
  73 + 'product_option_group_excl_lang'
  74 + );
  75 + $this->dropForeignKey(
  76 + 'product_option_group_excl_lang_product_option_group_excl_id_to_brand_fk',
  77 + 'product_option_group_excl_lang'
  78 + );
  79 + $this->dropIndex('product_option_group_excl_lang_alias_id', 'product_option_group_excl_lang');
  80 + $this->dropTable('product_option_group_excl_lang');
  81 + }
  82 + }
... ...
artweb/artbox-catalog/migrations/m170405_000016_variant_option_group_compl.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000016_variant_option_group_compl extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'variant_option_group_compl',
  11 + [
  12 + 'id' => $this->primaryKey(),
  13 + 'is_filter' => $this->boolean()
  14 + ->notNull()
  15 + ->defaultValue(false),
  16 + 'sort' => $this->integer()
  17 + ->defaultValue(0),
  18 + 'status' => $this->boolean()
  19 + ->defaultValue(true),
  20 + 'created_at' => $this->integer(),
  21 + 'updated_at' => $this->integer(),
  22 + ]
  23 + );
  24 + }
  25 +
  26 + public function safeDown()
  27 + {
  28 + $this->dropTable('variant_option_group_compl');
  29 + }
  30 + }
... ...
artweb/artbox-catalog/migrations/m170405_000017_variant_option_group_compl_lang.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000017_variant_option_group_compl_lang extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'variant_option_group_compl_lang',
  11 + [
  12 + 'variant_option_group_compl_id' => $this->integer(32)
  13 + ->notNull(),
  14 + 'language_id' => $this->integer(32)
  15 + ->notNull(),
  16 + 'title' => $this->string(255)
  17 + ->notNull(),
  18 + 'alias_id' => $this->integer(),
  19 + 'description' => $this->text(),
  20 + ]
  21 + );
  22 + $this->createIndex(
  23 + 'variant_option_group_compl_lang_alias_id',
  24 + 'variant_option_group_compl_lang',
  25 + 'alias_id',
  26 + true
  27 + );
  28 + $this->addPrimaryKey(
  29 + 'variant_option_group_compl_lang_pk',
  30 + 'variant_option_group_compl_lang',
  31 + [
  32 + 'variant_option_group_compl_id',
  33 + 'language_id',
  34 + ]
  35 + );
  36 + $this->addForeignKey(
  37 + 'variant_option_group_compl_lang_variant_option_group_compl_id_to_brand_fk',
  38 + 'variant_option_group_compl_lang',
  39 + 'variant_option_group_compl_id',
  40 + 'variant_option_group_compl',
  41 + 'id',
  42 + 'CASCADE',
  43 + 'CASCADE'
  44 + );
  45 + $this->addForeignKey(
  46 + 'variant_option_group_compl_lang_language_id_to_language_fk',
  47 + 'variant_option_group_compl_lang',
  48 + 'language_id',
  49 + 'language',
  50 + 'id',
  51 + 'RESTRICT',
  52 + 'CASCADE'
  53 + );
  54 + $this->addForeignKey(
  55 + 'variant_option_group_compl_lang_alias_id_to_alias_fk',
  56 + 'variant_option_group_compl_lang',
  57 + 'alias_id',
  58 + 'alias',
  59 + 'id',
  60 + 'SET NULL',
  61 + 'CASCADE'
  62 + );
  63 + }
  64 +
  65 + public function safeDown()
  66 + {
  67 + $this->dropForeignKey(
  68 + 'variant_option_group_compl_lang_alias_id_to_alias_fk',
  69 + 'variant_option_group_compl_lang'
  70 + );
  71 + $this->dropForeignKey(
  72 + 'variant_option_group_compl_lang_language_id_to_language_fk',
  73 + 'variant_option_group_compl_lang'
  74 + );
  75 + $this->dropForeignKey(
  76 + 'variant_option_group_compl_lang_variant_option_group_compl_id_to_brand_fk',
  77 + 'variant_option_group_compl_lang'
  78 + );
  79 + $this->dropIndex('variant_option_group_compl_lang_alias_id', 'variant_option_group_compl_lang');
  80 + $this->dropTable('variant_option_group_compl_lang');
  81 + }
  82 + }
... ...
artweb/artbox-catalog/migrations/m170405_000018_variant_option_group_excl.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000018_variant_option_group_excl extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'variant_option_group_excl',
  11 + [
  12 + 'id' => $this->primaryKey(),
  13 + 'is_filter' => $this->boolean()
  14 + ->notNull()
  15 + ->defaultValue(false),
  16 + 'sort' => $this->integer()
  17 + ->defaultValue(0),
  18 + 'status' => $this->boolean()
  19 + ->defaultValue(true),
  20 + 'created_at' => $this->integer(),
  21 + 'updated_at' => $this->integer(),
  22 + ]
  23 + );
  24 + }
  25 +
  26 + public function safeDown()
  27 + {
  28 + $this->dropTable('variant_option_group_excl');
  29 + }
  30 + }
... ...
artweb/artbox-catalog/migrations/m170405_000019_variant_option_group_excl_lang.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000019_variant_option_group_excl_lang extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'variant_option_group_excl_lang',
  11 + [
  12 + 'variant_option_group_excl_id' => $this->integer(32)
  13 + ->notNull(),
  14 + 'language_id' => $this->integer(32)
  15 + ->notNull(),
  16 + 'title' => $this->string(255)
  17 + ->notNull(),
  18 + 'alias_id' => $this->integer(),
  19 + 'description' => $this->text(),
  20 + ]
  21 + );
  22 + $this->createIndex(
  23 + 'variant_option_group_excl_lang_alias_id',
  24 + 'variant_option_group_excl_lang',
  25 + 'alias_id',
  26 + true
  27 + );
  28 + $this->addPrimaryKey(
  29 + 'variant_option_group_excl_lang_pk',
  30 + 'variant_option_group_excl_lang',
  31 + [
  32 + 'variant_option_group_excl_id',
  33 + 'language_id',
  34 + ]
  35 + );
  36 + $this->addForeignKey(
  37 + 'variant_option_group_excl_lang_variant_option_group_excl_id_to_brand_fk',
  38 + 'variant_option_group_excl_lang',
  39 + 'variant_option_group_excl_id',
  40 + 'variant_option_group_excl',
  41 + 'id',
  42 + 'CASCADE',
  43 + 'CASCADE'
  44 + );
  45 + $this->addForeignKey(
  46 + 'variant_option_group_excl_lang_language_id_to_language_fk',
  47 + 'variant_option_group_excl_lang',
  48 + 'language_id',
  49 + 'language',
  50 + 'id',
  51 + 'RESTRICT',
  52 + 'CASCADE'
  53 + );
  54 + $this->addForeignKey(
  55 + 'variant_option_group_excl_lang_alias_id_to_alias_fk',
  56 + 'variant_option_group_excl_lang',
  57 + 'alias_id',
  58 + 'alias',
  59 + 'id',
  60 + 'SET NULL',
  61 + 'CASCADE'
  62 + );
  63 + }
  64 +
  65 + public function safeDown()
  66 + {
  67 + $this->dropForeignKey(
  68 + 'variant_option_group_excl_lang_alias_id_to_alias_fk',
  69 + 'variant_option_group_excl_lang'
  70 + );
  71 + $this->dropForeignKey(
  72 + 'variant_option_group_excl_lang_language_id_to_language_fk',
  73 + 'variant_option_group_excl_lang'
  74 + );
  75 + $this->dropForeignKey(
  76 + 'variant_option_group_excl_lang_variant_option_group_excl_id_to_brand_fk',
  77 + 'variant_option_group_excl_lang'
  78 + );
  79 + $this->dropIndex('variant_option_group_excl_lang_alias_id', 'variant_option_group_excl_lang');
  80 + $this->dropTable('variant_option_group_excl_lang');
  81 + }
  82 + }
... ...
artweb/artbox-catalog/migrations/m170405_000020_product_option_compl.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000020_product_option_compl extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'product_option_compl',
  11 + [
  12 + 'id' => $this->primaryKey(),
  13 + 'product_option_group_compl_id' => $this->integer()
  14 + ->notNull(),
  15 + 'image_id' => $this->integer(),
  16 + 'sort' => $this->integer()
  17 + ->defaultValue(0),
  18 + 'status' => $this->boolean()
  19 + ->defaultValue(true),
  20 + 'created_at' => $this->integer(),
  21 + 'updated_at' => $this->integer(),
  22 + ]
  23 + );
  24 +
  25 + $this->addForeignKey(
  26 + 'product_option_compl_product_option_group_compl_id_to_product_option_group_compl_fk',
  27 + 'product_option_compl',
  28 + 'product_option_group_compl_id',
  29 + 'product_option_group_compl',
  30 + 'id',
  31 + 'CASCADE',
  32 + 'CASCADE'
  33 + );
  34 + }
  35 +
  36 + public function safeDown()
  37 + {
  38 + $this->dropForeignKey(
  39 + 'product_option_compl_product_option_group_compl_id_to_product_option_group_compl_fk',
  40 + 'product_option_compl'
  41 + );
  42 + $this->dropTable('product_option_compl');
  43 + }
  44 + }
... ...
artweb/artbox-catalog/migrations/m170405_000021_product_option_compl_lang.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000021_product_option_compl_lang extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'product_option_compl_lang',
  11 + [
  12 + 'product_option_compl_id' => $this->integer(32)
  13 + ->notNull(),
  14 + 'language_id' => $this->integer(32)
  15 + ->notNull(),
  16 + 'value' => $this->string(255)
  17 + ->notNull(),
  18 + 'alias_id' => $this->integer(),
  19 + ]
  20 + );
  21 + $this->createIndex('product_option_compl_lang_alias_id', 'product_option_compl_lang', 'alias_id', true);
  22 + $this->addPrimaryKey(
  23 + 'product_option_compl_lang_pk',
  24 + 'product_option_compl_lang',
  25 + [
  26 + 'product_option_compl_id',
  27 + 'language_id',
  28 + ]
  29 + );
  30 + $this->addForeignKey(
  31 + 'product_option_compl_lang_product_option_compl_id_to_product_option_compl_fk',
  32 + 'product_option_compl_lang',
  33 + 'product_option_compl_id',
  34 + 'product_option_compl',
  35 + 'id',
  36 + 'CASCADE',
  37 + 'CASCADE'
  38 + );
  39 + $this->addForeignKey(
  40 + 'product_option_compl_lang_language_id_to_language_fk',
  41 + 'product_option_compl_lang',
  42 + 'language_id',
  43 + 'language',
  44 + 'id',
  45 + 'RESTRICT',
  46 + 'CASCADE'
  47 + );
  48 + $this->addForeignKey(
  49 + 'product_option_compl_lang_alias_id_to_alias_fk',
  50 + 'product_option_compl_lang',
  51 + 'alias_id',
  52 + 'alias',
  53 + 'id',
  54 + 'SET NULL',
  55 + 'CASCADE'
  56 + );
  57 + }
  58 +
  59 + public function safeDown()
  60 + {
  61 + $this->dropForeignKey(
  62 + 'product_option_compl_lang_alias_id_to_alias_fk',
  63 + 'product_option_compl_lang'
  64 + );
  65 + $this->dropForeignKey(
  66 + 'product_option_compl_lang_language_id_to_language_fk',
  67 + 'product_option_compl_lang'
  68 + );
  69 + $this->dropForeignKey(
  70 + 'product_option_compl_lang_product_option_compl_id_to_product_option_compl_fk',
  71 + 'product_option_compl_lang'
  72 + );
  73 + $this->dropIndex('product_option_compl_lang_alias_id', 'product_option_compl_lang');
  74 + $this->dropTable('product_option_compl_lang');
  75 + }
  76 + }
... ...
artweb/artbox-catalog/migrations/m170405_000022_product_option_excl.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000022_product_option_excl extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'product_option_excl',
  11 + [
  12 + 'id' => $this->primaryKey(),
  13 + 'product_option_group_excl_id' => $this->integer()
  14 + ->notNull(),
  15 + 'image_id' => $this->integer(),
  16 + 'sort' => $this->integer()
  17 + ->defaultValue(0),
  18 + 'status' => $this->boolean()
  19 + ->defaultValue(true),
  20 + 'created_at' => $this->integer(),
  21 + 'updated_at' => $this->integer(),
  22 + ]
  23 + );
  24 +
  25 + $this->addForeignKey(
  26 + 'product_option_excl_product_option_group_excl_id_to_product_option_group_excl_fk',
  27 + 'product_option_excl',
  28 + 'product_option_group_excl_id',
  29 + 'product_option_group_excl',
  30 + 'id',
  31 + 'CASCADE',
  32 + 'CASCADE'
  33 + );
  34 + }
  35 +
  36 + public function safeDown()
  37 + {
  38 + $this->dropForeignKey(
  39 + 'product_option_excl_product_option_group_excl_id_to_product_option_group_excl_fk',
  40 + 'product_option_excl'
  41 + );
  42 + $this->dropTable('product_option_excl');
  43 + }
  44 + }
... ...
artweb/artbox-catalog/migrations/m170405_000023_product_option_excl_lang.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000023_product_option_excl_lang extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'product_option_excl_lang',
  11 + [
  12 + 'product_option_excl_id' => $this->integer(32)
  13 + ->notNull(),
  14 + 'language_id' => $this->integer(32)
  15 + ->notNull(),
  16 + 'value' => $this->string(255)
  17 + ->notNull(),
  18 + 'alias_id' => $this->integer(),
  19 + ]
  20 + );
  21 + $this->createIndex('product_option_excl_lang_alias_id', 'product_option_excl_lang', 'alias_id', true);
  22 + $this->addPrimaryKey(
  23 + 'product_option_excl_lang_pk',
  24 + 'product_option_excl_lang',
  25 + [
  26 + 'product_option_excl_id',
  27 + 'language_id',
  28 + ]
  29 + );
  30 + $this->addForeignKey(
  31 + 'product_option_excl_lang_product_option_excl_id_to_product_option_excl_fk',
  32 + 'product_option_excl_lang',
  33 + 'product_option_excl_id',
  34 + 'product_option_excl',
  35 + 'id',
  36 + 'CASCADE',
  37 + 'CASCADE'
  38 + );
  39 + $this->addForeignKey(
  40 + 'product_option_excl_lang_language_id_to_language_fk',
  41 + 'product_option_excl_lang',
  42 + 'language_id',
  43 + 'language',
  44 + 'id',
  45 + 'RESTRICT',
  46 + 'CASCADE'
  47 + );
  48 + $this->addForeignKey(
  49 + 'product_option_excl_lang_alias_id_to_alias_fk',
  50 + 'product_option_excl_lang',
  51 + 'alias_id',
  52 + 'alias',
  53 + 'id',
  54 + 'SET NULL',
  55 + 'CASCADE'
  56 + );
  57 + }
  58 +
  59 + public function safeDown()
  60 + {
  61 + $this->dropForeignKey(
  62 + 'product_option_excl_lang_alias_id_to_alias_fk',
  63 + 'product_option_excl_lang'
  64 + );
  65 + $this->dropForeignKey(
  66 + 'product_option_excl_lang_language_id_to_language_fk',
  67 + 'product_option_excl_lang'
  68 + );
  69 + $this->dropForeignKey(
  70 + 'product_option_excl_lang_product_option_excl_id_to_product_option_excl_fk',
  71 + 'product_option_excl_lang'
  72 + );
  73 + $this->dropIndex('product_option_excl_lang_alias_id', 'product_option_excl_lang');
  74 + $this->dropTable('product_option_excl_lang');
  75 + }
  76 + }
... ...
artweb/artbox-catalog/migrations/m170405_000024_variant_option_compl.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000024_variant_option_compl extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'variant_option_compl',
  11 + [
  12 + 'id' => $this->primaryKey(),
  13 + 'variant_option_group_compl_id' => $this->integer()
  14 + ->notNull(),
  15 + 'image_id' => $this->integer(),
  16 + 'sort' => $this->integer()
  17 + ->defaultValue(0),
  18 + 'status' => $this->boolean()
  19 + ->defaultValue(true),
  20 + 'created_at' => $this->integer(),
  21 + 'updated_at' => $this->integer(),
  22 + ]
  23 + );
  24 +
  25 + $this->addForeignKey(
  26 + 'variant_option_compl_variant_option_group_compl_id_to_variant_option_group_compl_fk',
  27 + 'variant_option_compl',
  28 + 'variant_option_group_compl_id',
  29 + 'variant_option_group_compl',
  30 + 'id',
  31 + 'CASCADE',
  32 + 'CASCADE'
  33 + );
  34 + }
  35 +
  36 + public function safeDown()
  37 + {
  38 + $this->dropForeignKey(
  39 + 'variant_option_compl_variant_option_group_compl_id_to_variant_option_group_compl_fk',
  40 + 'variant_option_compl'
  41 + );
  42 + $this->dropTable('variant_option_compl');
  43 + }
  44 + }
... ...
artweb/artbox-catalog/migrations/m170405_000025_variant_option_compl_lang.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000025_variant_option_compl_lang extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'variant_option_compl_lang',
  11 + [
  12 + 'variant_option_compl_id' => $this->integer(32)
  13 + ->notNull(),
  14 + 'language_id' => $this->integer(32)
  15 + ->notNull(),
  16 + 'value' => $this->string(255)
  17 + ->notNull(),
  18 + 'alias_id' => $this->integer(),
  19 + ]
  20 + );
  21 + $this->createIndex('variant_option_compl_lang_alias_id', 'variant_option_compl_lang', 'alias_id', true);
  22 + $this->addPrimaryKey(
  23 + 'variant_option_compl_lang_pk',
  24 + 'variant_option_compl_lang',
  25 + [
  26 + 'variant_option_compl_id',
  27 + 'language_id',
  28 + ]
  29 + );
  30 + $this->addForeignKey(
  31 + 'variant_option_compl_lang_variant_option_compl_id_to_variant_option_compl_fk',
  32 + 'variant_option_compl_lang',
  33 + 'variant_option_compl_id',
  34 + 'variant_option_compl',
  35 + 'id',
  36 + 'CASCADE',
  37 + 'CASCADE'
  38 + );
  39 + $this->addForeignKey(
  40 + 'variant_option_compl_lang_language_id_to_language_fk',
  41 + 'variant_option_compl_lang',
  42 + 'language_id',
  43 + 'language',
  44 + 'id',
  45 + 'RESTRICT',
  46 + 'CASCADE'
  47 + );
  48 + $this->addForeignKey(
  49 + 'variant_option_compl_lang_alias_id_to_alias_fk',
  50 + 'variant_option_compl_lang',
  51 + 'alias_id',
  52 + 'alias',
  53 + 'id',
  54 + 'SET NULL',
  55 + 'CASCADE'
  56 + );
  57 + }
  58 +
  59 + public function safeDown()
  60 + {
  61 + $this->dropForeignKey(
  62 + 'variant_option_compl_lang_alias_id_to_alias_fk',
  63 + 'variant_option_compl_lang'
  64 + );
  65 + $this->dropForeignKey(
  66 + 'variant_option_compl_lang_language_id_to_language_fk',
  67 + 'variant_option_compl_lang'
  68 + );
  69 + $this->dropForeignKey(
  70 + 'variant_option_compl_lang_variant_option_compl_id_to_variant_option_compl_fk',
  71 + 'variant_option_compl_lang'
  72 + );
  73 + $this->dropIndex('variant_option_compl_lang_alias_id', 'variant_option_compl_lang');
  74 + $this->dropTable('variant_option_compl_lang');
  75 + }
  76 + }
... ...
artweb/artbox-catalog/migrations/m170405_000026_variant_option_excl.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000026_variant_option_excl extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'variant_option_excl',
  11 + [
  12 + 'id' => $this->primaryKey(),
  13 + 'variant_option_group_excl_id' => $this->integer()
  14 + ->notNull(),
  15 + 'image_id' => $this->integer(),
  16 + 'sort' => $this->integer()
  17 + ->defaultValue(0),
  18 + 'status' => $this->boolean()
  19 + ->defaultValue(true),
  20 + 'created_at' => $this->integer(),
  21 + 'updated_at' => $this->integer(),
  22 + ]
  23 + );
  24 +
  25 + $this->addForeignKey(
  26 + 'variant_option_excl_variant_option_group_excl_id_to_variant_option_group_excl_fk',
  27 + 'variant_option_excl',
  28 + 'variant_option_group_excl_id',
  29 + 'variant_option_group_excl',
  30 + 'id',
  31 + 'CASCADE',
  32 + 'CASCADE'
  33 + );
  34 + }
  35 +
  36 + public function safeDown()
  37 + {
  38 + $this->dropForeignKey(
  39 + 'variant_option_excl_variant_option_group_excl_id_to_variant_option_group_excl_fk',
  40 + 'variant_option_excl'
  41 + );
  42 + $this->dropTable('variant_option_excl');
  43 + }
  44 + }
... ...
artweb/artbox-catalog/migrations/m170405_000027_variant_option_excl_lang.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000027_variant_option_excl_lang extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'variant_option_excl_lang',
  11 + [
  12 + 'variant_option_excl_id' => $this->integer(32)
  13 + ->notNull(),
  14 + 'language_id' => $this->integer(32)
  15 + ->notNull(),
  16 + 'value' => $this->string(255)
  17 + ->notNull(),
  18 + 'alias_id' => $this->integer(),
  19 + ]
  20 + );
  21 + $this->createIndex('variant_option_excl_lang_alias_id', 'variant_option_excl_lang', 'alias_id', true);
  22 + $this->addPrimaryKey(
  23 + 'variant_option_excl_lang_pk',
  24 + 'variant_option_excl_lang',
  25 + [
  26 + 'variant_option_excl_id',
  27 + 'language_id',
  28 + ]
  29 + );
  30 + $this->addForeignKey(
  31 + 'variant_option_excl_lang_variant_option_excl_id_to_variant_option_excl_fk',
  32 + 'variant_option_excl_lang',
  33 + 'variant_option_excl_id',
  34 + 'variant_option_excl',
  35 + 'id',
  36 + 'CASCADE',
  37 + 'CASCADE'
  38 + );
  39 + $this->addForeignKey(
  40 + 'variant_option_excl_lang_language_id_to_language_fk',
  41 + 'variant_option_excl_lang',
  42 + 'language_id',
  43 + 'language',
  44 + 'id',
  45 + 'RESTRICT',
  46 + 'CASCADE'
  47 + );
  48 + $this->addForeignKey(
  49 + 'variant_option_excl_lang_alias_id_to_alias_fk',
  50 + 'variant_option_excl_lang',
  51 + 'alias_id',
  52 + 'alias',
  53 + 'id',
  54 + 'SET NULL',
  55 + 'CASCADE'
  56 + );
  57 + }
  58 +
  59 + public function safeDown()
  60 + {
  61 + $this->dropForeignKey(
  62 + 'variant_option_excl_lang_alias_id_to_alias_fk',
  63 + 'variant_option_excl_lang'
  64 + );
  65 + $this->dropForeignKey(
  66 + 'variant_option_excl_lang_language_id_to_language_fk',
  67 + 'variant_option_excl_lang'
  68 + );
  69 + $this->dropForeignKey(
  70 + 'variant_option_excl_lang_variant_option_excl_id_to_variant_option_excl_fk',
  71 + 'variant_option_excl_lang'
  72 + );
  73 + $this->dropIndex('variant_option_excl_lang_alias_id', 'variant_option_excl_lang');
  74 + $this->dropTable('variant_option_excl_lang');
  75 + }
  76 + }
... ...
artweb/artbox-catalog/migrations/m170405_000028_product_to_product_option_compl.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000028_product_to_product_option_compl extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'product_to_product_option_compl',
  11 + [
  12 + 'product_id' => $this->integer()
  13 + ->notNull(),
  14 + 'product_option_compl_id' => $this->integer()
  15 + ->notNull(),
  16 + ]
  17 + );
  18 +
  19 + $this->addPrimaryKey(
  20 + 'product_to_product_option_compl_pk',
  21 + 'product_to_product_option_compl',
  22 + [
  23 + 'product_id',
  24 + 'product_option_compl_id',
  25 + ]
  26 + );
  27 +
  28 + $this->addForeignKey(
  29 + 'product_to_product_option_compl_product_id_to_product_fk',
  30 + 'product_to_product_option_compl',
  31 + 'product_id',
  32 + 'product',
  33 + 'id',
  34 + 'CASCADE',
  35 + 'CASCADE'
  36 + );
  37 +
  38 + $this->addForeignKey(
  39 + 'product_to_product_option_compl_product_to_product_option_compl_id_to_category_fk',
  40 + 'product_to_product_option_compl',
  41 + 'product_option_compl_id',
  42 + 'product_option_compl',
  43 + 'id',
  44 + 'CASCADE',
  45 + 'CASCADE'
  46 + );
  47 + }
  48 +
  49 + public function safeDown()
  50 + {
  51 + $this->dropForeignKey(
  52 + 'product_to_product_option_compl_product_id_to_product_fk',
  53 + 'product_to_product_option_compl'
  54 + );
  55 + $this->dropForeignKey(
  56 + 'product_to_product_option_compl_product_to_product_option_compl_id_to_category_fk',
  57 + 'product_to_product_option_compl'
  58 + );
  59 + $this->dropTable('product_to_product_option_compl');
  60 + }
  61 + }
... ...
artweb/artbox-catalog/migrations/m170405_000029_product_to_product_option_excl.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000029_product_to_product_option_excl extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'product_to_product_option_excl',
  11 + [
  12 + 'product_id' => $this->integer()
  13 + ->notNull(),
  14 + 'product_option_excl_id' => $this->integer()
  15 + ->notNull(),
  16 + ]
  17 + );
  18 +
  19 + $this->addPrimaryKey(
  20 + 'product_to_product_option_excl_pk',
  21 + 'product_to_product_option_excl',
  22 + [
  23 + 'product_id',
  24 + 'product_option_excl_id',
  25 + ]
  26 + );
  27 +
  28 + $this->addForeignKey(
  29 + 'product_to_product_option_excl_product_id_to_product_fk',
  30 + 'product_to_product_option_excl',
  31 + 'product_id',
  32 + 'product',
  33 + 'id',
  34 + 'CASCADE',
  35 + 'CASCADE'
  36 + );
  37 +
  38 + $this->addForeignKey(
  39 + 'product_to_product_option_excl_product_to_product_option_excl_id_to_category_fk',
  40 + 'product_to_product_option_excl',
  41 + 'product_option_excl_id',
  42 + 'product_option_excl',
  43 + 'id',
  44 + 'CASCADE',
  45 + 'CASCADE'
  46 + );
  47 + }
  48 +
  49 + public function safeDown()
  50 + {
  51 + $this->dropForeignKey(
  52 + 'product_to_product_option_excl_product_id_to_product_fk',
  53 + 'product_to_product_option_excl'
  54 + );
  55 + $this->dropForeignKey(
  56 + 'product_to_product_option_excl_product_to_product_option_excl_id_to_category_fk',
  57 + 'product_to_product_option_excl'
  58 + );
  59 + $this->dropTable('product_to_product_option_excl');
  60 + }
  61 + }
... ...
artweb/artbox-catalog/migrations/m170405_000030_variant_to_variant_option_compl.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000030_variant_to_variant_option_compl extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'variant_to_variant_option_compl',
  11 + [
  12 + 'variant_id' => $this->integer()
  13 + ->notNull(),
  14 + 'variant_option_compl_id' => $this->integer()
  15 + ->notNull(),
  16 + ]
  17 + );
  18 +
  19 + $this->addPrimaryKey(
  20 + 'variant_to_variant_option_compl_pk',
  21 + 'variant_to_variant_option_compl',
  22 + [
  23 + 'variant_id',
  24 + 'variant_option_compl_id',
  25 + ]
  26 + );
  27 +
  28 + $this->addForeignKey(
  29 + 'variant_to_variant_option_compl_variant_id_to_variant_fk',
  30 + 'variant_to_variant_option_compl',
  31 + 'variant_id',
  32 + 'variant',
  33 + 'id',
  34 + 'CASCADE',
  35 + 'CASCADE'
  36 + );
  37 +
  38 + $this->addForeignKey(
  39 + 'variant_to_variant_option_compl_variant_to_variant_option_compl_id_to_category_fk',
  40 + 'variant_to_variant_option_compl',
  41 + 'variant_option_compl_id',
  42 + 'variant_option_compl',
  43 + 'id',
  44 + 'CASCADE',
  45 + 'CASCADE'
  46 + );
  47 + }
  48 +
  49 + public function safeDown()
  50 + {
  51 + $this->dropForeignKey(
  52 + 'variant_to_variant_option_compl_variant_id_to_variant_fk',
  53 + 'variant_to_variant_option_compl'
  54 + );
  55 + $this->dropForeignKey(
  56 + 'variant_to_variant_option_compl_variant_to_variant_option_compl_id_to_category_fk',
  57 + 'variant_to_variant_option_compl'
  58 + );
  59 + $this->dropTable('variant_to_variant_option_compl');
  60 + }
  61 + }
... ...
artweb/artbox-catalog/migrations/m170405_000031_variant_to_variant_option_excl.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000031_variant_to_variant_option_excl extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'variant_to_variant_option_excl',
  11 + [
  12 + 'variant_id' => $this->integer()
  13 + ->notNull(),
  14 + 'variant_option_excl_id' => $this->integer()
  15 + ->notNull(),
  16 + ]
  17 + );
  18 +
  19 + $this->addPrimaryKey(
  20 + 'variant_to_variant_option_excl_pk',
  21 + 'variant_to_variant_option_excl',
  22 + [
  23 + 'variant_id',
  24 + 'variant_option_excl_id',
  25 + ]
  26 + );
  27 +
  28 + $this->addForeignKey(
  29 + 'variant_to_variant_option_excl_variant_id_to_variant_fk',
  30 + 'variant_to_variant_option_excl',
  31 + 'variant_id',
  32 + 'variant',
  33 + 'id',
  34 + 'CASCADE',
  35 + 'CASCADE'
  36 + );
  37 +
  38 + $this->addForeignKey(
  39 + 'variant_to_variant_option_excl_variant_to_variant_option_excl_id_to_category_fk',
  40 + 'variant_to_variant_option_excl',
  41 + 'variant_option_excl_id',
  42 + 'variant_option_excl',
  43 + 'id',
  44 + 'CASCADE',
  45 + 'CASCADE'
  46 + );
  47 + }
  48 +
  49 + public function safeDown()
  50 + {
  51 + $this->dropForeignKey(
  52 + 'variant_to_variant_option_excl_variant_id_to_variant_fk',
  53 + 'variant_to_variant_option_excl'
  54 + );
  55 + $this->dropForeignKey(
  56 + 'variant_to_variant_option_excl_variant_to_variant_option_excl_id_to_category_fk',
  57 + 'variant_to_variant_option_excl'
  58 + );
  59 + $this->dropTable('variant_to_variant_option_excl');
  60 + }
  61 + }
... ...
artweb/artbox-catalog/migrations/m170405_000032_product_option_compl_to_category.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000032_product_option_compl_to_category extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'product_option_compl_to_category',
  11 + [
  12 + 'category_id' => $this->integer()
  13 + ->notNull(),
  14 + 'product_option_compl_id' => $this->integer()
  15 + ->notNull(),
  16 + ]
  17 + );
  18 +
  19 + $this->addPrimaryKey(
  20 + 'product_option_compl_to_category_pk',
  21 + 'product_option_compl_to_category',
  22 + [
  23 + 'category_id',
  24 + 'product_option_compl_id',
  25 + ]
  26 + );
  27 +
  28 + $this->addForeignKey(
  29 + 'product_option_compl_to_category_category_id_to_category_fk',
  30 + 'product_option_compl_to_category',
  31 + 'category_id',
  32 + 'category',
  33 + 'id',
  34 + 'CASCADE',
  35 + 'CASCADE'
  36 + );
  37 +
  38 + $this->addForeignKey(
  39 + 'product_option_compl_to_category_product_option_compl_id_to_product_option_compl_fk',
  40 + 'product_option_compl_to_category',
  41 + 'product_option_compl_id',
  42 + 'product_option_compl',
  43 + 'id',
  44 + 'CASCADE',
  45 + 'CASCADE'
  46 + );
  47 + }
  48 +
  49 + public function safeDown()
  50 + {
  51 + $this->dropForeignKey(
  52 + 'product_option_compl_to_category_category_id_to_category_fk',
  53 + 'product_option_compl_to_category'
  54 + );
  55 + $this->dropForeignKey(
  56 + 'product_option_compl_to_category_product_option_compl_id_to_product_option_compl_fk',
  57 + 'product_option_compl_to_category'
  58 + );
  59 + $this->dropTable('product_option_compl_to_category');
  60 + }
  61 + }
... ...
artweb/artbox-catalog/migrations/m170405_000033_product_option_excll_to_category.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000033_product_option_excll_to_category extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'product_option_excl_to_category',
  11 + [
  12 + 'category_id' => $this->integer()
  13 + ->notNull(),
  14 + 'product_option_excl_id' => $this->integer()
  15 + ->notNull(),
  16 + ]
  17 + );
  18 +
  19 + $this->addPrimaryKey(
  20 + 'product_option_excl_to_category_pk',
  21 + 'product_option_excl_to_category',
  22 + [
  23 + 'category_id',
  24 + 'product_option_excl_id',
  25 + ]
  26 + );
  27 +
  28 + $this->addForeignKey(
  29 + 'product_option_excl_to_category_category_id_to_category_fk',
  30 + 'product_option_excl_to_category',
  31 + 'category_id',
  32 + 'category',
  33 + 'id',
  34 + 'CASCADE',
  35 + 'CASCADE'
  36 + );
  37 +
  38 + $this->addForeignKey(
  39 + 'product_option_excl_to_category_product_option_excl_id_to_product_option_excl_fk',
  40 + 'product_option_excl_to_category',
  41 + 'product_option_excl_id',
  42 + 'product_option_excl',
  43 + 'id',
  44 + 'CASCADE',
  45 + 'CASCADE'
  46 + );
  47 + }
  48 +
  49 + public function safeDown()
  50 + {
  51 + $this->dropForeignKey(
  52 + 'product_option_excl_to_category_category_id_to_category_fk',
  53 + 'product_option_excl_to_category'
  54 + );
  55 + $this->dropForeignKey(
  56 + 'product_option_excl_to_category_product_option_excl_id_to_product_option_excl_fk',
  57 + 'product_option_excl_to_category'
  58 + );
  59 + $this->dropTable('product_option_excl_to_category');
  60 + }
  61 + }
... ...
artweb/artbox-catalog/migrations/m170405_000034_variant_option_compl_to_category.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000034_variant_option_compl_to_category extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'variant_option_compl_to_category',
  11 + [
  12 + 'category_id' => $this->integer()
  13 + ->notNull(),
  14 + 'variant_option_compl_id' => $this->integer()
  15 + ->notNull(),
  16 + ]
  17 + );
  18 +
  19 + $this->addPrimaryKey(
  20 + 'variant_option_compl_to_category_pk',
  21 + 'variant_option_compl_to_category',
  22 + [
  23 + 'category_id',
  24 + 'variant_option_compl_id',
  25 + ]
  26 + );
  27 +
  28 + $this->addForeignKey(
  29 + 'variant_option_compl_to_category_category_id_to_category_fk',
  30 + 'variant_option_compl_to_category',
  31 + 'category_id',
  32 + 'category',
  33 + 'id',
  34 + 'CASCADE',
  35 + 'CASCADE'
  36 + );
  37 +
  38 + $this->addForeignKey(
  39 + 'variant_option_compl_to_category_variant_option_compl_id_to_variant_option_compl_fk',
  40 + 'variant_option_compl_to_category',
  41 + 'variant_option_compl_id',
  42 + 'variant_option_compl',
  43 + 'id',
  44 + 'CASCADE',
  45 + 'CASCADE'
  46 + );
  47 + }
  48 +
  49 + public function safeDown()
  50 + {
  51 + $this->dropForeignKey(
  52 + 'variant_option_compl_to_category_category_id_to_category_fk',
  53 + 'variant_option_compl_to_category'
  54 + );
  55 + $this->dropForeignKey(
  56 + 'variant_option_compl_to_category_variant_option_compl_id_to_variant_option_compl_fk',
  57 + 'variant_option_compl_to_category'
  58 + );
  59 + $this->dropTable('variant_option_compl_to_category');
  60 + }
  61 + }
... ...
artweb/artbox-catalog/migrations/m170405_000035_variant_option_excl_to_category.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170405_000035_variant_option_excl_to_category extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->createTable(
  10 + 'variant_option_excl_to_category',
  11 + [
  12 + 'category_id' => $this->integer()
  13 + ->notNull(),
  14 + 'variant_option_excl_id' => $this->integer()
  15 + ->notNull(),
  16 + ]
  17 + );
  18 +
  19 + $this->addPrimaryKey(
  20 + 'variant_option_excl_to_category_pk',
  21 + 'variant_option_excl_to_category',
  22 + [
  23 + 'category_id',
  24 + 'variant_option_excl_id',
  25 + ]
  26 + );
  27 +
  28 + $this->addForeignKey(
  29 + 'variant_option_excl_to_category_category_id_to_category_fk',
  30 + 'variant_option_excl_to_category',
  31 + 'category_id',
  32 + 'category',
  33 + 'id',
  34 + 'CASCADE',
  35 + 'CASCADE'
  36 + );
  37 +
  38 + $this->addForeignKey(
  39 + 'variant_option_excl_to_category_variant_option_excl_id_to_variant_option_excl_fk',
  40 + 'variant_option_excl_to_category',
  41 + 'variant_option_excl_id',
  42 + 'variant_option_excl',
  43 + 'id',
  44 + 'CASCADE',
  45 + 'CASCADE'
  46 + );
  47 + }
  48 +
  49 + public function safeDown()
  50 + {
  51 + $this->dropForeignKey(
  52 + 'variant_option_excl_to_category_category_id_to_category_fk',
  53 + 'variant_option_excl_to_category'
  54 + );
  55 + $this->dropForeignKey(
  56 + 'variant_option_excl_to_category_variant_option_excl_id_to_variant_option_excl_fk',
  57 + 'variant_option_excl_to_category'
  58 + );
  59 + $this->dropTable('variant_option_excl_to_category');
  60 + }
  61 + }
... ...
artweb/artbox-catalog/migrations/m170410_090534_change_category_link_from_option_to_group.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170410_090534_change_category_link_from_option_to_group extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->dropTable('product_option_compl_to_category');
  10 + $this->dropTable('product_option_excl_to_category');
  11 + $this->dropTable('variant_option_compl_to_category');
  12 + $this->dropTable('variant_option_excl_to_category');
  13 +
  14 + $this->createTable(
  15 + 'product_option_group_compl_to_category',
  16 + [
  17 + 'product_option_group_compl_id' => $this->integer()
  18 + ->notNull(),
  19 + 'category_id' => $this->integer()
  20 + ->notNull(),
  21 + ]
  22 + );
  23 +
  24 + $this->addPrimaryKey(
  25 + 'product_option_group_compl_to_category_pk',
  26 + 'product_option_group_compl_to_category',
  27 + [
  28 + 'category_id',
  29 + 'product_option_group_compl_id',
  30 + ]
  31 + );
  32 +
  33 + $this->addForeignKey(
  34 + 'product_option_group_compl_to_category_category_id_to_category_fk',
  35 + 'product_option_group_compl_to_category',
  36 + 'category_id',
  37 + 'category',
  38 + 'id',
  39 + 'CASCADE',
  40 + 'CASCADE'
  41 + );
  42 +
  43 + $this->addForeignKey(
  44 + 'product_option_group_compl_to_category_product_option_group_compl_id_to_product_option_compl_fk',
  45 + 'product_option_group_compl_to_category',
  46 + 'product_option_group_compl_id',
  47 + 'product_option_group_compl',
  48 + 'id',
  49 + 'CASCADE',
  50 + 'CASCADE'
  51 + );
  52 +
  53 + $this->createTable(
  54 + 'product_option_group_excl_to_category',
  55 + [
  56 + 'product_option_group_excl_id' => $this->integer()
  57 + ->notNull(),
  58 + 'category_id' => $this->integer()
  59 + ->notNull(),
  60 + ]
  61 + );
  62 +
  63 + $this->addPrimaryKey(
  64 + 'product_option_group_excl_to_category_pk',
  65 + 'product_option_group_excl_to_category',
  66 + [
  67 + 'category_id',
  68 + 'product_option_group_excl_id',
  69 + ]
  70 + );
  71 +
  72 + $this->addForeignKey(
  73 + 'product_option_group_excl_to_category_category_id_to_category_fk',
  74 + 'product_option_group_excl_to_category',
  75 + 'category_id',
  76 + 'category',
  77 + 'id',
  78 + 'CASCADE',
  79 + 'CASCADE'
  80 + );
  81 +
  82 + $this->addForeignKey(
  83 + 'product_option_group_excl_to_category_product_option_group_excl_id_to_product_option_excl_fk',
  84 + 'product_option_group_excl_to_category',
  85 + 'product_option_group_excl_id',
  86 + 'product_option_group_excl',
  87 + 'id',
  88 + 'CASCADE',
  89 + 'CASCADE'
  90 + );
  91 +
  92 + $this->createTable(
  93 + 'variant_option_group_compl_to_category',
  94 + [
  95 + 'variant_option_group_compl_id' => $this->integer()
  96 + ->notNull(),
  97 + 'category_id' => $this->integer()
  98 + ->notNull(),
  99 + ]
  100 + );
  101 +
  102 + $this->addPrimaryKey(
  103 + 'variant_option_group_compl_to_category_pk',
  104 + 'variant_option_group_compl_to_category',
  105 + [
  106 + 'category_id',
  107 + 'variant_option_group_compl_id',
  108 + ]
  109 + );
  110 +
  111 + $this->addForeignKey(
  112 + 'variant_option_group_compl_to_category_category_id_to_category_fk',
  113 + 'variant_option_group_compl_to_category',
  114 + 'category_id',
  115 + 'category',
  116 + 'id',
  117 + 'CASCADE',
  118 + 'CASCADE'
  119 + );
  120 +
  121 + $this->addForeignKey(
  122 + 'variant_option_group_compl_to_category_variant_option_group_compl_id_to_variant_option_compl_fk',
  123 + 'variant_option_group_compl_to_category',
  124 + 'variant_option_group_compl_id',
  125 + 'variant_option_group_compl',
  126 + 'id',
  127 + 'CASCADE',
  128 + 'CASCADE'
  129 + );
  130 +
  131 + $this->createTable(
  132 + 'variant_option_group_excl_to_category',
  133 + [
  134 + 'variant_option_group_excl_id' => $this->integer()
  135 + ->notNull(),
  136 + 'category_id' => $this->integer()
  137 + ->notNull(),
  138 + ]
  139 + );
  140 +
  141 + $this->addPrimaryKey(
  142 + 'variant_option_group_excl_to_category_pk',
  143 + 'variant_option_group_excl_to_category',
  144 + [
  145 + 'category_id',
  146 + 'variant_option_group_excl_id',
  147 + ]
  148 + );
  149 +
  150 + $this->addForeignKey(
  151 + 'variant_option_group_excl_to_category_category_id_to_category_fk',
  152 + 'variant_option_group_excl_to_category',
  153 + 'category_id',
  154 + 'category',
  155 + 'id',
  156 + 'CASCADE',
  157 + 'CASCADE'
  158 + );
  159 +
  160 + $this->addForeignKey(
  161 + 'variant_option_group_excl_to_category_variant_option_group_excl_id_to_variant_option_excl_fk',
  162 + 'variant_option_group_excl_to_category',
  163 + 'variant_option_group_excl_id',
  164 + 'variant_option_group_excl',
  165 + 'id',
  166 + 'CASCADE',
  167 + 'CASCADE'
  168 + );
  169 + }
  170 +
  171 + public function safeDown()
  172 + {
  173 + $this->dropTable('product_option_group_compl_to_category');
  174 +
  175 + $this->dropTable('product_option_group_excl_to_category');
  176 +
  177 + $this->dropTable('variant_option_group_compl_to_category');
  178 +
  179 + $this->dropTable('variant_option_group_excl_to_category');
  180 +
  181 + $this->createTable(
  182 + 'product_option_compl_to_category',
  183 + [
  184 + 'category_id' => $this->integer()
  185 + ->notNull(),
  186 + 'product_option_compl_id' => $this->integer()
  187 + ->notNull(),
  188 + ]
  189 + );
  190 +
  191 + $this->addPrimaryKey(
  192 + 'product_option_compl_to_category_pk',
  193 + 'product_option_compl_to_category',
  194 + [
  195 + 'category_id',
  196 + 'product_option_compl_id',
  197 + ]
  198 + );
  199 +
  200 + $this->addForeignKey(
  201 + 'product_option_compl_to_category_category_id_to_category_fk',
  202 + 'product_option_compl_to_category',
  203 + 'category_id',
  204 + 'category',
  205 + 'id',
  206 + 'CASCADE',
  207 + 'CASCADE'
  208 + );
  209 +
  210 + $this->addForeignKey(
  211 + 'product_option_compl_to_category_product_option_compl_id_to_product_option_compl_fk',
  212 + 'product_option_compl_to_category',
  213 + 'product_option_compl_id',
  214 + 'product_option_compl',
  215 + 'id',
  216 + 'CASCADE',
  217 + 'CASCADE'
  218 + );
  219 +
  220 + $this->createTable(
  221 + 'product_option_excl_to_category',
  222 + [
  223 + 'category_id' => $this->integer()
  224 + ->notNull(),
  225 + 'product_option_excl_id' => $this->integer()
  226 + ->notNull(),
  227 + ]
  228 + );
  229 +
  230 + $this->addPrimaryKey(
  231 + 'product_option_excl_to_category_pk',
  232 + 'product_option_excl_to_category',
  233 + [
  234 + 'category_id',
  235 + 'product_option_excl_id',
  236 + ]
  237 + );
  238 +
  239 + $this->addForeignKey(
  240 + 'product_option_excl_to_category_category_id_to_category_fk',
  241 + 'product_option_excl_to_category',
  242 + 'category_id',
  243 + 'category',
  244 + 'id',
  245 + 'CASCADE',
  246 + 'CASCADE'
  247 + );
  248 +
  249 + $this->addForeignKey(
  250 + 'product_option_excl_to_category_product_option_excl_id_to_product_option_excl_fk',
  251 + 'product_option_excl_to_category',
  252 + 'product_option_excl_id',
  253 + 'product_option_excl',
  254 + 'id',
  255 + 'CASCADE',
  256 + 'CASCADE'
  257 + );
  258 +
  259 + $this->createTable(
  260 + 'variant_option_compl_to_category',
  261 + [
  262 + 'category_id' => $this->integer()
  263 + ->notNull(),
  264 + 'variant_option_compl_id' => $this->integer()
  265 + ->notNull(),
  266 + ]
  267 + );
  268 +
  269 + $this->addPrimaryKey(
  270 + 'variant_option_compl_to_category_pk',
  271 + 'variant_option_compl_to_category',
  272 + [
  273 + 'category_id',
  274 + 'variant_option_compl_id',
  275 + ]
  276 + );
  277 +
  278 + $this->addForeignKey(
  279 + 'variant_option_compl_to_category_category_id_to_category_fk',
  280 + 'variant_option_compl_to_category',
  281 + 'category_id',
  282 + 'category',
  283 + 'id',
  284 + 'CASCADE',
  285 + 'CASCADE'
  286 + );
  287 +
  288 + $this->addForeignKey(
  289 + 'variant_option_compl_to_category_variant_option_compl_id_to_variant_option_compl_fk',
  290 + 'variant_option_compl_to_category',
  291 + 'variant_option_compl_id',
  292 + 'variant_option_compl',
  293 + 'id',
  294 + 'CASCADE',
  295 + 'CASCADE'
  296 + );
  297 +
  298 + $this->createTable(
  299 + 'variant_option_excl_to_category',
  300 + [
  301 + 'category_id' => $this->integer()
  302 + ->notNull(),
  303 + 'variant_option_excl_id' => $this->integer()
  304 + ->notNull(),
  305 + ]
  306 + );
  307 +
  308 + $this->addPrimaryKey(
  309 + 'variant_option_excl_to_category_pk',
  310 + 'variant_option_excl_to_category',
  311 + [
  312 + 'category_id',
  313 + 'variant_option_excl_id',
  314 + ]
  315 + );
  316 +
  317 + $this->addForeignKey(
  318 + 'variant_option_excl_to_category_category_id_to_category_fk',
  319 + 'variant_option_excl_to_category',
  320 + 'category_id',
  321 + 'category',
  322 + 'id',
  323 + 'CASCADE',
  324 + 'CASCADE'
  325 + );
  326 +
  327 + $this->addForeignKey(
  328 + 'variant_option_excl_to_category_variant_option_excl_id_to_variant_option_excl_fk',
  329 + 'variant_option_excl_to_category',
  330 + 'variant_option_excl_id',
  331 + 'variant_option_excl',
  332 + 'id',
  333 + 'CASCADE',
  334 + 'CASCADE'
  335 + );
  336 + }
  337 + }
... ...
artweb/artbox-catalog/migrations/m170426_074728_add_main_images_to_catalog.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170426_074728_add_main_images_to_catalog extends Migration
  6 + {
  7 + public function up()
  8 + {
  9 + $this->addColumn('variant', 'image_id', $this->integer());
  10 +
  11 + $this->addForeignKey('image_fk', 'variant', 'image_id', 'ImageManager', 'id', 'CASCADE', 'CASCADE');
  12 +
  13 + $this->addColumn('product', 'image_id', $this->integer());
  14 +
  15 + $this->addForeignKey('image_fk', 'product', 'image_id', 'ImageManager', 'id', 'CASCADE', 'CASCADE');
  16 + }
  17 +
  18 + public function down()
  19 + {
  20 + $this->dropForeignKey('image_fk', 'product');
  21 +
  22 + $this->dropColumn('product', 'image_id');
  23 +
  24 + $this->dropForeignKey('image_fk', 'variant');
  25 +
  26 + $this->dropColumn('variant', 'image_id');
  27 + }
  28 + }
... ...
artweb/artbox-catalog/migrations/m170428_143235_create_import_table.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + /**
  6 + * Handles the creation of table `import`.
  7 + */
  8 + class m170428_143235_create_import_table extends Migration
  9 + {
  10 + /**
  11 + * @inheritdoc
  12 + */
  13 + public function up()
  14 + {
  15 + $this->createTable(
  16 + 'import',
  17 + [
  18 + 'category_name' => $this->string(),
  19 + 'brand_name' => $this->string(),
  20 + 'product_name' => $this->string(),
  21 + 'sku' => $this->string(),
  22 + 'price' => $this->float(),
  23 + 'price_old' => $this->float(),
  24 + 'mask' => $this->integer(),
  25 + 'image_link' => $this->string(),
  26 + 'image_name' => $this->string(),
  27 + 'video' => $this->string(),
  28 + 'stock' => $this->integer(),
  29 + 'characteristics' => $this->text(),
  30 + ]
  31 + );
  32 + }
  33 +
  34 + /**
  35 + * @inheritdoc
  36 + */
  37 + public function down()
  38 + {
  39 + $this->dropTable('import');
  40 + }
  41 + }
... ...
artweb/artbox-catalog/migrations/m170518_134754_new_import_table.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170518_134754_new_import_table extends Migration
  6 + {
  7 + /**
  8 + * @inheritdoc
  9 + */
  10 + public function up()
  11 + {
  12 + $this->dropTable('import');
  13 + $this->createTable(
  14 + 'import',
  15 + [
  16 + 'category_name' => $this->string(),
  17 + 'brand_name' => $this->string(),
  18 + 'product_name' => $this->string(),
  19 + 'sku' => $this->string(),
  20 + 'price' => $this->float(),
  21 + 'price_old' => $this->float(),
  22 + 'mask' => $this->integer(),
  23 + 'image_link' => $this->string(),
  24 + 'image_name' => $this->string(),
  25 + 'video' => $this->string(),
  26 + 'stock' => $this->integer(),
  27 + 'characteristics' => $this->text(),
  28 + ]
  29 + );
  30 + }
  31 +
  32 + /**
  33 + * @inheritdoc
  34 + */
  35 + public function down()
  36 + {
  37 + $this->dropTable('import');
  38 + $this->createTable(
  39 + 'import',
  40 + [
  41 + 'category_name' => $this->string(),
  42 + 'brand_name' => $this->string(),
  43 + 'product_name' => $this->string(),
  44 + 'sku' => $this->string(),
  45 + 'price' => $this->float(),
  46 + 'price_old' => $this->float(),
  47 + 'mask' => $this->integer(),
  48 + 'image_link' => $this->string(),
  49 + 'image_name' => $this->string(),
  50 + 'video' => $this->string(),
  51 + 'stock' => $this->integer(),
  52 + 'characteristics' => $this->text(),
  53 + ]
  54 + );
  55 + }
  56 + }
... ...
artweb/artbox-catalog/migrations/m170525_092834_add_column_description_import.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170525_092834_add_column_description_import extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->addColumn('import', 'description', $this->text());
  10 + }
  11 +
  12 + public function safeDown()
  13 + {
  14 + $this->dropColumn('import', 'description');
  15 + }
  16 + }
... ...
artweb/artbox-catalog/migrations/m170606_143404_create_product_recommend_table.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + /**
  6 + * Handles the creation of table `product_recommend`.
  7 + */
  8 + class m170606_143404_create_product_recommend_table extends Migration
  9 + {
  10 + /**
  11 + * @inheritdoc
  12 + */
  13 + public function safeUp()
  14 + {
  15 + $this->createTable(
  16 + 'product_recommend',
  17 + [
  18 + 'product_id' => $this->integer()
  19 + ->notNull(),
  20 + 'recommend_id' => $this->integer()
  21 + ->notNull(),
  22 + ]
  23 + );
  24 + $this->addPrimaryKey(
  25 + 'product_recommend_pk',
  26 + 'product_recommend',
  27 + [
  28 + 'product_id',
  29 + 'recommend_id',
  30 + ]
  31 + );
  32 + $this->addForeignKey(
  33 + 'product_fkey',
  34 + 'product_recommend',
  35 + 'product_id',
  36 + 'product',
  37 + 'id',
  38 + 'CASCADE',
  39 + 'CASCADE'
  40 + );
  41 + $this->addForeignKey(
  42 + 'recommend_fkey',
  43 + 'product_recommend',
  44 + 'recommend_id',
  45 + 'product',
  46 + 'id',
  47 + 'CASCADE',
  48 + 'CASCADE'
  49 + );
  50 + }
  51 +
  52 + /**
  53 + * @inheritdoc
  54 + */
  55 + public function safeDown()
  56 + {
  57 + $this->dropTable('product_recommend');
  58 + }
  59 + }
... ...
artweb/artbox-catalog/migrations/m170704_121345_add_in_menu_column_to_group_table.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + /**
  6 + * Handles adding in_menu to table `group`.
  7 + */
  8 + class m170704_121345_add_in_menu_column_to_group_table extends Migration
  9 + {
  10 + /**
  11 + * @inheritdoc
  12 + */
  13 + public function safeUp()
  14 + {
  15 + $this->addColumn('product_option_group_excl', 'in_menu', $this->boolean());
  16 + }
  17 +
  18 + /**
  19 + * @inheritdoc
  20 + */
  21 + public function safeDown()
  22 + {
  23 + $this->dropColumn('product_option_group_excl', 'in_menu');
  24 + }
  25 + }
... ...
artweb/artbox-catalog/migrations/m170704_125357_add_gallery_column_to_product_table.php 0 → 100755
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + /**
  6 + * Handles adding gallery to table `product`.
  7 + */
  8 + class m170704_125357_add_gallery_column_to_product_table extends Migration
  9 + {
  10 + /**
  11 + * @inheritdoc
  12 + */
  13 + public function up()
  14 + {
  15 + $this->addColumn('product', 'gallery', $this->string());
  16 + }
  17 +
  18 + /**
  19 + * @inheritdoc
  20 + */
  21 + public function down()
  22 + {
  23 + $this->dropColumn('product', 'gallery');
  24 + }
  25 + }
... ...
artweb/artbox-catalog/migrations/m170718_122904_add_in_menu_column_to_group_table.php 0 → 100644
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + /**
  6 + * Handles adding in_menu to table `group`.
  7 + */
  8 + class m170718_122904_add_in_menu_column_to_group_table extends Migration
  9 + {
  10 + /**
  11 + * @inheritdoc
  12 + */
  13 + public function safeUp()
  14 + {
  15 + $this->addColumn('product_option_group_compl', 'in_menu', $this->boolean());
  16 + }
  17 +
  18 + /**
  19 + * @inheritdoc
  20 + */
  21 + public function safeDown()
  22 + {
  23 + $this->dropColumn('product_option_group_compl', 'in_menu');
  24 + }
  25 + }
... ...
artweb/artbox-catalog/migrations/m170728_075321_add_the_rest_in_menu.php 0 → 100644
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170728_075321_add_the_rest_in_menu extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->addColumn('variant_option_group_compl', 'in_menu', $this->boolean());
  10 + $this->addColumn('variant_option_group_excl', 'in_menu', $this->boolean());
  11 + }
  12 +
  13 + public function safeDown()
  14 + {
  15 + $this->dropColumn('variant_option_group_compl', 'in_menu');
  16 + $this->dropColumn('variant_option_group_excl', 'in_menu');
  17 + }
  18 + }
... ...
artweb/artbox-catalog/migrations/m170802_085651_create_price_upload_table.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\db\Migration;
  4 +
  5 +/**
  6 + * Handles the creation of table `price_upload`.
  7 + */
  8 +class m170802_085651_create_price_upload_table extends Migration
  9 +{
  10 + /**
  11 + * @inheritdoc
  12 + */
  13 + public function up()
  14 + {
  15 + $this->createTable('price_upload', [
  16 + 'sku' => $this->string(),
  17 + 'price' => $this->decimal(),
  18 + 'price_old' => $this->decimal(),
  19 + ]);
  20 +
  21 + $this->addPrimaryKey('sku_price_upload_pk', 'price_upload', 'sku');
  22 + }
  23 +
  24 + /**
  25 + * @inheritdoc
  26 + */
  27 + public function down()
  28 + {
  29 + $this->dropTable('price_upload');
  30 + }
  31 +}
... ...
artweb/artbox-catalog/migrations/m170804_121051_add_group_to_category_columns.php 0 → 100644
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + class m170804_121051_add_group_to_category_columns extends Migration
  6 + {
  7 + public function safeUp()
  8 + {
  9 + $this->addColumn('product_option_group_excl_to_category', 'sort', $this->integer());
  10 + $this->addColumn('product_option_group_excl_to_category', 'is_filter', $this->boolean());
  11 + $this->addColumn('product_option_group_excl_to_category', 'status', $this->boolean());
  12 + $this->addColumn('product_option_group_excl_to_category', 'in_menu', $this->boolean());
  13 +
  14 + $this->addColumn('variant_option_group_excl_to_category', 'sort', $this->integer());
  15 + $this->addColumn('variant_option_group_excl_to_category', 'is_filter', $this->boolean());
  16 + $this->addColumn('variant_option_group_excl_to_category', 'status', $this->boolean());
  17 + $this->addColumn('variant_option_group_excl_to_category', 'in_menu', $this->boolean());
  18 + }
  19 +
  20 + public function safeDown()
  21 + {
  22 + $this->dropColumn('product_option_group_excl_to_category', 'sort');
  23 + $this->dropColumn('product_option_group_excl_to_category', 'is_filter');
  24 + $this->dropColumn('product_option_group_excl_to_category', 'status');
  25 + $this->dropColumn('product_option_group_excl_to_category', 'in_menu');
  26 +
  27 + $this->dropColumn('variant_option_group_excl_to_category', 'sort');
  28 + $this->dropColumn('variant_option_group_excl_to_category', 'is_filter');
  29 + $this->dropColumn('variant_option_group_excl_to_category', 'status');
  30 + $this->dropColumn('variant_option_group_excl_to_category', 'in_menu');
  31 + }
  32 + }
... ...
artweb/artbox-catalog/models/Brand.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use artbox\core\behaviors\LanguageBehavior;
  6 + use artbox\core\models\Image;
  7 + use artbox\core\models\Language;
  8 + use Yii;
  9 + use yii\behaviors\TimestampBehavior;
  10 + use yii\db\ActiveQuery;
  11 + use yii\db\ActiveRecord;
  12 + use yii\web\Request;
  13 +
  14 + /**
  15 + * This is the model class for table "brand".
  16 + *
  17 + * @property integer $id
  18 + * @property integer $image_id
  19 + * @property integer $sort
  20 + * @property boolean $status
  21 + * @property integer $created_at
  22 + * @property integer $updated_at
  23 + *
  24 + * @property Image $image
  25 + * @property BrandLang[] $brandLangs
  26 + * @property Language[] $languages
  27 + * @property Product[] $products
  28 + *
  29 + * * From language behavior *
  30 + * @property BrandLang $lang
  31 + * @property BrandLang[] $langs
  32 + * @property BrandLang $objectLang
  33 + * @property string $ownerKey
  34 + * @property string $langKey
  35 + * @property BrandLang[] $modelLangs
  36 + * @property bool $transactionStatus
  37 + * @method string getOwnerKey()
  38 + * @method void setOwnerKey( string $value )
  39 + * @method string getLangKey()
  40 + * @method void setLangKey( string $value )
  41 + * @method ActiveQuery getLangs()
  42 + * @method ActiveQuery getLang( integer $language_id )
  43 + * @method BrandLang[] generateLangs()
  44 + * @method void loadLangs( Request $request )
  45 + * @method bool linkLangs()
  46 + * @method bool saveLangs()
  47 + * @method bool getTransactionStatus()
  48 + * @method bool loadWithLangs( Request $request )
  49 + * @method bool saveWithLangs()
  50 + * * End language behavior *
  51 + * @see LanguageBehavior
  52 + */
  53 + class Brand extends ActiveRecord
  54 + {
  55 + /**
  56 + * @inheritdoc
  57 + */
  58 + public static function tableName()
  59 + {
  60 + return 'brand';
  61 + }
  62 +
  63 + /**
  64 + * @inheritdoc
  65 + */
  66 + public function behaviors()
  67 + {
  68 + return [
  69 + 'language' => [
  70 + 'class' => LanguageBehavior::className(),
  71 + ],
  72 + 'timestamp' => [
  73 + 'class' => TimestampBehavior::className(),
  74 + ],
  75 + ];
  76 + }
  77 +
  78 + /**
  79 + * @inheritdoc
  80 + */
  81 + public function rules()
  82 + {
  83 + return [
  84 + [
  85 + [
  86 + 'image_id',
  87 + 'sort',
  88 + ],
  89 + 'integer',
  90 + ],
  91 + [
  92 + [ 'status' ],
  93 + 'boolean',
  94 + ],
  95 + [
  96 + [ 'image_id' ],
  97 + 'exist',
  98 + 'skipOnError' => true,
  99 + 'targetClass' => Image::className(),
  100 + 'targetAttribute' => [ 'image_id' => 'id' ],
  101 + ],
  102 + ];
  103 + }
  104 +
  105 + /**
  106 + * @inheritdoc
  107 + */
  108 + public function attributeLabels()
  109 + {
  110 + return [
  111 + 'id' => Yii::t('catalog', 'ID'),
  112 + 'image_id' => Yii::t('catalog', 'ID изображения'),
  113 + 'sort' => Yii::t('catalog', 'Сортировка'),
  114 + 'status' => Yii::t('catalog', 'Статус'),
  115 + 'created_at' => Yii::t('catalog', 'Создано'),
  116 + 'updated_at' => Yii::t('catalog', 'Обновлено'),
  117 + ];
  118 + }
  119 +
  120 + /**
  121 + * @return \yii\db\ActiveQuery
  122 + */
  123 + public function getImage()
  124 + {
  125 + return $this->hasOne(Image::className(), [ 'id' => 'image_id' ]);
  126 + }
  127 +
  128 + /**
  129 + * @return \yii\db\ActiveQuery
  130 + */
  131 + public function getBrandLangs()
  132 + {
  133 + return $this->hasMany(BrandLang::className(), [ 'brand_id' => 'id' ])
  134 + ->inverseOf('brand');
  135 + }
  136 +
  137 + /**
  138 + * @return \yii\db\ActiveQuery
  139 + */
  140 + public function getLanguages()
  141 + {
  142 + return $this->hasMany(Language::className(), [ 'id' => 'language_id' ])
  143 + ->viaTable('brand_lang', [ 'brand_id' => 'id' ]);
  144 + }
  145 +
  146 + /**
  147 + * @return \yii\db\ActiveQuery
  148 + */
  149 + public function getProducts()
  150 + {
  151 + return $this->hasMany(Product::className(), [ 'brand_id' => 'id' ])
  152 + ->inverseOf('brand');
  153 + }
  154 + }
... ...
artweb/artbox-catalog/models/BrandLang.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use artbox\core\behaviors\SlugBehavior;
  6 + use artbox\core\models\Alias;
  7 + use artbox\core\models\Language;
  8 + use Yii;
  9 + use yii\db\ActiveRecord;
  10 +
  11 + /**
  12 + * This is the model class for table "brand_lang".
  13 + *
  14 + * @property integer $brand_id
  15 + * @property integer $language_id
  16 + * @property string $title
  17 + * @property integer $alias_id
  18 + * @property string $description
  19 + *
  20 + * @property Alias $alias
  21 + * @property Brand $brand
  22 + * @property Language $language
  23 + */
  24 + class BrandLang extends ActiveRecord
  25 + {
  26 + /**
  27 + * @inheritdoc
  28 + */
  29 + public static function tableName()
  30 + {
  31 + return 'brand_lang';
  32 + }
  33 +
  34 + /**
  35 + * @inheritdoc
  36 + */
  37 + public function behaviors()
  38 + {
  39 + return [
  40 + 'slug' => [
  41 + 'class' => SlugBehavior::className(),
  42 + 'action' => 'brand/view',
  43 + 'params' => [
  44 + 'id' => 'brand_id',
  45 + ],
  46 + 'fields' => [
  47 + 'title' => \Yii::t('catalog', 'Brand title'),
  48 + 'description' => \Yii::t('catalog', 'Brand description'),
  49 + ],
  50 + ],
  51 + ];
  52 + }
  53 +
  54 + /**
  55 + * @inheritdoc
  56 + */
  57 + public function rules()
  58 + {
  59 + return [
  60 + [
  61 + [
  62 + 'title',
  63 + ],
  64 + 'required',
  65 + ],
  66 + [
  67 + [ 'description' ],
  68 + 'string',
  69 + ],
  70 + [
  71 + [
  72 + 'title',
  73 + 'aliasValue',
  74 + ],
  75 + 'string',
  76 + 'max' => 255,
  77 + ],
  78 + ];
  79 + }
  80 +
  81 + /**
  82 + * @inheritdoc
  83 + */
  84 + public function attributeLabels()
  85 + {
  86 + return [
  87 + 'brand_id' => Yii::t('catalog', 'Brand ID'),
  88 + 'language_id' => Yii::t('catalog', 'Language ID'),
  89 + 'title' => Yii::t('catalog', 'Title'),
  90 + 'alias_id' => Yii::t('catalog', 'Alias ID'),
  91 + 'description' => Yii::t('catalog', 'Description'),
  92 + ];
  93 + }
  94 +
  95 + /**
  96 + * @return \yii\db\ActiveQuery
  97 + */
  98 + public function getAlias()
  99 + {
  100 + return $this->hasOne(Alias::className(), [ 'id' => 'alias_id' ]);
  101 + }
  102 +
  103 + /**
  104 + * @return \yii\db\ActiveQuery
  105 + */
  106 + public function getBrand()
  107 + {
  108 + return $this->hasOne(Brand::className(), [ 'id' => 'brand_id' ])
  109 + ->inverseOf('brandLangs');
  110 + }
  111 +
  112 + /**
  113 + * @return \yii\db\ActiveQuery
  114 + */
  115 + public function getLanguage()
  116 + {
  117 + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]);
  118 + }
  119 + }
... ...
artweb/artbox-catalog/models/BrandSearch.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use yii\base\Model;
  6 + use yii\data\ActiveDataProvider;
  7 +
  8 + /**
  9 + * BrandSearch represents the model behind the search form about `artbox\catalog\models\Brand`.
  10 + */
  11 + class BrandSearch extends Brand
  12 + {
  13 +
  14 + public $title;
  15 +
  16 + /**
  17 + * @inheritdoc
  18 + */
  19 + public function behaviors()
  20 + {
  21 + return [];
  22 + }
  23 +
  24 + /**
  25 + * @inheritdoc
  26 + */
  27 + public function rules()
  28 + {
  29 + return [
  30 + [
  31 + [
  32 + 'id',
  33 + 'image_id',
  34 + ],
  35 + 'integer',
  36 + ],
  37 + [
  38 + [
  39 + 'title',
  40 + ],
  41 + 'string',
  42 + ],
  43 + [
  44 + [ 'status' ],
  45 + 'boolean',
  46 + ],
  47 + ];
  48 + }
  49 +
  50 + /**
  51 + * @inheritdoc
  52 + */
  53 + public function scenarios()
  54 + {
  55 + // bypass scenarios() implementation in the parent class
  56 + return Model::scenarios();
  57 + }
  58 +
  59 + /**
  60 + * Creates data provider instance with search query applied
  61 + *
  62 + * @param array $params
  63 + *
  64 + * @return ActiveDataProvider
  65 + */
  66 + public function search($params)
  67 + {
  68 + $query = Brand::find()
  69 + ->joinWith('lang');
  70 +
  71 + // add conditions that should always apply here
  72 +
  73 + $dataProvider = new ActiveDataProvider(
  74 + [
  75 + 'query' => $query,
  76 + 'sort' => [
  77 + 'attributes' => [
  78 + 'id',
  79 + 'title',
  80 + 'created_at',
  81 + 'status',
  82 + 'sort',
  83 + ],
  84 + ],
  85 + ]
  86 + );
  87 +
  88 + $this->load($params);
  89 +
  90 + if (!$this->validate()) {
  91 + // uncomment the following line if you do not want to return any records when validation fails
  92 + // $query->where('0=1');
  93 + return $dataProvider;
  94 + }
  95 +
  96 + // grid filtering conditions
  97 + $query->andFilterWhere(
  98 + [
  99 + 'id' => $this->id,
  100 + 'status' => $this->status,
  101 + ]
  102 + )
  103 + ->andFilterWhere(
  104 + [
  105 + 'like',
  106 + 'brand_lang.title',
  107 + $this->title,
  108 + ]
  109 + );
  110 +
  111 + return $dataProvider;
  112 + }
  113 + }
... ...
artweb/artbox-catalog/models/Category.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use artbox\catalog\behaviors\LevelBehavior;
  6 + use artbox\catalog\models\queries\CategoryQuery;
  7 + use artbox\core\behaviors\LanguageBehavior;
  8 + use artbox\core\models\Image;
  9 + use yii\behaviors\TimestampBehavior;
  10 + use yii\db\ActiveRecord;
  11 + use yii\db\ActiveQuery;
  12 + use yii\web\Request;
  13 + use artbox\core\models\Language;
  14 +
  15 + /**
  16 + * This is the model class for table "category".
  17 + *
  18 + * @property integer $id
  19 + * @property integer $image_id
  20 + * @property integer $thumb_id
  21 + * @property integer $parent_id
  22 + * @property integer $level
  23 + * @property integer $sort
  24 + * @property boolean $status
  25 + * @property integer $created_at
  26 + * @property integer $updated_at
  27 + * @property Image $image
  28 + * @property Image $thumb
  29 + * @property Category $parent
  30 + * @property Category[] $categories
  31 + * @property CategoryLang[] $categoryLangs
  32 + * @property Language[] $languages
  33 + * @property ProductToCategory[] $productToCategories
  34 + * @property Product[] $products
  35 + * @property ProductOptionGroupComplToCategory[] $productOptionGroupComplToCategories
  36 + * @property ProductOptionGroupExclToCategory[] $productOptionGroupExclToCategories
  37 + * @property VariantOptionGroupComplToCategory[] $variantOptionGroupComplToCategories
  38 + * @property VariantOptionGroupExclToCategory[] $variantOptionGroupExclToCategories
  39 + * @property ProductOptionGroupCompl[] $productOptionGroupCompls
  40 + * @property ProductOptionGroupExcl[] $productOptionGroupExcls
  41 + * @property VariantOptionGroupCompl[] $variantOptionGroupCompls
  42 + * @property VariantOptionGroupExcl[] $variantOptionGroupExcls
  43 + * * From language behavior *
  44 + * @property CategoryLang $lang
  45 + * @property CategoryLang[] $langs
  46 + * @property CategoryLang $objectLang
  47 + * @property string $ownerKey
  48 + * @property string $langKey
  49 + * @property CategoryLang[] $modelLangs
  50 + * @property bool $transactionStatus
  51 + * @method string getOwnerKey()
  52 + * @method void setOwnerKey( string $value )
  53 + * @method string getLangKey()
  54 + * @method void setLangKey( string $value )
  55 + * @method ActiveQuery getLangs()
  56 + * @method ActiveQuery getLang( integer $language_id )
  57 + * @method CategoryLang[] generateLangs()
  58 + * @method void loadLangs( Request $request )
  59 + * @method bool linkLangs()
  60 + * @method bool saveLangs()
  61 + * @method bool getTransactionStatus()
  62 + * @method bool loadWithLangs( Request $request )
  63 + * @method bool saveWithLangs()
  64 + * * End language behavior *
  65 + * @see LanguageBehavior
  66 + */
  67 + class Category extends ActiveRecord
  68 + {
  69 +
  70 + /**
  71 + * @return CategoryQuery the active query used by this AR class.
  72 + */
  73 + public static function find()
  74 + {
  75 + return new CategoryQuery(get_called_class());
  76 + }
  77 +
  78 + /**
  79 + * @inheritdoc
  80 + */
  81 + public static function tableName()
  82 + {
  83 + return 'category';
  84 + }
  85 +
  86 + /**
  87 + * @inheritdoc
  88 + */
  89 + public function behaviors()
  90 + {
  91 + return [
  92 + 'language' => [
  93 + 'class' => LanguageBehavior::className(),
  94 + ],
  95 + [
  96 + 'class' => TimestampBehavior::className(),
  97 + ],
  98 + [
  99 + 'class' => LevelBehavior::className(),
  100 + ],
  101 + ];
  102 + }
  103 +
  104 + /**
  105 + * @inheritdoc
  106 + */
  107 + public function rules()
  108 + {
  109 + return [
  110 + [
  111 + [
  112 + 'image_id',
  113 + 'thumb_id',
  114 + 'parent_id',
  115 + 'level',
  116 + 'sort',
  117 + 'created_at',
  118 + 'updated_at',
  119 + ],
  120 + 'integer',
  121 + ],
  122 + [
  123 + [ 'status' ],
  124 + 'boolean',
  125 + ],
  126 + [
  127 + [ 'parent_id' ],
  128 + 'exist',
  129 + 'skipOnError' => true,
  130 + 'targetClass' => Category::className(),
  131 + 'targetAttribute' => [ 'parent_id' => 'id' ],
  132 + ],
  133 + ];
  134 + }
  135 +
  136 + /**
  137 + * @inheritdoc
  138 + */
  139 + public function attributeLabels()
  140 + {
  141 + return [
  142 + 'id' => \Yii::t('catalog', 'ID'),
  143 + 'image_id' => \Yii::t('catalog', 'ID изображения'),
  144 + 'thumb_id' => \Yii::t('catalog', 'ID миниатюры'),
  145 + 'parent_id' => \Yii::t('catalog', 'Родительский ID'),
  146 + 'level' => \Yii::t('catalog', 'Уровень'),
  147 + 'sort' => \Yii::t('catalog', 'Сортировка'),
  148 + 'status' => \Yii::t('catalog', 'Статус'),
  149 + 'created_at' => \Yii::t('catalog', 'Создано'),
  150 + 'updated_at' => \Yii::t('catalog', 'Обновлено'),
  151 + 'title' => \Yii::t('catalog', 'Title'),
  152 + ];
  153 + }
  154 +
  155 + /**
  156 + * @return \yii\db\ActiveQuery
  157 + */
  158 + public function getImage()
  159 + {
  160 + return $this->hasOne(Image::className(), [ 'id' => 'image_id' ]);
  161 + }
  162 +
  163 + /**
  164 + * @return \yii\db\ActiveQuery
  165 + */
  166 + public function getThumb()
  167 + {
  168 + return $this->hasOne(Image::className(), [ 'id' => 'thumb_id' ]);
  169 + }
  170 +
  171 + /**
  172 + * @return \yii\db\ActiveQuery
  173 + */
  174 + public function getParent()
  175 + {
  176 + return $this->hasOne(Category::className(), [ 'id' => 'parent_id' ]);
  177 + }
  178 +
  179 + /**
  180 + * @return \yii\db\ActiveQuery
  181 + */
  182 + public function getCategories()
  183 + {
  184 + return $this->hasMany(Category::className(), [ 'parent_id' => 'id' ]);
  185 + }
  186 +
  187 + /**
  188 + * @return \yii\db\ActiveQuery
  189 + */
  190 + public function getCategoryLangs()
  191 + {
  192 + return $this->hasMany(CategoryLang::className(), [ 'category_id' => 'id' ]);
  193 + }
  194 +
  195 + /**
  196 + * @return \yii\db\ActiveQuery
  197 + */
  198 + public function getLanguages()
  199 + {
  200 + return $this->hasMany(Language::className(), [ 'id' => 'language_id' ])
  201 + ->viaTable('category_lang', [ 'category_id' => 'id' ]);
  202 + }
  203 +
  204 + /**
  205 + * @return \yii\db\ActiveQuery
  206 + */
  207 + public function getProductToCategories()
  208 + {
  209 + return $this->hasMany(ProductToCategory::className(), [ 'category_id' => 'id' ]);
  210 + }
  211 +
  212 + /**
  213 + * @return \yii\db\ActiveQuery
  214 + */
  215 + public function getProducts()
  216 + {
  217 + return $this->hasMany(Product::className(), [ 'id' => 'product_id' ])
  218 + ->viaTable('product_to_category', [ 'category_id' => 'id' ]);
  219 + }
  220 +
  221 + /**
  222 + * @return \yii\db\ActiveQuery
  223 + */
  224 + public function getProductOptionGroupComplToCategories()
  225 + {
  226 + return $this->hasMany(ProductOptionGroupComplToCategory::className(), [ 'category_id' => 'id' ])
  227 + ->inverseOf('category');
  228 + }
  229 +
  230 + /**
  231 + * @return \yii\db\ActiveQuery
  232 + */
  233 + public function getProductOptionGroupCompls()
  234 + {
  235 + return $this->hasMany(ProductOptionGroupCompl::className(), [ 'id' => 'product_option_group_compl_id' ])
  236 + ->viaTable('product_option_group_compl_to_category', [ 'category_id' => 'id' ]);
  237 + }
  238 +
  239 + /**
  240 + * @return \yii\db\ActiveQuery
  241 + */
  242 + public function getProductOptionGroupExclToCategories()
  243 + {
  244 + return $this->hasMany(ProductOptionGroupExclToCategory::className(), [ 'category_id' => 'id' ])
  245 + ->inverseOf('category');
  246 + }
  247 +
  248 + /**
  249 + * @return \yii\db\ActiveQuery
  250 + */
  251 + public function getProductOptionGroupExcls()
  252 + {
  253 + return $this->hasMany(ProductOptionGroupExcl::className(), [ 'id' => 'product_option_group_excl_id' ])
  254 + ->viaTable('product_option_group_excl_to_category', [ 'category_id' => 'id' ]);
  255 + }
  256 +
  257 + /**
  258 + * @return \yii\db\ActiveQuery
  259 + */
  260 + public function getVariantOptionGroupComplToCategories()
  261 + {
  262 + return $this->hasMany(VariantOptionGroupComplToCategory::className(), [ 'category_id' => 'id' ])
  263 + ->inverseOf('category');
  264 + }
  265 +
  266 + /**
  267 + * @return \yii\db\ActiveQuery
  268 + */
  269 + public function getVariantOptionGroupCompls()
  270 + {
  271 + return $this->hasMany(VariantOptionGroupCompl::className(), [ 'id' => 'variant_option_group_compl_id' ])
  272 + ->viaTable('variant_option_group_compl_to_category', [ 'category_id' => 'id' ]);
  273 + }
  274 +
  275 + /**
  276 + * @return \yii\db\ActiveQuery
  277 + */
  278 + public function getVariantOptionGroupExclToCategories()
  279 + {
  280 + return $this->hasMany(VariantOptionGroupExclToCategory::className(), [ 'category_id' => 'id' ])
  281 + ->inverseOf('category');
  282 + }
  283 +
  284 + /**
  285 + * @return \yii\db\ActiveQuery
  286 + */
  287 + public function getVariantOptionGroupExcls()
  288 + {
  289 + return $this->hasMany(VariantOptionGroupExcl::className(), [ 'id' => 'variant_option_group_excl_id' ])
  290 + ->viaTable('variant_option_group_excl_to_category', [ 'category_id' => 'id' ]);
  291 + }
  292 +
  293 + public static function findWithFilters(int $category_id): ActiveQuery
  294 + {
  295 + return self::find()
  296 + ->where([ 'category.id' => $category_id ])
  297 + ->with(
  298 + [
  299 + 'productOptionGroupCompls' => function ($query) {
  300 + /**
  301 + * @var ActiveQuery $query
  302 + */
  303 + $query->andWhere(
  304 + [
  305 + 'product_option_group_compl.is_filter' => true,
  306 + ]
  307 + );
  308 + $query->orderBy(
  309 + [
  310 + 'sort' => SORT_ASC,
  311 + 'product_option_group_compl_lang.title' => SORT_ASC,
  312 + ]
  313 + );
  314 + $query->innerJoinWith('lang.alias')
  315 + ->with(
  316 + [
  317 + 'options' => function ($query) {
  318 + /**
  319 + * @var ActiveQuery $query
  320 + */
  321 + $query->innerJoinWith('lang.alias');
  322 + $query->orderBy(
  323 + [
  324 + 'sort' => SORT_ASC,
  325 + 'product_option_compl_lang.value' => SORT_DESC,
  326 + ]
  327 + );
  328 + },
  329 + ]
  330 + );
  331 + },
  332 + ]
  333 + )
  334 + ->with(
  335 + [
  336 + 'productOptionGroupExcls' => function ($query) {
  337 + /**
  338 + * @var ActiveQuery $query
  339 + */
  340 + $query->andWhere(
  341 + [
  342 + 'product_option_group_excl.is_filter' => true,
  343 + ]
  344 + );
  345 + $query->orderBy(
  346 + [
  347 + 'sort' => SORT_ASC,
  348 + 'product_option_group_excl_lang.title' => SORT_ASC,
  349 + ]
  350 + );
  351 + $query->innerJoinWith('lang.alias')
  352 + ->with(
  353 + [
  354 + 'options' => function ($query) {
  355 + /**
  356 + * @var ActiveQuery $query
  357 + */
  358 + $query->innerJoinWith('lang.alias');
  359 + $query->orderBy(
  360 + [
  361 + 'sort' => SORT_ASC,
  362 + 'product_option_excl_lang.value' => SORT_DESC,
  363 + ]
  364 + );
  365 + },
  366 + ]
  367 + );
  368 + },
  369 + ]
  370 + )
  371 + ->with(
  372 + [
  373 + 'variantOptionGroupCompls' => function ($query) {
  374 + /**
  375 + * @var ActiveQuery $query
  376 + */
  377 + $query->andWhere(
  378 + [
  379 + 'variant_option_group_compl.is_filter' => true,
  380 + ]
  381 + );
  382 + $query->orderBy(
  383 + [
  384 + 'sort' => SORT_ASC,
  385 + 'variant_option_group_compl_lang.title' => SORT_ASC,
  386 + ]
  387 + );
  388 + $query->innerJoinWith('lang.alias')
  389 + ->with(
  390 + [
  391 + 'options' => function ($query) {
  392 + /**
  393 + * @var ActiveQuery $query
  394 + */
  395 + $query->innerJoinWith('lang.alias');
  396 + $query->orderBy(
  397 + [
  398 + 'sort' => SORT_ASC,
  399 + 'variant_option_compl_lang.value' => SORT_DESC,
  400 + ]
  401 + );
  402 + },
  403 + ]
  404 + );
  405 + },
  406 + ]
  407 + )
  408 + ->with(
  409 + [
  410 + 'variantOptionGroupExcls' => function ($query) {
  411 + /**
  412 + * @var ActiveQuery $query
  413 + */
  414 + $query->andWhere(
  415 + [
  416 + 'variant_option_group_excl.is_filter' => true,
  417 + ]
  418 + );
  419 + $query->orderBy(
  420 + [
  421 + 'sort' => SORT_ASC,
  422 + 'variant_option_group_excl_lang.title' => SORT_ASC,
  423 + ]
  424 + );
  425 + $query->innerJoinWith('lang.alias')
  426 + ->with(
  427 + [
  428 + 'options' => function ($query) {
  429 + /**
  430 + * @var ActiveQuery $query
  431 + */
  432 + $query->innerJoinWith('lang.alias');
  433 + $query->orderBy(
  434 + [
  435 + 'sort' => SORT_ASC,
  436 + 'variant_option_excl_lang.value' => SORT_DESC,
  437 + ]
  438 + );
  439 + },
  440 + ]
  441 + );
  442 + },
  443 + ]
  444 + )
  445 + ->with('products.brand.lang.alias');
  446 + }
  447 +
  448 + public static function findWithFiltersProducts(int $category_id): ActiveQuery
  449 + {
  450 + return self::find()
  451 + ->where([ 'category.id' => $category_id ])
  452 + ->with(
  453 + [
  454 + 'productOptionGroupCompls' => function ($query) use($category_id) {
  455 + /**
  456 + * @var ActiveQuery $query
  457 + */
  458 + $query->andWhere(
  459 + [
  460 + 'product_option_group_compl.is_filter' => true,
  461 + ]
  462 + );
  463 + $query->orderBy(
  464 + [
  465 + 'sort' => SORT_ASC,
  466 + 'product_option_group_compl_lang.title' => SORT_ASC,
  467 + ]
  468 + );
  469 + $query->innerJoinWith('lang.alias')
  470 + ->with(
  471 + [
  472 + 'options' => function ($query) use($category_id) {
  473 + /**
  474 + * @var ActiveQuery $query
  475 + */
  476 + $query->select(['product_option_compl.*']);
  477 + $query->groupBy(['product_option_compl.id', 'product_option_compl_lang.value']);
  478 + $query->innerJoinWith('lang.alias');
  479 + $query->innerJoinWith('products.productToCategories', false);
  480 + $query->andWhere(['product_to_category.category_id' => $category_id]);
  481 + $query->orderBy(
  482 + [
  483 + 'sort' => SORT_ASC,
  484 + 'product_option_compl_lang.value' => SORT_DESC,
  485 + ]
  486 + );
  487 + },
  488 + ]
  489 + );
  490 + },
  491 + ]
  492 + )
  493 + ->with(
  494 + [
  495 + 'productOptionGroupExcls' => function ($query) use($category_id) {
  496 + /**
  497 + * @var ActiveQuery $query
  498 + */
  499 + $query->joinWith('productOptionGroupExclToCategories');
  500 + $query->andWhere(
  501 + [
  502 + 'product_option_group_excl_to_category.is_filter' => true,
  503 + ]
  504 + );
  505 + $query->orderBy(
  506 + [
  507 + 'sort' => SORT_ASC,
  508 + 'product_option_group_excl_lang.title' => SORT_ASC,
  509 + ]
  510 + );
  511 + $query->innerJoinWith('lang.alias')
  512 + ->with(
  513 + [
  514 + 'options' => function ($query) use($category_id) {
  515 + /**
  516 + * @var ActiveQuery $query
  517 + */
  518 + $query->select(['product_option_excl.*']);
  519 + $query->groupBy(['product_option_excl.id', 'product_option_excl_lang.value']);
  520 + $query->innerJoinWith('lang.alias');
  521 + $query->innerJoinWith('products.productToCategories', false);
  522 + $query->andWhere(['product_to_category.category_id' => $category_id]);
  523 + $query->orderBy(
  524 + [
  525 + 'sort' => SORT_ASC,
  526 + 'product_option_excl_lang.value' => SORT_DESC,
  527 + ]
  528 + );
  529 + },
  530 + ]
  531 + );
  532 + },
  533 + ]
  534 + )
  535 + ->with(
  536 + [
  537 + 'variantOptionGroupCompls' => function ($query) use($category_id) {
  538 + /**
  539 + * @var ActiveQuery $query
  540 + */
  541 + $query->andWhere(
  542 + [
  543 + 'variant_option_group_compl.is_filter' => true,
  544 + ]
  545 + );
  546 + $query->orderBy(
  547 + [
  548 + 'sort' => SORT_ASC,
  549 + 'variant_option_group_compl_lang.title' => SORT_ASC,
  550 + ]
  551 + );
  552 + $query->innerJoinWith('lang.alias')
  553 + ->with(
  554 + [
  555 + 'options' => function ($query) use($category_id) {
  556 + /**
  557 + * @var ActiveQuery $query
  558 + */
  559 + $query->select(['variant_option_compl.*']);
  560 + $query->groupBy(['variant_option_compl.id', 'variant_option_compl_lang.value']);
  561 + $query->innerJoinWith('lang.alias');
  562 + $query->innerJoinWith('variants.product.productToCategories', false);
  563 + $query->andWhere(['product_to_category.category_id' => $category_id]);
  564 + $query->orderBy(
  565 + [
  566 + 'sort' => SORT_ASC,
  567 + 'variant_option_compl_lang.value' => SORT_DESC,
  568 + ]
  569 + );
  570 + },
  571 + ]
  572 + );
  573 + },
  574 + ]
  575 + )
  576 + ->with(
  577 + [
  578 + 'variantOptionGroupExcls' => function ($query) use($category_id) {
  579 + /**
  580 + * @var ActiveQuery $query
  581 + */
  582 + $query->andWhere(
  583 + [
  584 + 'variant_option_group_excl.is_filter' => true,
  585 + ]
  586 + );
  587 + $query->orderBy(
  588 + [
  589 + 'sort' => SORT_ASC,
  590 + 'variant_option_group_excl_lang.title' => SORT_ASC,
  591 + ]
  592 + );
  593 + $query->innerJoinWith('lang.alias')
  594 + ->with(
  595 + [
  596 + 'options' => function ($query) use($category_id) {
  597 + /**
  598 + * @var ActiveQuery $query
  599 + */
  600 + $query->select(['variant_option_excl.*']);
  601 + $query->groupBy(['variant_option_excl.id', 'variant_option_excl_lang.value']);
  602 + $query->innerJoinWith('lang.alias');
  603 + $query->innerJoinWith('variants.product.productToCategories', false);
  604 + $query->andWhere(['product_to_category.category_id' => $category_id]);
  605 + $query->orderBy(
  606 + [
  607 + 'sort' => SORT_ASC,
  608 + 'variant_option_excl_lang.value' => SORT_DESC,
  609 + ]
  610 + );
  611 + },
  612 + ]
  613 + );
  614 + },
  615 + ]
  616 + )
  617 + ->with('products.brand.lang.alias');
  618 + }
  619 + }
0 620 \ No newline at end of file
... ...
artweb/artbox-catalog/models/CategoryLang.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use artbox\core\behaviors\SlugBehavior;
  6 + use artbox\core\models\Alias;
  7 + use artbox\core\models\Language;
  8 + use Yii;
  9 + use yii\db\ActiveRecord;
  10 +
  11 + /**
  12 + * This is the model class for table "category_lang".
  13 + *
  14 + * @property integer $category_id
  15 + * @property integer $language_id
  16 + * @property string $title
  17 + * @property integer $alias_id
  18 + * @property string $description
  19 + * @property Alias $alias
  20 + * @property Category $category
  21 + * @property Language $language
  22 + */
  23 + class CategoryLang extends ActiveRecord
  24 + {
  25 + /**
  26 + * @inheritdoc
  27 + */
  28 + public static function tableName()
  29 + {
  30 + return 'category_lang';
  31 + }
  32 +
  33 + /**
  34 + * @inheritdoc
  35 + */
  36 + public function behaviors()
  37 + {
  38 + return [
  39 + 'slug' => [
  40 + 'class' => SlugBehavior::className(),
  41 + 'action' => 'category/view',
  42 + 'params' => [
  43 + 'id' => 'category_id',
  44 + ],
  45 + 'fields' => [
  46 + 'title' => 'Category title',
  47 + ],
  48 + ],
  49 + ];
  50 + }
  51 +
  52 + /**
  53 + * @inheritdoc
  54 + */
  55 + public function rules()
  56 + {
  57 + return [
  58 + [
  59 + [
  60 + 'category_id',
  61 + 'language_id',
  62 + 'title',
  63 + ],
  64 + 'required',
  65 + ],
  66 + [
  67 + [
  68 + 'category_id',
  69 + 'language_id',
  70 + 'alias_id',
  71 + ],
  72 + 'integer',
  73 + ],
  74 + [
  75 + [ 'description' ],
  76 + 'string',
  77 + ],
  78 + [
  79 + [
  80 + 'title',
  81 + 'aliasValue',
  82 + ],
  83 + 'string',
  84 + 'max' => 255,
  85 + ],
  86 + [
  87 + [ 'alias_id' ],
  88 + 'unique',
  89 + ],
  90 + [
  91 + [ 'category_id' ],
  92 + 'exist',
  93 + 'skipOnError' => true,
  94 + 'targetClass' => Category::className(),
  95 + 'targetAttribute' => [ 'category_id' => 'id' ],
  96 + ],
  97 + [
  98 + [ 'language_id' ],
  99 + 'exist',
  100 + 'skipOnError' => true,
  101 + 'targetClass' => Language::className(),
  102 + 'targetAttribute' => [ 'language_id' => 'id' ],
  103 + ],
  104 + ];
  105 + }
  106 +
  107 + /**
  108 + * @inheritdoc
  109 + */
  110 + public function attributeLabels()
  111 + {
  112 + return [
  113 + 'category_id' => Yii::t('catalog', 'Category ID'),
  114 + 'language_id' => Yii::t('catalog', 'Language ID'),
  115 + 'title' => Yii::t('catalog', 'Title'),
  116 + 'alias_id' => Yii::t('catalog', 'Alias ID'),
  117 + 'description' => Yii::t('catalog', 'Description'),
  118 + ];
  119 + }
  120 +
  121 + /**
  122 + * @return \yii\db\ActiveQuery
  123 + */
  124 + public function getAlias()
  125 + {
  126 + return $this->hasOne(Alias::className(), [ 'id' => 'alias_id' ]);
  127 + }
  128 +
  129 + /**
  130 + * @return \yii\db\ActiveQuery
  131 + */
  132 + public function getCategory()
  133 + {
  134 + return $this->hasOne(Category::className(), [ 'id' => 'category_id' ]);
  135 + }
  136 +
  137 + /**
  138 + * @return \yii\db\ActiveQuery
  139 + */
  140 + public function getLanguage()
  141 + {
  142 + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]);
  143 + }
  144 + }
... ...
artweb/artbox-catalog/models/CategorySearch.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use yii\base\Model;
  6 + use yii\data\ActiveDataProvider;
  7 +
  8 + /**
  9 + * CategorySearch represents the model behind the search form about `backend\models\Category`.
  10 + */
  11 + class CategorySearch extends Category
  12 + {
  13 + public $title;
  14 +
  15 + public function behaviors()
  16 + {
  17 + return [];
  18 + }
  19 + /**
  20 + * @inheritdoc
  21 + */
  22 + public function rules()
  23 + {
  24 + return [
  25 + [
  26 + [
  27 + 'id',
  28 + 'image_id',
  29 + 'level',
  30 + 'sort',
  31 + 'created_at',
  32 + 'updated_at',
  33 + ],
  34 + 'integer',
  35 + ],
  36 + [
  37 + [ 'status' ],
  38 + 'boolean',
  39 + ],
  40 + [
  41 + [
  42 + 'title',
  43 + ],
  44 + 'string',
  45 + ],
  46 + ];
  47 + }
  48 +
  49 + /**
  50 + * @inheritdoc
  51 + */
  52 + public function scenarios()
  53 + {
  54 + // bypass scenarios() implementation in the parent class
  55 + return Model::scenarios();
  56 + }
  57 +
  58 + /**
  59 + * Creates data provider instance with search query applied
  60 + *
  61 + * @param array $params
  62 + *
  63 + * @return ActiveDataProvider
  64 + */
  65 + public function search($params)
  66 + {
  67 + $query = Category::find()
  68 + ->joinWith([ 'lang' ]);
  69 +
  70 + // add conditions that should always apply here
  71 +
  72 + $dataProvider = new ActiveDataProvider(
  73 + [
  74 + 'query' => $query,
  75 + ]
  76 + );
  77 +
  78 + $this->load($params);
  79 +
  80 + if (!$this->validate()) {
  81 + // uncomment the following line if you do not want to return any records when validation fails
  82 + // $query->where('0=1');
  83 + return $dataProvider;
  84 + }
  85 +
  86 + // grid filtering conditions
  87 + $query->andFilterWhere(
  88 + [
  89 + 'id' => $this->id,
  90 + 'level' => $this->level,
  91 + 'sort' => $this->sort,
  92 + 'status' => $this->status,
  93 + 'created_at' => $this->created_at,
  94 + 'updated_at' => $this->updated_at,
  95 + ]
  96 + )
  97 + ->andFilterWhere(
  98 + [
  99 + 'like',
  100 + 'category_lang.title',
  101 + $this->title,
  102 + ]
  103 + );
  104 +
  105 + return $dataProvider;
  106 + }
  107 + }
... ...
artweb/artbox-catalog/models/Event.php 0 → 100755
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: stes
  5 + * Date: 13.07.17
  6 + * Time: 17:11
  7 + */
  8 +
  9 +namespace artbox\catalog\models;
  10 +use yii\db\ActiveRecord;
  11 +use artbox\core\behaviors\LanguageBehavior;
  12 +use yii\behaviors\TimestampBehavior;
  13 +
  14 +class Event extends ActiveRecord
  15 +{
  16 + public static function tableName()
  17 + {
  18 + return 'event';
  19 + }
  20 + public function behaviors()
  21 + {
  22 + return [
  23 + 'language' => [
  24 + 'class' => LanguageBehavior::className(),
  25 + ],
  26 + ];
  27 + }
  28 +
  29 + public function getEventLangs()
  30 + {
  31 + return $this->hasMany(EventLang::className(), [ 'event_id' => 'id' ]);
  32 + }
  33 +}
0 34 \ No newline at end of file
... ...
artweb/artbox-catalog/models/EventLang.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace artbox\catalog\models;
  4 +
  5 +use Yii;
  6 +
  7 +/**
  8 + * This is the model class for table "event_lang".
  9 + *
  10 + * @property integer $event_id
  11 + * @property integer $language_id
  12 + * @property integer $alias_id
  13 + * @property string $title
  14 + * @property string $description
  15 + *
  16 + * @property Alias $alias
  17 + * @property Event $event
  18 + * @property Language $language
  19 + */
  20 +class EventLang extends \yii\db\ActiveRecord
  21 +{
  22 + /**
  23 + * @inheritdoc
  24 + */
  25 + public static function tableName()
  26 + {
  27 + return 'event_lang';
  28 + }
  29 +
  30 + /**
  31 + * @inheritdoc
  32 + */
  33 + public function rules()
  34 + {
  35 + return [
  36 + [['event_id', 'language_id', 'title'], 'required'],
  37 + [['event_id', 'language_id', 'alias_id'], 'integer'],
  38 + [['description'], 'string'],
  39 + [['title'], 'string', 'max' => 255],
  40 + [['alias_id'], 'exist', 'skipOnError' => true, 'targetClass' => Alias::className(), 'targetAttribute' => ['alias_id' => 'id']],
  41 + [['event_id'], 'exist', 'skipOnError' => true, 'targetClass' => Event::className(), 'targetAttribute' => ['event_id' => 'id']],
  42 + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'id']],
  43 + ];
  44 + }
  45 +
  46 + /**
  47 + * @inheritdoc
  48 + */
  49 + public function attributeLabels()
  50 + {
  51 + return [
  52 + 'event_id' => 'Event ID',
  53 + 'language_id' => 'Language ID',
  54 + 'alias_id' => 'Alias ID',
  55 + 'title' => 'Title',
  56 + 'description' => 'Description',
  57 + ];
  58 + }
  59 +
  60 + /**
  61 + * @return \yii\db\ActiveQuery
  62 + */
  63 + public function getAlias()
  64 + {
  65 + return $this->hasOne(Alias::className(), ['id' => 'alias_id']);
  66 + }
  67 +
  68 + /**
  69 + * @return \yii\db\ActiveQuery
  70 + */
  71 + public function getEvent()
  72 + {
  73 + return $this->hasOne(Event::className(), ['id' => 'event_id']);
  74 + }
  75 +
  76 + /**
  77 + * @return \yii\db\ActiveQuery
  78 + */
  79 + public function getLanguage()
  80 + {
  81 + return $this->hasOne(Language::className(), ['id' => 'language_id']);
  82 + }
  83 +}
... ...
artweb/artbox-catalog/models/Filter.php 0 → 100644
  1 +<?php
  2 + namespace artbox\catalog\models;
  3 +
  4 + use artbox\core\models\Alias;
  5 + use yii\base\Object;
  6 + use yii\db\ActiveQuery;
  7 + use yii\helpers\Json;
  8 +
  9 + /**
  10 + * Class Filter
  11 + * The stub class to identify dynamic filters
  12 + *
  13 + * @property bool $isTop
  14 + * @property bool $isNew
  15 + * @property bool $isSale
  16 + * @property bool $isExclusive
  17 + * @package artbox\catalog\models
  18 + */
  19 + class Filter extends Object
  20 + {
  21 + /**
  22 + * Stub property
  23 + *
  24 + * @var null
  25 + */
  26 + public $fields = null;
  27 +
  28 + protected $rewritedFilters = null;
  29 +
  30 + /**
  31 + * @var bool
  32 + */
  33 + public $isTop = '';
  34 +
  35 + /**
  36 + * @var bool
  37 + */
  38 + public $isNew = '';
  39 +
  40 + /**
  41 + * @var bool
  42 + */
  43 + public $isSale = '';
  44 +
  45 + /**
  46 + * @var bool
  47 + */
  48 + public $isExclusive = '';
  49 +
  50 + public function init()
  51 + {
  52 + $url = \Yii::$app->request->url;
  53 +
  54 + if (strpos($url, 'is-top')) {
  55 + $this->isTop = 'is-top';
  56 + }
  57 + if (strpos($url, 'is-new')) {
  58 + $this->isNew = 'is-new';
  59 + }
  60 + if (strpos($url, 'is-sale')) {
  61 + $this->isSale = 'is-sale';
  62 + }
  63 + if (strpos($url, 'is-excl')) {
  64 + $this->isExclusive = 'is-excl';
  65 + }
  66 +
  67 + $aliases = \Yii::$app->db->cache(
  68 + function () {
  69 + return Alias::find()
  70 + ->where(
  71 + [
  72 + 'entity' => self::className(),
  73 + ]
  74 + )
  75 + ->asArray()
  76 + ->all();
  77 + }
  78 + );
  79 +
  80 + $rewritedFilters = [];
  81 + foreach ($aliases as $alias) {
  82 + $element = Json::decode($alias[ 'route' ]);
  83 + /**
  84 + * @todo Fix hard coded 'catalog'
  85 + */
  86 + $filter = '/catalog/' . $element[ 'category' ] . '/' . $element[ 'filter' ];
  87 + $rewritedFilters[ $filter ] = '/' . $alias[ 'value' ];
  88 + }
  89 +
  90 + $this->rewritedFilters = $rewritedFilters;
  91 + }
  92 +
  93 + public function replaceFilterUrl(string $url)
  94 + {
  95 + $return = $url;
  96 + if (array_key_exists($url, $this->rewritedFilters)) {
  97 + $return = $this->rewritedFilters[ $url ];
  98 + }
  99 + if (preg_match('#^/catalog/[\w-]+/[\w-]+$#', $return)) {
  100 + if ($this->isTop) {
  101 + $return .= '_is-top';
  102 + }
  103 + if ($this->isNew) {
  104 + $return .= '_is-new';
  105 + }
  106 + if ($this->isSale) {
  107 + $return .= '_is-sale';
  108 + }
  109 + if ($this->isExclusive) {
  110 + $return .= '_is-excl';
  111 + }
  112 + }
  113 +
  114 + return $return;
  115 + }
  116 +
  117 + public function parseQuery(ActiveQuery $query)
  118 + {
  119 + if ($this->isTop) {
  120 + $query->andWhere('mask & 1 != 0');
  121 + }
  122 + if ($this->isNew) {
  123 + $query->andWhere('mask & 2 != 0');
  124 + }
  125 + if ($this->isSale) {
  126 + $query->andWhere('mask & 4 != 0');
  127 + }
  128 + if ($this->isExclusive) {
  129 + $query->andWhere('mask & 8 != 0');
  130 + }
  131 + }
  132 + }
0 133 \ No newline at end of file
... ...
artweb/artbox-catalog/models/Import.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use artbox\core\models\Image;
  6 + use yii\db\ActiveRecord;
  7 +
  8 + /**
  9 + * Class Import
  10 + *
  11 + * @package artbox\catalog\models
  12 + * @property string $category_name
  13 + * @property string $brand_name
  14 + * @property string $image_link
  15 + * @property string $image_name
  16 + * @property string $sku
  17 + * @property string $product_name
  18 + * @property Image $image
  19 + * @property Variant $variant
  20 + * @property CategoryLang $categoryLang
  21 + * @property BrandLang $brandLang
  22 + * @property string $description
  23 + * @property double $price
  24 + * @property double $price_old
  25 + * @property integer $stock
  26 + * @property integer $mask
  27 + * @property string $video
  28 + * @property string $characteristics
  29 + */
  30 + class Import extends ActiveRecord
  31 + {
  32 + public $categoryId = null;
  33 +
  34 + public $brandId = null;
  35 +
  36 + public $imageId = null;
  37 +
  38 + public $groups = [];
  39 +
  40 + /**
  41 + * @inheritdoc
  42 + */
  43 + public static function tableName()
  44 + {
  45 + return 'import';
  46 + }
  47 +
  48 + /**
  49 + * @return \yii\db\ActiveQuery
  50 + */
  51 + public function getVariant()
  52 + {
  53 + return $this->hasOne(Variant::className(), [ 'sku' => 'sku' ]);
  54 + }
  55 +
  56 + /**
  57 + * @return \yii\db\ActiveQuery
  58 + */
  59 + public function getCategoryLang()
  60 + {
  61 + return $this->hasOne(CategoryLang::className(), [ 'title' => 'category_name' ]);
  62 + }
  63 +
  64 + /**
  65 + * @return \yii\db\ActiveQuery
  66 + */
  67 + public function getBrandLang()
  68 + {
  69 + return $this->hasOne(BrandLang::className(), [ 'title' => 'brand_name' ]);
  70 + }
  71 +
  72 + /**
  73 + * @return \yii\db\ActiveQuery
  74 + */
  75 + public function getImage()
  76 + {
  77 + return $this->hasOne(Image::className(), [ 'fileName' => 'image_name' ]);
  78 + }
  79 + }
0 80 \ No newline at end of file
... ...
artweb/artbox-catalog/models/Option.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use artbox\core\behaviors\LanguageBehavior;
  6 + use artbox\core\models\Image;
  7 + use Yii;
  8 + use yii\behaviors\TimestampBehavior;
  9 + use yii\db\ActiveQuery;
  10 + use yii\db\ActiveRecord;
  11 + use yii\web\Request;
  12 +
  13 + /**
  14 + * This is the abstract model class for option models.
  15 + *
  16 + * @property integer $id
  17 + * @property integer $groupId
  18 + * @property integer $image_id
  19 + * @property integer $sort
  20 + * @property boolean $status
  21 + * @property integer $created_at
  22 + * @property integer $updated_at
  23 + * @property OptionGroup|null $group
  24 + * @property Image $image
  25 + * * From language behavior *
  26 + * @property OptionLang $lang
  27 + * @property OptionLang[] $langs
  28 + * @property OptionLang $objectLang
  29 + * @property string $ownerKey
  30 + * @property string $langKey
  31 + * @property OptionLang[] $modelLangs
  32 + * @property bool $transactionStatus
  33 + * @method string getOwnerKey()
  34 + * @method void setOwnerKey( string $value )
  35 + * @method string getLangKey()
  36 + * @method void setLangKey( string $value )
  37 + * @method ActiveQuery getLangs()
  38 + * @method ActiveQuery getLang( integer $language_id )
  39 + * @method OptionLang[] generateLangs()
  40 + * @method void loadLangs( Request $request )
  41 + * @method bool linkLangs()
  42 + * @method bool saveLangs()
  43 + * @method bool getTransactionStatus()
  44 + * @method bool loadWithLangs( Request $request )
  45 + * @method bool saveWithLangs()
  46 + * * End language behavior *
  47 + * @see LanguageBehavior
  48 + */
  49 + abstract class Option extends ActiveRecord
  50 + {
  51 +
  52 + /**
  53 + * @inheritdoc
  54 + */
  55 + public function behaviors()
  56 + {
  57 + return [
  58 + 'language' => [
  59 + 'class' => LanguageBehavior::className(),
  60 + ],
  61 + 'timestamp' => [
  62 + 'class' => TimestampBehavior::className(),
  63 + ],
  64 + ];
  65 + }
  66 +
  67 + /**
  68 + * @inheritdoc
  69 + */
  70 + public function rules()
  71 + {
  72 + return [
  73 + [
  74 + [
  75 + 'status',
  76 + ],
  77 + 'boolean',
  78 + ],
  79 + [
  80 + [
  81 + 'sort',
  82 + 'image_id',
  83 + ],
  84 + 'integer',
  85 + ],
  86 + [
  87 + [
  88 + 'image_id',
  89 + ],
  90 + 'exist',
  91 + 'targetClass' => Image::className(),
  92 + 'targetAttribute' => 'id',
  93 + ],
  94 + ];
  95 + }
  96 +
  97 + /**
  98 + * @inheritdoc
  99 + */
  100 + public function attributeLabels()
  101 + {
  102 + return [
  103 + 'id' => Yii::t('catalog', 'ID'),
  104 + 'groupId' => Yii::t('catalog', 'Group ID'),
  105 + 'image_id' => Yii::t('catalog', 'Image ID'),
  106 + 'sort' => Yii::t('catalog', 'Sort'),
  107 + 'status' => Yii::t('catalog', 'Status'),
  108 + 'created_at' => Yii::t('catalog', 'Created At'),
  109 + 'updated_at' => Yii::t('catalog', 'Updated At'),
  110 + ];
  111 + }
  112 +
  113 + /**
  114 + * Return ActiveQuery to get Image for exact Option if exist
  115 + *
  116 + * @return \yii\db\ActiveQuery
  117 + */
  118 + public function getImage()
  119 + {
  120 + return $this->hasOne(
  121 + Image::className(),
  122 + [
  123 + 'id' => 'image_id',
  124 + ]
  125 + );
  126 + }
  127 +
  128 + /**
  129 + * Get exact Option Group id value
  130 + *
  131 + * @return int|null
  132 + */
  133 + abstract public function getGroupId();
  134 +
  135 + /**
  136 + * Set Option Group link to Option model
  137 + *
  138 + * @param int $id
  139 + *
  140 + * @return void
  141 + */
  142 + abstract public function setGroupId(int $id);
  143 +
  144 + /**
  145 + * Get Group query
  146 + *
  147 + * @return \yii\db\ActiveQuery
  148 + */
  149 + abstract public function getGroup(): ActiveQuery;
  150 + }
... ...
artweb/artbox-catalog/models/OptionGroup.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use artbox\catalog\behaviors\ManyToManyBehavior;
  6 + use artbox\core\behaviors\LanguageBehavior;
  7 + use Yii;
  8 + use yii\behaviors\TimestampBehavior;
  9 + use yii\db\ActiveQuery;
  10 + use yii\db\ActiveRecord;
  11 + use yii\web\Request;
  12 +
  13 + /**
  14 + * This is the abstract model class for option group models.
  15 + *
  16 + * @property integer $id
  17 + * @property boolean $is_filter
  18 + * @property integer $sort
  19 + * @property boolean $status
  20 + * @property boolean $in_menu
  21 + * @property integer $created_at
  22 + * @property integer $updated_at
  23 + * @property Category[] $categories
  24 + * @property Option[] $options
  25 + * * From language behavior *
  26 + * @property OptionGroupLang $lang
  27 + * @property OptionGroupLang[] $langs
  28 + * @property OptionGroupLang $objectLang
  29 + * @property string $ownerKey
  30 + * @property string $langKey
  31 + * @property OptionGroupLang[] $modelLangs
  32 + * @property bool $transactionStatus
  33 + * @method string getOwnerKey()
  34 + * @method void setOwnerKey( string $value )
  35 + * @method string getLangKey()
  36 + * @method void setLangKey( string $value )
  37 + * @method ActiveQuery getLangs()
  38 + * @method ActiveQuery getLang( integer $language_id )
  39 + * @method OptionGroupLang[] generateLangs()
  40 + * @method void loadLangs( Request $request )
  41 + * @method bool linkLangs()
  42 + * @method bool saveLangs()
  43 + * @method bool getTransactionStatus()
  44 + * @method bool loadWithLangs( Request $request )
  45 + * @method bool saveWithLangs()
  46 + * * End language behavior *
  47 + * * From ManyToManyBehavior
  48 + * @method void linkMany( string $name, array $models, array $extraColumns = [] )
  49 + * * End ManyToManyBehavior
  50 + * @see LanguageBehavior
  51 + */
  52 + abstract class OptionGroup extends ActiveRecord
  53 + {
  54 +
  55 + public $categoryIds = [];
  56 +
  57 + /**
  58 + * @var Option[] $currentOptions Container for current options
  59 + */
  60 + public $currentOptions = [];
  61 +
  62 + /**
  63 + * @inheritdoc
  64 + */
  65 + public function behaviors()
  66 + {
  67 + return [
  68 + 'language' => [
  69 + 'class' => LanguageBehavior::className(),
  70 + ],
  71 + 'timestamp' => [
  72 + 'class' => TimestampBehavior::className(),
  73 + ],
  74 + [
  75 + 'class' => ManyToManyBehavior::className(),
  76 + ],
  77 + ];
  78 + }
  79 +
  80 + /**
  81 + * @inheritdoc
  82 + */
  83 + public function rules()
  84 + {
  85 + return [
  86 + [
  87 + [
  88 + 'is_filter',
  89 + 'status',
  90 + 'in_menu',
  91 + ],
  92 + 'boolean',
  93 + ],
  94 + [
  95 + [
  96 + 'sort',
  97 + ],
  98 + 'integer',
  99 + ],
  100 + ];
  101 + }
  102 +
  103 + /**
  104 + * @inheritdoc
  105 + */
  106 + public function attributeLabels()
  107 + {
  108 + return [
  109 + 'id' => Yii::t('catalog', 'ID'),
  110 + 'is_filter' => Yii::t('catalog', 'Is Filter'),
  111 + 'sort' => Yii::t('catalog', 'Sort'),
  112 + 'status' => Yii::t('catalog', 'Status'),
  113 + 'created_at' => Yii::t('catalog', 'Created At'),
  114 + 'updated_at' => Yii::t('catalog', 'Updated At'),
  115 + 'categories' => Yii::t('catalog', 'Categories'),
  116 + 'in_menu' => Yii::t('catalog', 'In menu'),
  117 + ];
  118 + }
  119 +
  120 + /**
  121 + * @param array $batch
  122 + *
  123 + * @return mixed
  124 + */
  125 + public abstract function insertCategories(array $batch);
  126 +
  127 + /**
  128 + * ActiveQuery to get categories for exact model
  129 + *
  130 + * @return ActiveQuery
  131 + */
  132 + public abstract function getCategories();
  133 +
  134 + /**
  135 + * ActiveQuery to get options for exact model
  136 + *
  137 + * @return ActiveQuery
  138 + */
  139 + public abstract function getOptions();
  140 + }
... ...
artweb/artbox-catalog/models/OptionGroupLang.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use artbox\core\models\Alias;
  6 + use artbox\core\models\Language;
  7 + use Yii;
  8 + use yii\db\ActiveRecord;
  9 +
  10 + /**
  11 + * This is the abstract model class for table Option Group Language models.
  12 + *
  13 + * @property integer $language_id
  14 + * @property string $title
  15 + * @property integer $alias_id
  16 + * @property string $description
  17 + *
  18 + * @property Alias $alias
  19 + * @property Language $language
  20 + */
  21 + abstract class OptionGroupLang extends ActiveRecord
  22 + {
  23 + /**
  24 + * @inheritdoc
  25 + */
  26 + public function rules()
  27 + {
  28 + return [
  29 + [
  30 + [
  31 + 'title',
  32 + ],
  33 + 'required',
  34 + ],
  35 + [
  36 + [ 'description' ],
  37 + 'string',
  38 + ],
  39 + [
  40 + [
  41 + 'title',
  42 + 'aliasValue',
  43 + ],
  44 + 'string',
  45 + 'max' => 255,
  46 + ],
  47 + ];
  48 + }
  49 +
  50 + /**
  51 + * @inheritdoc
  52 + */
  53 + public function attributeLabels()
  54 + {
  55 + return [
  56 + 'language_id' => Yii::t('catalog', 'Language ID'),
  57 + 'title' => Yii::t('catalog', 'Title'),
  58 + 'alias_id' => Yii::t('catalog', 'Alias ID'),
  59 + 'description' => Yii::t('catalog', 'Description'),
  60 + ];
  61 + }
  62 +
  63 + /**
  64 + * @return \yii\db\ActiveQuery
  65 + */
  66 + public function getAlias()
  67 + {
  68 + return $this->hasOne(Alias::className(), [ 'id' => 'alias_id' ]);
  69 + }
  70 +
  71 + /**
  72 + * @return \yii\db\ActiveQuery
  73 + */
  74 + public function getLanguage()
  75 + {
  76 + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]);
  77 + }
  78 + }
... ...
artweb/artbox-catalog/models/OptionGroupSearch.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use yii\base\Model;
  6 + use yii\data\ActiveDataProvider;
  7 + use yii\db\ActiveQuery;
  8 +
  9 + /**
  10 + * OptionGroupSearch represents the abstract search model for Option Groups.
  11 + */
  12 + abstract class OptionGroupSearch extends OptionGroup
  13 + {
  14 +
  15 + public $title;
  16 +
  17 + public $category;
  18 +
  19 + /**
  20 + * @inheritdoc
  21 + */
  22 + public function rules()
  23 + {
  24 + return [
  25 + [
  26 + [
  27 + 'id',
  28 + 'sort',
  29 + ],
  30 + 'integer',
  31 + ],
  32 + [
  33 + [
  34 + 'is_filter',
  35 + 'status',
  36 + 'in_menu',
  37 + ],
  38 + 'boolean',
  39 + ],
  40 + [
  41 + [
  42 + 'title',
  43 + 'category',
  44 + ],
  45 + 'safe',
  46 + ],
  47 + ];
  48 + }
  49 +
  50 + /**
  51 + * @inheritdoc
  52 + */
  53 + public function behaviors()
  54 + {
  55 + return [];
  56 + }
  57 +
  58 + /**
  59 + * @inheritdoc
  60 + */
  61 + public function scenarios()
  62 + {
  63 + // bypass scenarios() implementation in the parent class
  64 + return Model::scenarios();
  65 + }
  66 +
  67 + /**
  68 + * Creates data provider instance with search query applied
  69 + *
  70 + * @param array $params
  71 + *
  72 + * @return ActiveDataProvider
  73 + */
  74 + public function search($params)
  75 + {
  76 + $query = $this->createQuery()
  77 + ->joinWith(
  78 + [
  79 + 'lang',
  80 + 'categories.lang',
  81 + ]
  82 + );
  83 +
  84 + // add conditions that should always apply here
  85 +
  86 + $dataProvider = new ActiveDataProvider(
  87 + [
  88 + 'query' => $query,
  89 + 'pagination' => [
  90 + 'pageSize' => 50,
  91 + ],
  92 + ]
  93 + );
  94 + $this->load($params);
  95 +
  96 + if (!$this->validate()) {
  97 + // uncomment the following line if you do not want to return any records when validation fails
  98 + // $query->where('0=1');
  99 + return $dataProvider;
  100 + }
  101 +
  102 + // grid filtering conditions
  103 + $query->andFilterWhere(
  104 + [
  105 + 'id' => $this->id,
  106 + 'is_filter' => $this->is_filter,
  107 + 'sort' => $this->sort,
  108 + 'status' => $this->status,
  109 + 'in_menu' => $this->in_menu,
  110 + ]
  111 + );
  112 +
  113 + $query->andFilterWhere(
  114 + [
  115 + 'ilike',
  116 + 'category_lang.title',
  117 + $this->category,
  118 + ]
  119 + );
  120 +
  121 + return $dataProvider;
  122 + }
  123 +
  124 + /**
  125 + * @inheritdoc
  126 + */
  127 + public function getCategories()
  128 + {
  129 + return Category::find();
  130 + }
  131 +
  132 + /**
  133 + * @inheritdoc
  134 + */
  135 + public function getOptions()
  136 + {
  137 +
  138 + }
  139 +
  140 + /**
  141 + * Return ActiveQueyr for current model
  142 + *
  143 + * @return \yii\db\ActiveQuery
  144 + */
  145 + abstract protected function createQuery(): ActiveQuery;
  146 + }
... ...
artweb/artbox-catalog/models/OptionLang.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use artbox\core\models\Alias;
  6 + use artbox\core\models\Language;
  7 + use Yii;
  8 + use yii\db\ActiveRecord;
  9 +
  10 + /**
  11 + * This is the abstract model class for table Option Group Language models.
  12 + *
  13 + * @property integer $language_id
  14 + * @property string $value
  15 + * @property integer $alias_id
  16 + *
  17 + * @property Alias $alias
  18 + * @property Language $language
  19 + */
  20 + abstract class OptionLang extends ActiveRecord
  21 + {
  22 + /**
  23 + * @inheritdoc
  24 + */
  25 + public function rules()
  26 + {
  27 + return [
  28 + [
  29 + [
  30 + 'value',
  31 + ],
  32 + 'required',
  33 + ],
  34 + [
  35 + [
  36 + 'value',
  37 + 'aliasValue',
  38 + ],
  39 + 'string',
  40 + 'max' => 255,
  41 + ],
  42 + ];
  43 + }
  44 +
  45 + /**
  46 + * @inheritdoc
  47 + */
  48 + public function attributeLabels()
  49 + {
  50 + return [
  51 + 'language_id' => Yii::t('catalog', 'Language ID'),
  52 + 'value' => Yii::t('catalog', 'Value'),
  53 + 'alias_id' => Yii::t('catalog', 'Alias ID'),
  54 + ];
  55 + }
  56 +
  57 + /**
  58 + * @return \yii\db\ActiveQuery
  59 + */
  60 + public function getAlias()
  61 + {
  62 + return $this->hasOne(Alias::className(), [ 'id' => 'alias_id' ]);
  63 + }
  64 +
  65 + /**
  66 + * @return \yii\db\ActiveQuery
  67 + */
  68 + public function getLanguage()
  69 + {
  70 + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]);
  71 + }
  72 + }
... ...
artweb/artbox-catalog/models/OptionSearch.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use yii\base\Model;
  6 + use yii\data\ActiveDataProvider;
  7 + use yii\db\ActiveQuery;
  8 +
  9 + /**
  10 + * OptionSearch represents the abstract search model for Option models.
  11 + */
  12 + abstract class OptionSearch extends Option
  13 + {
  14 +
  15 + public $value;
  16 +
  17 + /**
  18 + * @inheritdoc
  19 + */
  20 + public function rules()
  21 + {
  22 + return [
  23 + [
  24 + [
  25 + 'id',
  26 + 'sort',
  27 + ],
  28 + 'integer',
  29 + ],
  30 + [
  31 + [
  32 + 'status',
  33 + ],
  34 + 'boolean',
  35 + ],
  36 + [
  37 + [
  38 + 'value',
  39 + ],
  40 + 'safe',
  41 + ],
  42 + ];
  43 + }
  44 +
  45 + /**
  46 + * @inheritdoc
  47 + */
  48 + public function behaviors()
  49 + {
  50 + return [];
  51 + }
  52 +
  53 + /**
  54 + * @inheritdoc
  55 + */
  56 + public function scenarios()
  57 + {
  58 + // bypass scenarios() implementation in the parent class
  59 + return Model::scenarios();
  60 + }
  61 +
  62 + /**
  63 + * Creates data provider instance with search query applied
  64 + *
  65 + * @param array $params
  66 + *
  67 + * @param OptionGroup $group
  68 + *
  69 + * @return \yii\data\ActiveDataProvider
  70 + */
  71 + public function search($params, $group)
  72 + {
  73 + $query = $this->createQuery()
  74 + ->joinWith('lang');
  75 +
  76 + // add conditions that should always apply here
  77 +
  78 + $dataProvider = new ActiveDataProvider(
  79 + [
  80 + 'query' => $query,
  81 + ]
  82 + );
  83 + $this->load($params);
  84 +
  85 + if (!$this->validate()) {
  86 + // uncomment the following line if you do not want to return any records when validation fails
  87 + // $query->where('0=1');
  88 + return $dataProvider;
  89 + }
  90 +
  91 + // grid filtering conditions
  92 + $query->andFilterWhere(
  93 + [
  94 + 'id' => $this->id,
  95 + 'sort' => $this->sort,
  96 + 'status' => $this->status,
  97 + ]
  98 + );
  99 +
  100 + return $dataProvider;
  101 + }
  102 +
  103 + /**
  104 + * Return ActiveQuery for current model
  105 + *
  106 + * @return \yii\db\ActiveQuery
  107 + */
  108 + abstract protected function createQuery(): ActiveQuery;
  109 +
  110 + /**
  111 + * @inheritdoc
  112 + */
  113 + public function getGroupId()
  114 + {
  115 +
  116 + }
  117 +
  118 + /**
  119 + * @inheritdoc
  120 + */
  121 + public function setGroupId(int $id)
  122 + {
  123 +
  124 + }
  125 +
  126 + /**
  127 + * @inheritdoc
  128 + */
  129 + public function getGroup(): ActiveQuery
  130 + {
  131 + return new ActiveQuery(self::className());
  132 + }
  133 + }
... ...
artweb/artbox-catalog/models/PriceUpload.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace artbox\catalog\models;
  4 +
  5 +
  6 +/**
  7 + * This is the model class for table "price_upload".
  8 + *
  9 + * @property string $sku
  10 + * @property string $price
  11 + * @property string $price_old
  12 + */
  13 +class PriceUpload extends \yii\db\ActiveRecord
  14 +{
  15 + /**
  16 + * @inheritdoc
  17 + */
  18 + public static function tableName()
  19 + {
  20 + return 'price_upload';
  21 + }
  22 +
  23 + /**
  24 + * @inheritdoc
  25 + */
  26 + public function rules()
  27 + {
  28 + return [
  29 + [['sku'], 'required'],
  30 + [['price', 'price_old'], 'number'],
  31 + [['sku'], 'string', 'max' => 255],
  32 + ];
  33 + }
  34 +
  35 + /**
  36 + * @inheritdoc
  37 + */
  38 + public function attributeLabels()
  39 + {
  40 + return [
  41 + 'sku' => 'Sku',
  42 + 'price' => 'Price',
  43 + 'price_old' => 'Price Old',
  44 + ];
  45 + }
  46 +}
... ...
artweb/artbox-catalog/models/Product.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use artbox\catalog\behaviors\DefaultVariantBehavior;
  6 + use artbox\catalog\behaviors\ManyToManyBehavior;
  7 + use artbox\catalog\models\queries\ProductQuery;
  8 + use artbox\core\behaviors\BitMaskBehavior;
  9 + use artbox\core\behaviors\GalleryBehavior;
  10 + use artbox\core\behaviors\LanguageBehavior;
  11 + use artbox\core\models\Image;
  12 + use artbox\core\models\Language;
  13 + use Yii;
  14 + use yii\behaviors\TimestampBehavior;
  15 + use yii\db\ActiveQuery;
  16 + use yii\db\ActiveRecord;
  17 + use yii\helpers\ArrayHelper;
  18 + use yii\web\Request;
  19 +
  20 + /**
  21 + * This is the model class for table "product".
  22 + *
  23 + * @property integer $id
  24 + * @property integer $brand_id
  25 + * @property string $video
  26 + * @property integer $mask
  27 + * @property boolean $status
  28 + * @property integer $sort
  29 + * @property integer $created_at
  30 + * @property integer $updated_at
  31 + * @property integer $image_id
  32 + * @property Image $image
  33 + * @property Brand $brand
  34 + * @property ProductLang[] $productLangs
  35 + * @property Language[] $languages
  36 + * @property ProductToCategory[] $productToCategories
  37 + * @property Category[] $categories
  38 + * @property Category $category
  39 + * @property ProductToImage[] $productToImages
  40 + * @property Image[] $images
  41 + * @property ProductToProductOptionCompl[] $productToProductOptionCompls
  42 + * @property ProductOptionCompl[] $productOptionCompls
  43 + * @property ProductToProductOptionExcl[] $productToProductOptionExcls
  44 + * @property ProductOptionExcl[] $productOptionExcls
  45 + * @property Variant[] $variants
  46 + * @property Variant $variant
  47 + * @property \artbox\catalog\models\ProductRecommend[] $productRecommends
  48 + * @property \artbox\catalog\models\Product[] $recommendedProducts
  49 + * * From language behavior *
  50 + * @property ProductLang $lang
  51 + * @property ProductLang[] $langs
  52 + * @property ProductLang $objectLang
  53 + * @property string $ownerKey
  54 + * @property string $langKey
  55 + * @property ProductLang[] $modelLangs
  56 + * @property bool $transactionStatus
  57 + * @method string getOwnerKey()
  58 + * @method void setOwnerKey( string $value )
  59 + * @method string getLangKey()
  60 + * @method void setLangKey( string $value )
  61 + * @method ActiveQuery getLangs()
  62 + * @method ActiveQuery getLang( integer $language_id )
  63 + * @method ProductLang[] generateLangs()
  64 + * @method void loadLangs( Request $request )
  65 + * @method bool linkLangs()
  66 + * @method bool saveLangs()
  67 + * @method bool getTransactionStatus()
  68 + * @method bool loadWithLangs( Request $request )
  69 + * @method bool saveWithLangs()
  70 + * * End language behavior *
  71 + * @see LanguageBehavior
  72 + * @method void linkMany( string $name, array $models )
  73 + * @method void loadMask( Request $request )
  74 + * @method bool is( string $field )
  75 + */
  76 + class Product extends ActiveRecord
  77 + {
  78 + public $categoryIds = [];
  79 + public $recommendIds = [];
  80 +
  81 + /**
  82 + * @return ProductQuery the active query used by this AR class.
  83 + */
  84 + public static function find()
  85 + {
  86 + return new ProductQuery(get_called_class());
  87 + }
  88 +
  89 + /**
  90 + * @inheritdoc
  91 + */
  92 + public static function tableName()
  93 + {
  94 + return 'product';
  95 + }
  96 +
  97 + /**
  98 + * @inheritdoc
  99 + */
  100 + public function behaviors()
  101 + {
  102 + return [
  103 + 'language' => [
  104 + 'class' => LanguageBehavior::className(),
  105 + ],
  106 + 'timestamp' => [
  107 + 'class' => TimestampBehavior::className(),
  108 + ],
  109 + [
  110 + 'class' => ManyToManyBehavior::className(),
  111 + ],
  112 + 'defaultVariant' => [
  113 + 'class' => DefaultVariantBehavior::className(),
  114 + ],
  115 + [
  116 + 'class' => BitMaskBehavior::className(),
  117 + 'fields' => [
  118 + 'top' => 0,
  119 + 'new' => 1,
  120 + 'akcia' => 2,
  121 + ],
  122 + ],
  123 + [
  124 + 'class' => GalleryBehavior::className(),
  125 + ],
  126 + ];
  127 + }
  128 +
  129 + /**
  130 + * @inheritdoc
  131 + */
  132 + public function rules()
  133 + {
  134 + return [
  135 + [
  136 + [
  137 + 'brand_id',
  138 + 'mask',
  139 + 'sort',
  140 + 'image_id',
  141 + ],
  142 + 'integer',
  143 + ],
  144 + [
  145 + [
  146 + 'video',
  147 + 'gallery',
  148 + ],
  149 + 'string',
  150 + ],
  151 + [
  152 + [ 'status' ],
  153 + 'boolean',
  154 + ],
  155 + [
  156 + [ 'brand_id' ],
  157 + 'exist',
  158 + 'skipOnError' => true,
  159 + 'targetClass' => Brand::className(),
  160 + 'targetAttribute' => [ 'brand_id' => 'id' ],
  161 + ],
  162 + [
  163 + [
  164 + 'productOptionCompls',
  165 + 'productOptionExcls',
  166 + ],
  167 + 'safe',
  168 + ],
  169 + ];
  170 + }
  171 +
  172 + /**
  173 + * @inheritdoc
  174 + */
  175 + public function attributeLabels()
  176 + {
  177 + return [
  178 + 'id' => Yii::t('catalog', 'ID'),
  179 + 'brand_id' => Yii::t('catalog', 'Brand ID'),
  180 + 'video' => Yii::t('catalog', 'Video'),
  181 + 'mask' => Yii::t('catalog', 'Mask'),
  182 + 'status' => Yii::t('catalog', 'Status'),
  183 + 'sort' => Yii::t('catalog', 'Sort'),
  184 + 'created_at' => Yii::t('catalog', 'Created At'),
  185 + 'updated_at' => Yii::t('catalog', 'Updated At'),
  186 + 'image_id' => Yii::t('catalog', 'Image'),
  187 + ];
  188 + }
  189 +
  190 + /**
  191 + * @return \yii\db\ActiveQuery
  192 + */
  193 + public function getBrand()
  194 + {
  195 + return $this->hasOne(Brand::className(), [ 'id' => 'brand_id' ])
  196 + ->inverseOf('products');
  197 + }
  198 +
  199 + /**
  200 + * @return \yii\db\ActiveQuery
  201 + */
  202 + public function getProductLangs()
  203 + {
  204 + return $this->hasMany(ProductLang::className(), [ 'product_id' => 'id' ])
  205 + ->inverseOf('product');
  206 + }
  207 +
  208 + /**
  209 + * @return \yii\db\ActiveQuery
  210 + */
  211 + public function getLanguages()
  212 + {
  213 + return $this->hasMany(Language::className(), [ 'id' => 'language_id' ])
  214 + ->viaTable('product_lang', [ 'product_id' => 'id' ]);
  215 + }
  216 +
  217 + /**
  218 + * @return \yii\db\ActiveQuery
  219 + */
  220 + public function getProductToCategories()
  221 + {
  222 + return $this->hasMany(ProductToCategory::className(), [ 'product_id' => 'id' ])
  223 + ->inverseOf('product');
  224 + }
  225 +
  226 + /**
  227 + * @return \yii\db\ActiveQuery
  228 + */
  229 + public function getCategories()
  230 + {
  231 + return $this->hasMany(Category::className(), [ 'id' => 'category_id' ])
  232 + ->viaTable('product_to_category', [ 'product_id' => 'id' ]);
  233 + }
  234 +
  235 + /**
  236 + * @return ActiveQuery
  237 + */
  238 + public function getCategory()
  239 + {
  240 + return $this->hasOne(Category::className(), [ 'id' => 'category_id' ])
  241 + ->viaTable('product_to_category', [ 'product_id' => 'id' ]);
  242 + }
  243 +
  244 + /**
  245 + * @return \yii\db\ActiveQuery
  246 + */
  247 + public function getProductToImages()
  248 + {
  249 + return $this->hasMany(ProductToImage::className(), [ 'product_id' => 'id' ])
  250 + ->inverseOf('product');
  251 + }
  252 +
  253 + /**
  254 + * @return \yii\db\ActiveQuery
  255 + */
  256 +// public function getImages()
  257 +// {
  258 +// return $this->hasMany(Image::className(), [ 'id' => 'image_id' ])
  259 +// ->viaTable('product_to_image', [ 'product_id' => 'id' ]);
  260 +// }
  261 +
  262 + /**
  263 + * @return \yii\db\ActiveQuery
  264 + */
  265 + public function getProductToProductOptionCompls()
  266 + {
  267 + return $this->hasMany(ProductToProductOptionCompl::className(), [ 'product_id' => 'id' ])
  268 + ->inverseOf('product');
  269 + }
  270 +
  271 + /**
  272 + * @return \yii\db\ActiveQuery
  273 + */
  274 + public function getProductOptionCompls()
  275 + {
  276 + return $this->hasMany(ProductOptionCompl::className(), [ 'id' => 'product_option_compl_id' ])
  277 + ->viaTable('product_to_product_option_compl', [ 'product_id' => 'id' ]);
  278 + }
  279 +
  280 + /**
  281 + * @return \yii\db\ActiveQuery
  282 + */
  283 + public function getProductToProductOptionExcls()
  284 + {
  285 + return $this->hasMany(ProductToProductOptionExcl::className(), [ 'product_id' => 'id' ])
  286 + ->inverseOf('product');
  287 + }
  288 +
  289 + /**
  290 + * @return \yii\db\ActiveQuery
  291 + */
  292 + public function getProductOptionExcls()
  293 + {
  294 + return $this->hasMany(ProductOptionExcl::className(), [ 'id' => 'product_option_excl_id' ])
  295 + ->viaTable('product_to_product_option_excl', [ 'product_id' => 'id' ]);
  296 + }
  297 +
  298 + /**
  299 + * @return \yii\db\ActiveQuery
  300 + */
  301 + public function getVariants()
  302 + {
  303 + return $this->hasMany(Variant::className(), [ 'product_id' => 'id' ])
  304 + ->inverseOf('product');
  305 + }
  306 +
  307 + public function getVariant()
  308 + {
  309 + return $this->hasOne(Variant::className(), [ 'product_id' => 'id' ])
  310 + ->inverseOf('product');
  311 + }
  312 +
  313 + /**
  314 + * Setter for Product Options Complementary
  315 + *
  316 + * @param $value
  317 + */
  318 + public function setProductOptionCompls($value)
  319 + {
  320 + $this->productOptionCompls = $value;
  321 + }
  322 +
  323 + /**
  324 + * Setter for Product Options Exclusion
  325 + *
  326 + * @param $value
  327 + */
  328 + public function setProductOptionExcls($value)
  329 + {
  330 + $this->productOptionExcls = $value;
  331 + }
  332 +
  333 + /**
  334 + * @return \yii\db\ActiveQuery
  335 + */
  336 + public function getImage()
  337 + {
  338 + return $this->hasOne(Image::className(), [ 'id' => 'image_id' ]);
  339 + }
  340 +
  341 + public function getSimilarProducts(int $limit = 10)
  342 + {
  343 +
  344 + $poc = ArrayHelper::getColumn($this->productToProductOptionCompls, 'product_option_compl_id');
  345 + $poe = ArrayHelper::getColumn($this->productToProductOptionExcls, 'product_option_excl_id');
  346 +
  347 +
  348 + $query_compl = self::find()
  349 + ->with('variants.image', 'lang')
  350 + ->with('variant', 'variant.variantOptionCompls', 'variant.image')
  351 + ->with(['variant.variantOptionExcls' => function (ActiveQuery $query){
  352 + $query->with('group', 'group.lang', 'lang');
  353 + }])
  354 + ->with('category', 'category.lang')
  355 + ->with('brand', 'brand.lang')
  356 + ->innerJoinWith('productToCategories', false)
  357 + ->joinWith('productToProductOptionCompls', false)
  358 + ->with(['productOptionExcls' => function (ActiveQuery $query){
  359 + $query->with('group', 'group.lang', 'lang');
  360 + }])
  361 + ->with(['productOptionCompls' => function (ActiveQuery $query){
  362 + $query->with('group', 'group.lang', 'lang');
  363 + }])
  364 + ->andWhere([ 'product_to_product_option_compl.product_option_compl_id' => $poc ])
  365 + ->andWhere(
  366 + [
  367 + 'not',
  368 + [
  369 + 'product.id' => $this->id,
  370 + ],
  371 + ]
  372 + );
  373 +
  374 + $query_excl = self::find()
  375 + ->with('variants.image', 'lang')
  376 + ->with('brand', 'brand.lang')
  377 + ->with('variant', 'variant.variantOptionCompls', 'variant.image')
  378 + ->with(['variant.variantOptionExcls' => function (ActiveQuery $query){
  379 + $query->with('group', 'group.lang', 'lang');
  380 + }])
  381 + ->with(['productOptionCompls' => function (ActiveQuery $query){
  382 + $query->with('group', 'group.lang', 'lang');
  383 + }])
  384 + ->with('category', 'category.lang')
  385 + ->innerJoinWith('productToCategories', false)
  386 + ->joinWith('productToProductOptionExcls', false)
  387 + ->with(['productOptionExcls' => function (ActiveQuery $query){
  388 + $query->with('group', 'group.lang', 'lang');
  389 + }])
  390 + ->andWhere([ 'product_to_product_option_excl.product_option_excl_id' => $poe ])
  391 + ->andWhere(
  392 + [
  393 + 'not',
  394 + [
  395 + 'product.id' => $this->id,
  396 + ],
  397 + ]
  398 + )
  399 + ->limit(8);
  400 +
  401 + if (class_exists('\artbox\stock\models\VariantToShop')){
  402 + $query_compl->with('variant.counts');
  403 + $query_excl->with('variant.counts');
  404 + }
  405 + $result = $query_compl->union($query_excl, false)
  406 + ->limit($limit);
  407 + return $result->all();
  408 + }
  409 +
  410 + /**
  411 + * @return ActiveQuery
  412 + */
  413 + public static function findWithFilters()
  414 + {
  415 + return self::find()
  416 + ->with(
  417 + [
  418 + 'productOptionCompls' => function ($query) {
  419 + /**
  420 + * @var ActiveQuery $query
  421 + */
  422 + $query->with('lang')
  423 + ->with('group.lang');
  424 + },
  425 + ]
  426 + )
  427 + ->with(
  428 + [
  429 + 'productOptionExcls' => function ($query) {
  430 + /**
  431 + * @var ActiveQuery $query
  432 + */
  433 + $query->with('lang')
  434 + ->with('group.lang');
  435 + },
  436 + ]
  437 + )
  438 + ->with(
  439 + [
  440 + 'variants' => function ($query) {
  441 + /**
  442 + * @var ActiveQuery $query
  443 + */
  444 + $query->with(
  445 + [
  446 + 'variantOptionCompls' => function ($query) {
  447 + /**
  448 + * @var ActiveQuery $query
  449 + */
  450 + $query->with('lang')
  451 + ->with('group.lang');
  452 + },
  453 + ]
  454 + )
  455 + ->with(
  456 + [
  457 + 'variantOptionExcls' => function ($query) {
  458 + /**
  459 + * @var ActiveQuery $query
  460 + */
  461 + $query->with('lang')
  462 + ->with('group.lang');
  463 + },
  464 + ]
  465 + )
  466 + ->with('lang');
  467 + },
  468 + ]
  469 + );
  470 + }
  471 +
  472 + /**
  473 + * Get ProductRecommends
  474 + *
  475 + * @return ActiveQuery
  476 + */
  477 + public function getProductRecommends()
  478 + {
  479 + return $this->hasMany(ProductRecommend::className(), [ 'product_id' => 'id' ]);
  480 + }
  481 +
  482 + /**
  483 + * Get recommended Products
  484 + *
  485 + * @return ActiveQuery
  486 + */
  487 + public function getRecommendedProducts()
  488 + {
  489 + return $this->hasMany(Product::className(), [ 'id' => 'recommend_id' ])
  490 + ->via('productRecommends');
  491 + }
  492 +
  493 + public function getRelatedArticles()
  494 + {
  495 + if (class_exists('\artbox\weblog\models\Article')) {
  496 + return $this->hasMany('\artbox\weblog\models\Article', [ 'id' => 'article_id' ])->viaTable('article_to_product', [
  497 + 'product_id' => 'id'
  498 + ]);
  499 + } else {
  500 + return null;
  501 + }
  502 + }
  503 +
  504 + public function getEvent(){
  505 + return $this->hasMany(Event::className(), [ 'id' => 'event_id' ])->viaTable('product_to_event', [
  506 + 'product_id' => 'id'
  507 + ]);
  508 + }
  509 + }
... ...
artweb/artbox-catalog/models/ProductLang.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use artbox\core\behaviors\SlugBehavior;
  6 + use artbox\core\models\Alias;
  7 + use artbox\core\models\Language;
  8 + use Yii;
  9 + use yii\db\ActiveRecord;
  10 +
  11 + /**
  12 + * This is the model class for table "product_lang".
  13 + *
  14 + * @property integer $product_id
  15 + * @property integer $language_id
  16 + * @property string $title
  17 + * @property integer $alias_id
  18 + * @property string $description
  19 + *
  20 + * @property Alias $alias
  21 + * @property Language $language
  22 + * @property Product $product
  23 + */
  24 + class ProductLang extends ActiveRecord
  25 + {
  26 + /**
  27 + * @inheritdoc
  28 + */
  29 + public static function tableName()
  30 + {
  31 + return 'product_lang';
  32 + }
  33 +
  34 + /**
  35 + * @inheritdoc
  36 + */
  37 + public function behaviors()
  38 + {
  39 + return [
  40 + 'slug' => [
  41 + 'class' => SlugBehavior::className(),
  42 + 'action' => 'product/view',
  43 + 'params' => [
  44 + 'id' => 'product_id',
  45 + ],
  46 + 'fields' => [
  47 + 'title' => \Yii::t('catalog', 'Product title'),
  48 + 'description' => \Yii::t('catalog', 'Product description'),
  49 + ],
  50 + ],
  51 + ];
  52 + }
  53 +
  54 + /**
  55 + * @inheritdoc
  56 + */
  57 + public function rules()
  58 + {
  59 + return [
  60 + [
  61 + [
  62 + 'title',
  63 + ],
  64 + 'required',
  65 + ],
  66 + [
  67 + [ 'description' ],
  68 + 'string',
  69 + ],
  70 + [
  71 + [
  72 + 'title',
  73 + 'aliasValue',
  74 + ],
  75 + 'string',
  76 + 'max' => 255,
  77 + ],
  78 + ];
  79 + }
  80 +
  81 + /**
  82 + * @inheritdoc
  83 + */
  84 + public function attributeLabels()
  85 + {
  86 + return [
  87 + 'product_id' => Yii::t('catalog', 'Product ID'),
  88 + 'language_id' => Yii::t('catalog', 'Language ID'),
  89 + 'title' => Yii::t('catalog', 'Title'),
  90 + 'alias_id' => Yii::t('catalog', 'Alias ID'),
  91 + 'description' => Yii::t('catalog', 'Description'),
  92 + ];
  93 + }
  94 +
  95 + /**
  96 + * @return \yii\db\ActiveQuery
  97 + */
  98 + public function getAlias()
  99 + {
  100 + return $this->hasOne(Alias::className(), [ 'id' => 'alias_id' ]);
  101 + }
  102 +
  103 + /**
  104 + * @return \yii\db\ActiveQuery
  105 + */
  106 + public function getLanguage()
  107 + {
  108 + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]);
  109 + }
  110 +
  111 + /**
  112 + * @return \yii\db\ActiveQuery
  113 + */
  114 + public function getProduct()
  115 + {
  116 + return $this->hasOne(Product::className(), [ 'id' => 'product_id' ])
  117 + ->inverseOf('productLangs');
  118 + }
  119 + }
... ...
artweb/artbox-catalog/models/ProductOptionCompl.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use artbox\core\models\Language;
  6 + use yii\db\ActiveQuery;
  7 +
  8 + /**
  9 + * This is the model class for table "product_option_compl".
  10 + *
  11 + * @property integer $product_option_group_compl_id
  12 + *
  13 + * @property ProductOptionGroupCompl $productOptionGroupCompl
  14 + * @property ProductOptionComplLang[] $productOptionComplLangs
  15 + * @property Language[] $languages
  16 + * @property ProductOptionComplToCategory[] $productOptionComplToCategories
  17 + * @property Category[] $categories
  18 + * @property ProductToProductOptionCompl[] $productToProductOptionCompls
  19 + * @property Product[] $products
  20 + */
  21 + class ProductOptionCompl extends Option
  22 + {
  23 + /**
  24 + * @inheritdoc
  25 + */
  26 + public static function tableName()
  27 + {
  28 + return 'product_option_compl';
  29 + }
  30 +
  31 + /**
  32 + * @return \yii\db\ActiveQuery
  33 + */
  34 + public function getProductOptionGroupCompl()
  35 + {
  36 + return $this->hasOne(ProductOptionGroupCompl::className(), [ 'id' => 'product_option_group_compl_id' ])
  37 + ->inverseOf('productOptionCompls');
  38 + }
  39 +
  40 + /**
  41 + * @return \yii\db\ActiveQuery
  42 + */
  43 + public function getProductOptionComplLangs()
  44 + {
  45 + return $this->hasMany(ProductOptionComplLang::className(), [ 'product_option_compl_id' => 'id' ])
  46 + ->inverseOf('productOptionCompl');
  47 + }
  48 +
  49 + /**
  50 + * @return \yii\db\ActiveQuery
  51 + */
  52 + public function getLanguages()
  53 + {
  54 + return $this->hasMany(Language::className(), [ 'id' => 'language_id' ])
  55 + ->viaTable('product_option_compl_lang', [ 'product_option_compl_id' => 'id' ]);
  56 + }
  57 +
  58 + /**
  59 + * @return \yii\db\ActiveQuery
  60 + */
  61 + public function getProductOptionComplToCategories()
  62 + {
  63 + return $this->hasMany(ProductOptionComplToCategory::className(), [ 'product_option_compl_id' => 'id' ])
  64 + ->inverseOf('productOptionCompl');
  65 + }
  66 +
  67 + /**
  68 + * @return \yii\db\ActiveQuery
  69 + */
  70 + public function getCategories()
  71 + {
  72 + return $this->hasMany(Category::className(), [ 'id' => 'category_id' ])
  73 + ->viaTable('product_option_compl_to_category', [ 'product_option_compl_id' => 'id' ]);
  74 + }
  75 +
  76 + /**
  77 + * @return \yii\db\ActiveQuery
  78 + */
  79 + public function getProductToProductOptionCompls()
  80 + {
  81 + return $this->hasMany(ProductToProductOptionCompl::className(), [ 'product_option_compl_id' => 'id' ])
  82 + ->inverseOf('productOptionCompl');
  83 + }
  84 +
  85 + /**
  86 + * @return \yii\db\ActiveQuery
  87 + */
  88 + public function getProducts()
  89 + {
  90 + return $this->hasMany(Product::className(), [ 'id' => 'product_id' ])
  91 + ->viaTable('product_to_product_option_compl', [ 'product_option_compl_id' => 'id' ]);
  92 + }
  93 + /**
  94 + * Get exact Option Group id value
  95 + *
  96 + * @return int|null
  97 + */
  98 + public function getGroupId()
  99 + {
  100 + return $this->product_option_group_compl_id;
  101 + }
  102 + /**
  103 + * Set Option Group link to Option model
  104 + *
  105 + * @param int $id
  106 + *
  107 + * @return void
  108 + */
  109 + public function setGroupId(int $id)
  110 + {
  111 + $this->product_option_group_compl_id = $id;
  112 + }
  113 + /**
  114 + * Get Group query
  115 + *
  116 + * @return \yii\db\ActiveQuery
  117 + */
  118 + public function getGroup(): ActiveQuery
  119 + {
  120 + return $this->getProductOptionGroupCompl()
  121 + ->inverseOf('options');
  122 + }
  123 + }
... ...
artweb/artbox-catalog/models/ProductOptionComplLang.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use artbox\core\behaviors\SlugBehavior;
  6 +
  7 + /**
  8 + * This is the model class for table "product_option_compl_lang".
  9 + *
  10 + * @property integer $product_option_compl_id
  11 + *
  12 + * @property ProductOptionCompl $productOptionCompl
  13 + */
  14 + class ProductOptionComplLang extends OptionLang
  15 + {
  16 + /**
  17 + * @inheritdoc
  18 + */
  19 + public static function tableName()
  20 + {
  21 + return 'product_option_compl_lang';
  22 + }
  23 +
  24 + /**
  25 + * @inheritdoc
  26 + */
  27 + public function behaviors()
  28 + {
  29 + return [
  30 + 'slug' => [
  31 + 'class' => SlugBehavior::className(),
  32 + 'inAttribute' => 'value',
  33 + 'action' => 'product-option-complementary/view',
  34 + 'params' => [
  35 + 'id' => 'product_option_compl_id',
  36 + ],
  37 + 'fields' => [
  38 + 'title' => \Yii::t('catalog', 'Option title'),
  39 + 'description' => \Yii::t('catalog', 'Option description'),
  40 + ],
  41 + ],
  42 + ];
  43 + }
  44 +
  45 + /**
  46 + * @return \yii\db\ActiveQuery
  47 + */
  48 + public function getProductOptionCompl()
  49 + {
  50 + return $this->hasOne(ProductOptionCompl::className(), [ 'id' => 'product_option_compl_id' ])
  51 + ->inverseOf('productOptionComplLangs');
  52 + }
  53 + }
... ...
artweb/artbox-catalog/models/ProductOptionComplSearch.php 0 → 100755
  1 +<?php
  2 +
  3 + namespace artbox\catalog\models;
  4 +
  5 + use yii\db\ActiveQuery;
  6 +
  7 + /**
  8 + * ProductOptionComplSearch represents the model behind the search form about
  9 + * `artbox\catalog\models\ProductOptionCompl`.
  10 + */
  11 + class ProductOptionComplSearch extends OptionSearch
  12 + {
  13 + /**
  14 + * @inheritdoc
  15 + */
  16 + public static function tableName()
  17 + {
  18 + return ProductOptionCompl::tableName();
  19 + }
  20 +
  21 + /**
  22 + * @inheritdoc
  23 + */
  24 + public function search($params, $group)
  25 + {
  26 + $dataProvider = parent::search($params, $group);
  27 + $dataProvider->query->andWhere(
  28 + [
  29 + 'product_option_group_compl_id' => $group->id,
  30 + ]
  31 + );
  32 + $dataProvider->query->andFilterWhere(
  33 + [
  34 + 'ilike',
  35 + 'product_option_compl_lang.value',
  36 + $this->value,
  37 + ]
  38 + );
  39 + $dataProvider->sort = [
  40 + 'attributes' => [
  41 + 'id',
  42 + 'value' => [
  43 + 'asc' => [ 'product_option_compl_lang.value' => SORT_ASC ],
  44 + 'desc' => [ 'product_option_compl_lang.value' => SORT_DESC ],
  45 + ],
  46 + 'created_at',
  47 + 'is_filter',
  48 + 'status',
  49 + 'sort',
  50 + ],
  51 + ];
  52 + return $dataProvider;
  53 + }
  54 +
  55 + /**
  56 + * Return ActiveQuery for current model
  57 + *
  58 + * @return \yii\db\ActiveQuery
  59 + */
  60 + protected function createQuery(): ActiveQuery
  61 + {
  62 + return ProductOptionCompl::find();
  63 + }
  64 + }
... ...