Commit 01b711c81f2b09d44fb5c060e7c11b15a358abe5
1 parent
91fc4901
Synonyms
Showing
11 changed files
with
685 additions
and
479 deletions
Show diff stats
backend/views/category/_form.php
| @@ -20,8 +20,10 @@ use kartik\select2\Select2; | @@ -20,8 +20,10 @@ use kartik\select2\Select2; | ||
| 20 | ]); ?> | 20 | ]); ?> |
| 21 | 21 | ||
| 22 | <?= $form->field($model, 'name')->textInput() ?> | 22 | <?= $form->field($model, 'name')->textInput() ?> |
| 23 | - | 23 | + |
| 24 | <?= $form->field($model, 'alias')->textInput(['maxlength' => true]) ?> | 24 | <?= $form->field($model, 'alias')->textInput(['maxlength' => true]) ?> |
| 25 | + | ||
| 26 | + <?= $form->field($model, 'synonym')->textInput(['maxlength' => true]) ?> | ||
| 25 | 27 | ||
| 26 | <?= $form->field($model, 'parent_id')->dropDownList($categories, [ | 28 | <?= $form->field($model, 'parent_id')->dropDownList($categories, [ |
| 27 | 'prompt' => Yii::t('rubrication', 'Root category'), | 29 | 'prompt' => Yii::t('rubrication', 'Root category'), |
common/config/main.php
| @@ -9,7 +9,7 @@ return [ | @@ -9,7 +9,7 @@ return [ | ||
| 9 | ], | 9 | ], |
| 10 | 'components' => [ | 10 | 'components' => [ |
| 11 | 'cache' => [ | 11 | 'cache' => [ |
| 12 | - 'class' => 'yii\caching\MemCache', | 12 | + 'class' => 'yii\caching\DummyCache', |
| 13 | 'keyPrefix' => 'linija_' | 13 | 'keyPrefix' => 'linija_' |
| 14 | ], | 14 | ], |
| 15 | 'sms' => [ | 15 | 'sms' => [ |
common/modules/product/models/Category.php
| @@ -30,6 +30,7 @@ use common\behaviors\Slug; | @@ -30,6 +30,7 @@ use common\behaviors\Slug; | ||
| 30 | * @property string $alias | 30 | * @property string $alias |
| 31 | * @property boolean $populary | 31 | * @property boolean $populary |
| 32 | * @property string $name | 32 | * @property string $name |
| 33 | + * @property string $synonym | ||
| 33 | * | 34 | * |
| 34 | * @property CategoryName $categoryName | 35 | * @property CategoryName $categoryName |
| 35 | * @property Product[] $products | 36 | * @property Product[] $products |
| @@ -77,7 +78,7 @@ class Category extends \yii\db\ActiveRecord | @@ -77,7 +78,7 @@ class Category extends \yii\db\ActiveRecord | ||
| 77 | [['name'], 'string'], | 78 | [['name'], 'string'], |
| 78 | [['parent_id', 'depth', 'category_name_id', 'product_unit_id'], 'integer'], | 79 | [['parent_id', 'depth', 'category_name_id', 'product_unit_id'], 'integer'], |
| 79 | [['path', 'meta_desc', 'h1', 'seo_text'], 'string'], | 80 | [['path', 'meta_desc', 'h1', 'seo_text'], 'string'], |
| 80 | - [['meta_title', 'image'], 'string', 'max' => 255], | 81 | + [['meta_title', 'image', 'synonym'], 'string', 'max' => 255], |
| 81 | [['meta_robots'], 'string', 'max' => 50], | 82 | [['meta_robots'], 'string', 'max' => 50], |
| 82 | [['alias', 'name'], 'string', 'max' => 250], | 83 | [['alias', 'name'], 'string', 'max' => 250], |
| 83 | [['populary'], 'boolean'], | 84 | [['populary'], 'boolean'], |
| @@ -108,6 +109,7 @@ class Category extends \yii\db\ActiveRecord | @@ -108,6 +109,7 @@ class Category extends \yii\db\ActiveRecord | ||
| 108 | 'populary' => Yii::t('product', 'Populary'), | 109 | 'populary' => Yii::t('product', 'Populary'), |
| 109 | 'name' => Yii::t('product', 'Name'), | 110 | 'name' => Yii::t('product', 'Name'), |
| 110 | 'remote_id' => Yii::t('product', 'Remote ID'), | 111 | 'remote_id' => Yii::t('product', 'Remote ID'), |
| 112 | + 'synonym' => Yii::t('product', 'Синоним'), | ||
| 111 | ]; | 113 | ]; |
| 112 | } | 114 | } |
| 113 | 115 |
common/modules/product/models/Product.php
| 1 | <?php | 1 | <?php |
| 2 | - | ||
| 3 | -namespace common\modules\product\models; | ||
| 4 | - | ||
| 5 | -use common\behaviors\SaveMultipleImgBehavior; | ||
| 6 | -use common\behaviors\Slug; | ||
| 7 | -use common\models\ProductToRating; | ||
| 8 | -use common\models\Share; | ||
| 9 | -use common\modules\comment\models\CommentModel; | ||
| 10 | -use common\modules\product\behaviors\FilterBehavior; | ||
| 11 | -use common\modules\rubrication\models\TaxGroup; | ||
| 12 | -use common\modules\rubrication\models\TaxOption; | ||
| 13 | -use Yii; | ||
| 14 | -use yii\db\ActiveQuery; | ||
| 15 | -use yii\db\ActiveRecord; | ||
| 16 | -use yii\helpers\ArrayHelper; | ||
| 17 | -use common\models\Event; | ||
| 18 | -/** | ||
| 19 | - * This is the model class for table "{{%product}}". | ||
| 20 | - * | ||
| 21 | - * @property string $name | ||
| 22 | - * @property integer $brand_id | ||
| 23 | - * @property integer $product_id | ||
| 24 | - * @property Category $category | ||
| 25 | - * @property array $categories | ||
| 26 | - * @property array of ProductVariant $variants | ||
| 27 | - * @property ProductVariant $variant | ||
| 28 | - * @property ProductImage $image | ||
| 29 | - * @property array $images | ||
| 30 | - * @property boolean $is_top | ||
| 31 | - * @property boolean $is_new | ||
| 32 | - * @property boolean $akciya | ||
| 33 | - * @property ProductToRating $averageRating | ||
| 34 | - * @property array $properties | ||
| 35 | - * @property ProductVariant $enabledVariant | ||
| 36 | - * @property array $enabledVariants | ||
| 37 | - */ | ||
| 38 | -class Product extends \yii\db\ActiveRecord | ||
| 39 | -{ | ||
| 40 | - public $_variants = []; | ||
| 41 | - public $_categories = []; | ||
| 42 | - public $_options = []; | ||
| 43 | - | ||
| 44 | - /** @var array $_images */ | ||
| 45 | - public $imagesUpload = ''; | ||
| 46 | - | ||
| 47 | - | ||
| 48 | - | ||
| 49 | - | ||
| 50 | - /** | ||
| 51 | - * @inheritdoc | ||
| 52 | - */ | ||
| 53 | - public function behaviors() | ||
| 54 | - { | ||
| 55 | - return [ | ||
| 56 | - [ | ||
| 57 | - 'class' => SaveMultipleImgBehavior::className(), | ||
| 58 | - 'fields' => [ | ||
| 59 | - ['name'=>'imagesUpload','directory' => 'products' ] | ||
| 60 | - ] | ||
| 61 | - ], | ||
| 62 | - [ | ||
| 63 | - 'class' => FilterBehavior::className(), | ||
| 64 | - ], | ||
| 65 | - [ | ||
| 66 | - 'class' => Slug::className(), | ||
| 67 | - 'in_attribute' => 'name', | ||
| 68 | - 'out_attribute' => 'alias', | ||
| 69 | - 'translit' => true | ||
| 70 | - ] | ||
| 71 | - ]; | ||
| 72 | - } | ||
| 73 | - | ||
| 74 | - /** | ||
| 75 | - * @inheritdoc | ||
| 76 | - */ | ||
| 77 | - public static function tableName() | ||
| 78 | - { | ||
| 79 | - return '{{%product}}'; | ||
| 80 | - } | ||
| 81 | - | ||
| 82 | - | ||
| 83 | - /** | ||
| 84 | - * @return \yii\db\ActiveQuery | ||
| 85 | - */ | ||
| 86 | - public function getEvents(){ | ||
| 87 | - return $this->hasMany(Event::className(), ['event_id' => 'event_id'])->viaTable('events_to_products', ['product_id' => 'product_id']); | ||
| 88 | - } | ||
| 89 | - | ||
| 90 | - /** | ||
| 91 | - * @inheritdoc | ||
| 92 | - */ | ||
| 93 | - public function rules() | ||
| 94 | - { | ||
| 95 | - return [ | ||
| 96 | -// [['categories'], 'required'], | ||
| 97 | - [['brand_id'], 'integer'], | ||
| 98 | - [['name'], 'string', 'max' => 150], | ||
| 99 | - [['alias'], 'string', 'max' => 250], | ||
| 100 | - [['categories', 'variants', 'options', 'imagesUpload'], 'safe'], | ||
| 101 | -// [['imagesUpload'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg, gif', 'maxFiles' => 50], | ||
| 102 | - [['description', 'video'], 'safe'], | ||
| 103 | - [['is_top', 'is_new', 'akciya'], 'boolean'], | ||
| 104 | -// [['product_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product::className(), 'targetAttribute' => ['product_id' => 'product_id']], | ||
| 105 | - ]; | ||
| 106 | - } | ||
| 107 | - | ||
| 108 | - /** | ||
| 109 | - * @inheritdoc | ||
| 110 | - */ | ||
| 111 | - public function attributeLabels() | ||
| 112 | - { | ||
| 113 | - return [ | ||
| 114 | - 'product_id' => Yii::t('product', 'ID'), | ||
| 115 | - 'name' => Yii::t('product', 'Name'), | ||
| 116 | - 'brand_id' => Yii::t('product', 'Brand'), | ||
| 117 | - 'categories' => Yii::t('product', 'Categories'), // relation behavior field | ||
| 118 | - 'category' => Yii::t('product', 'Category'), // relation behavior field | ||
| 119 | - 'image' => Yii::t('product', 'Image'), | ||
| 120 | - 'images' => Yii::t('product', 'Images'), | ||
| 121 | - 'description' => Yii::t('product', 'Description'), | ||
| 122 | - 'video' => Yii::t('product', 'Video embeded'), | ||
| 123 | - 'variants' => Yii::t('product', 'Variants'), | ||
| 124 | - 'is_top' => Yii::t('product', 'Is top'), | ||
| 125 | - 'is_new' => Yii::t('product', 'Is new'), | ||
| 126 | - 'akciya' => Yii::t('product', 'Is promo'), | ||
| 127 | - ]; | ||
| 128 | - } | ||
| 129 | - | ||
| 130 | - public function getUrl() { | ||
| 131 | - return '/product/'. $this->alias; | ||
| 132 | - } | ||
| 133 | - | ||
| 134 | - /** | ||
| 135 | - * @return \yii\db\ActiveQuery | ||
| 136 | - */ | ||
| 137 | - public function getBrand() | ||
| 138 | - { | ||
| 139 | - return $this->hasOne(Brand::className(), ['brand_id' => 'brand_id']); | ||
| 140 | - } | ||
| 141 | - | ||
| 142 | - /** | ||
| 143 | - * @return \yii\db\ActiveQuery | ||
| 144 | - */ | ||
| 145 | - public function getImage() | ||
| 146 | - { | ||
| 147 | - return $this->hasOne(ProductImage::className(), ['product_id' => 'product_id']); | ||
| 148 | - } | ||
| 149 | - | ||
| 150 | - /** | ||
| 151 | - * fetch stored image url | ||
| 152 | - * @return string | ||
| 153 | - */ | ||
| 154 | - public function getImageUrl() | ||
| 155 | - { | ||
| 156 | - | ||
| 157 | - $image = !empty($this->image) ? $this->image : $this->variant->image; | ||
| 158 | - return !empty($image) ? $image->imageUrl : '/storage/no_photo.png'; | ||
| 159 | - } | ||
| 160 | - | ||
| 161 | - /** | ||
| 162 | - * @return \yii\db\ActiveQuery | ||
| 163 | - */ | ||
| 164 | - public function getImages() | ||
| 165 | - { | ||
| 166 | - return $this->hasMany(ProductImage::className(), ['product_id' => 'product_id'])->where(['product_variant_id' => null]); | ||
| 167 | - } | ||
| 168 | - | ||
| 169 | - | ||
| 170 | - /** | ||
| 171 | - * @return \yii\db\ActiveQuery | ||
| 172 | - */ | ||
| 173 | - public function getVariant() | ||
| 174 | - { | ||
| 175 | - return $this->hasOne(ProductVariant::className(), ['product_id' => 'product_id']); | ||
| 176 | - } | ||
| 177 | - | ||
| 178 | - /** | ||
| 179 | - * @return \yii\db\ActiveQuery | ||
| 180 | - */ | ||
| 181 | - public function getVariants() | ||
| 182 | - { | ||
| 183 | - return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id']); | ||
| 184 | - } | 2 | + |
| 3 | + namespace common\modules\product\models; | ||
| 4 | + | ||
| 5 | + use common\behaviors\SaveMultipleImgBehavior; | ||
| 6 | + use common\behaviors\Slug; | ||
| 7 | + use common\models\ProductToRating; | ||
| 8 | + use common\models\Share; | ||
| 9 | + use common\modules\comment\models\CommentModel; | ||
| 10 | + use common\modules\product\behaviors\FilterBehavior; | ||
| 11 | + use common\modules\rubrication\models\TaxGroup; | ||
| 12 | + use common\modules\rubrication\models\TaxOption; | ||
| 13 | + use Yii; | ||
| 14 | + use yii\db\ActiveQuery; | ||
| 15 | + use yii\db\ActiveRecord; | ||
| 16 | + use yii\helpers\ArrayHelper; | ||
| 17 | + use common\models\Event; | ||
| 185 | 18 | ||
| 186 | /** | 19 | /** |
| 187 | - * @return \yii\db\ActiveQuery | 20 | + * This is the model class for table "{{%product}}". |
| 21 | + * | ||
| 22 | + * @property string $name | ||
| 23 | + * @property integer $brand_id | ||
| 24 | + * @property integer $product_id | ||
| 25 | + * @property Category $category | ||
| 26 | + * @property array $categories | ||
| 27 | + * @property array of ProductVariant $variants | ||
| 28 | + * @property ProductVariant $variant | ||
| 29 | + * @property ProductImage $image | ||
| 30 | + * @property array $images | ||
| 31 | + * @property boolean $is_top | ||
| 32 | + * @property boolean $is_new | ||
| 33 | + * @property boolean $akciya | ||
| 34 | + * @property ProductToRating $averageRating | ||
| 35 | + * @property array $properties | ||
| 36 | + * @property ProductVariant $enabledVariant | ||
| 37 | + * @property array $enabledVariants | ||
| 188 | */ | 38 | */ |
| 189 | - public function getEnabledVariant() | 39 | + class Product extends \yii\db\ActiveRecord |
| 190 | { | 40 | { |
| 191 | - return $this->hasOne(ProductVariant::className(), ['product_id' => 'product_id']) | ||
| 192 | - ->andOnCondition(['!=', ProductVariant::tableName() .'.status', 1]); | ||
| 193 | - } | ||
| 194 | - | ||
| 195 | - public function getVariantPrice() { | ||
| 196 | - return $this->variant->price; | ||
| 197 | - } | ||
| 198 | - | ||
| 199 | - | ||
| 200 | - public function getPrice() { | ||
| 201 | - return $this->variant->price; | ||
| 202 | - } | ||
| 203 | - | ||
| 204 | - public function getEnabledVariantPrice() { | ||
| 205 | - return $this->enabledVariants[0]->price; | ||
| 206 | - } | ||
| 207 | - | ||
| 208 | - | ||
| 209 | - | ||
| 210 | - public function getEnabledVariants() | ||
| 211 | - { | ||
| 212 | - return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id'])->andOnCondition(['!=', ProductVariant::tableName() .'.status', 1])->joinWith('image'); | ||
| 213 | - } | ||
| 214 | - | ||
| 215 | - /* | ||
| 216 | - * Get variants grouped by type | ||
| 217 | - */ | ||
| 218 | - public function getEnabledVariantsGrouped() | ||
| 219 | - { | ||
| 220 | - $variants = []; | ||
| 221 | - foreach ($this->enabledVariants as $variant) { | ||
| 222 | - $variants[$variant->product_variant_type_id ? $variant->product_variant_type_id : 1][] = $variant; | 41 | + public $_variants = []; |
| 42 | + public $_categories = []; | ||
| 43 | + public $_options = []; | ||
| 44 | + | ||
| 45 | + /** @var array $_images */ | ||
| 46 | + public $imagesUpload = ''; | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * @inheritdoc | ||
| 50 | + */ | ||
| 51 | + public function behaviors() | ||
| 52 | + { | ||
| 53 | + return [ | ||
| 54 | + [ | ||
| 55 | + 'class' => SaveMultipleImgBehavior::className(), | ||
| 56 | + 'fields' => [ | ||
| 57 | + [ | ||
| 58 | + 'name' => 'imagesUpload', | ||
| 59 | + 'directory' => 'products', | ||
| 60 | + ], | ||
| 61 | + ], | ||
| 62 | + ], | ||
| 63 | + [ | ||
| 64 | + 'class' => FilterBehavior::className(), | ||
| 65 | + ], | ||
| 66 | + [ | ||
| 67 | + 'class' => Slug::className(), | ||
| 68 | + 'in_attribute' => 'name', | ||
| 69 | + 'out_attribute' => 'alias', | ||
| 70 | + 'translit' => true, | ||
| 71 | + ], | ||
| 72 | + ]; | ||
| 223 | } | 73 | } |
| 224 | - if (empty($variants)) { | ||
| 225 | - return []; | 74 | + |
| 75 | + /** | ||
| 76 | + * @inheritdoc | ||
| 77 | + */ | ||
| 78 | + public static function tableName() | ||
| 79 | + { | ||
| 80 | + return '{{%product}}'; | ||
| 226 | } | 81 | } |
| 227 | - $ids = array_keys($variants); | ||
| 228 | - $variants_type = []; | ||
| 229 | - foreach(ProductVariantType::find()->select(['product_variant_type_id', 'name2'])->where(['product_variant_type_id' => $ids])->all() as $variant_type) { | ||
| 230 | - $variant_type->_variants = $variants[$variant_type->product_variant_type_id]; | ||
| 231 | - $variants_type[] = $variant_type; | 82 | + |
| 83 | + /** | ||
| 84 | + * @return \yii\db\ActiveQuery | ||
| 85 | + */ | ||
| 86 | + public function getEvents() | ||
| 87 | + { | ||
| 88 | + return $this->hasMany(Event::className(), [ 'event_id' => 'event_id' ]) | ||
| 89 | + ->viaTable('events_to_products', [ 'product_id' => 'product_id' ]); | ||
| 232 | } | 90 | } |
| 233 | - return $variants_type; | ||
| 234 | - } | ||
| 235 | - | ||
| 236 | - public function setVariants($variants) { | ||
| 237 | - $this->_variants = $variants; | ||
| 238 | - } | ||
| 239 | - | ||
| 240 | - public function getFullName() | ||
| 241 | - { | ||
| 242 | - return empty($this->brand) ? $this->name : $this->brand->name .' '. $this->name; | ||
| 243 | - } | ||
| 244 | - | ||
| 245 | - public function getCategories() { | ||
| 246 | - return $this->hasMany(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']); | ||
| 247 | -// return $this->getRelations('product_categories'); | ||
| 248 | - } | ||
| 249 | - public function getCategoriesWithName() { | ||
| 250 | - return $this->hasMany(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']); | ||
| 251 | -// return $this->getRelations('product_categories'); | ||
| 252 | - } | ||
| 253 | - | ||
| 254 | - public function getCategoriesNames() { | ||
| 255 | - $result = []; | ||
| 256 | - foreach($this->categories as $category) { | ||
| 257 | - $result[] = $category->name; | 91 | + |
| 92 | + /** | ||
| 93 | + * @inheritdoc | ||
| 94 | + */ | ||
| 95 | + public function rules() | ||
| 96 | + { | ||
| 97 | + return [ | ||
| 98 | + // [['categories'], 'required'], | ||
| 99 | + [ | ||
| 100 | + [ 'brand_id' ], | ||
| 101 | + 'integer', | ||
| 102 | + ], | ||
| 103 | + [ | ||
| 104 | + [ 'name' ], | ||
| 105 | + 'string', | ||
| 106 | + 'max' => 150, | ||
| 107 | + ], | ||
| 108 | + [ | ||
| 109 | + [ 'alias' ], | ||
| 110 | + 'string', | ||
| 111 | + 'max' => 250, | ||
| 112 | + ], | ||
| 113 | + [ | ||
| 114 | + [ | ||
| 115 | + 'categories', | ||
| 116 | + 'variants', | ||
| 117 | + 'options', | ||
| 118 | + 'imagesUpload', | ||
| 119 | + ], | ||
| 120 | + 'safe', | ||
| 121 | + ], | ||
| 122 | + // [['imagesUpload'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg, gif', 'maxFiles' => 50], | ||
| 123 | + [ | ||
| 124 | + [ | ||
| 125 | + 'description', | ||
| 126 | + 'video', | ||
| 127 | + ], | ||
| 128 | + 'safe', | ||
| 129 | + ], | ||
| 130 | + [ | ||
| 131 | + [ | ||
| 132 | + 'is_top', | ||
| 133 | + 'is_new', | ||
| 134 | + 'akciya', | ||
| 135 | + ], | ||
| 136 | + 'boolean', | ||
| 137 | + ], | ||
| 138 | + // [['product_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product::className(), 'targetAttribute' => ['product_id' => 'product_id']], | ||
| 139 | + ]; | ||
| 258 | } | 140 | } |
| 259 | - return $result; | ||
| 260 | - } | ||
| 261 | - | ||
| 262 | - public function getVariantsWithFilters(){ | ||
| 263 | - return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id'])->with(['filters','image']); | ||
| 264 | - } | ||
| 265 | - | ||
| 266 | - /** | ||
| 267 | - * @return ActiveQuery | ||
| 268 | - */ | ||
| 269 | - public function getCategory() { | ||
| 270 | - return $this->hasOne(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']); | ||
| 271 | - } | ||
| 272 | - | ||
| 273 | - public function getOptions() { | ||
| 274 | - return $this->hasMany(TaxOption::className(), ['tax_option_id' => 'option_id'])->viaTable('product_option', ['product_id' => 'product_id']); | ||
| 275 | - } | ||
| 276 | - | ||
| 277 | - public function getProperties() { | ||
| 278 | - $groups = $options = []; | ||
| 279 | - foreach ($this->options as $option) { | ||
| 280 | - $options[$option->tax_group_id][] = $option; | ||
| 281 | - } | ||
| 282 | - foreach (TaxGroup::find()->where(['tax_group_id' => array_keys($options)])->all() as $group) { | ||
| 283 | - if (!empty($options[$group->tax_group_id])) { | ||
| 284 | - $group->_options = $options[$group->tax_group_id]; | ||
| 285 | - $groups[] = $group; | 141 | + |
| 142 | + /** | ||
| 143 | + * @inheritdoc | ||
| 144 | + */ | ||
| 145 | + public function attributeLabels() | ||
| 146 | + { | ||
| 147 | + return [ | ||
| 148 | + 'product_id' => Yii::t('product', 'ID'), | ||
| 149 | + 'name' => Yii::t('product', 'Name'), | ||
| 150 | + 'brand_id' => Yii::t('product', 'Brand'), | ||
| 151 | + 'categories' => Yii::t('product', 'Categories'), | ||
| 152 | + // relation behavior field | ||
| 153 | + 'category' => Yii::t('product', 'Category'), | ||
| 154 | + // relation behavior field | ||
| 155 | + 'image' => Yii::t('product', 'Image'), | ||
| 156 | + 'images' => Yii::t('product', 'Images'), | ||
| 157 | + 'description' => Yii::t('product', 'Description'), | ||
| 158 | + 'video' => Yii::t('product', 'Video embeded'), | ||
| 159 | + 'variants' => Yii::t('product', 'Variants'), | ||
| 160 | + 'is_top' => Yii::t('product', 'Is top'), | ||
| 161 | + 'is_new' => Yii::t('product', 'Is new'), | ||
| 162 | + 'akciya' => Yii::t('product', 'Is promo'), | ||
| 163 | + ]; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + public function getUrl() | ||
| 167 | + { | ||
| 168 | + return '/product/' . $this->alias; | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + /** | ||
| 172 | + * @return \yii\db\ActiveQuery | ||
| 173 | + */ | ||
| 174 | + public function getBrand() | ||
| 175 | + { | ||
| 176 | + return $this->hasOne(Brand::className(), [ 'brand_id' => 'brand_id' ]); | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + /** | ||
| 180 | + * @return \yii\db\ActiveQuery | ||
| 181 | + */ | ||
| 182 | + public function getImage() | ||
| 183 | + { | ||
| 184 | + return $this->hasOne(ProductImage::className(), [ 'product_id' => 'product_id' ]); | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + /** | ||
| 188 | + * fetch stored image url | ||
| 189 | + * | ||
| 190 | + * @return string | ||
| 191 | + */ | ||
| 192 | + public function getImageUrl() | ||
| 193 | + { | ||
| 194 | + | ||
| 195 | + $image = !empty( $this->image ) ? $this->image : $this->variant->image; | ||
| 196 | + return !empty( $image ) ? $image->imageUrl : '/storage/no_photo.png'; | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + /** | ||
| 200 | + * @return \yii\db\ActiveQuery | ||
| 201 | + */ | ||
| 202 | + public function getImages() | ||
| 203 | + { | ||
| 204 | + return $this->hasMany(ProductImage::className(), [ 'product_id' => 'product_id' ]) | ||
| 205 | + ->where([ 'product_variant_id' => null ]); | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + /** | ||
| 209 | + * @return \yii\db\ActiveQuery | ||
| 210 | + */ | ||
| 211 | + public function getVariant() | ||
| 212 | + { | ||
| 213 | + return $this->hasOne(ProductVariant::className(), [ 'product_id' => 'product_id' ]); | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + /** | ||
| 217 | + * @return \yii\db\ActiveQuery | ||
| 218 | + */ | ||
| 219 | + public function getVariants() | ||
| 220 | + { | ||
| 221 | + return $this->hasMany(ProductVariant::className(), [ 'product_id' => 'product_id' ]); | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + /** | ||
| 225 | + * @return \yii\db\ActiveQuery | ||
| 226 | + */ | ||
| 227 | + public function getEnabledVariant() | ||
| 228 | + { | ||
| 229 | + return $this->hasOne(ProductVariant::className(), [ 'product_id' => 'product_id' ]) | ||
| 230 | + ->andOnCondition( | ||
| 231 | + [ | ||
| 232 | + '!=', | ||
| 233 | + ProductVariant::tableName() . '.status', | ||
| 234 | + 1, | ||
| 235 | + ] | ||
| 236 | + ); | ||
| 237 | + } | ||
| 238 | + | ||
| 239 | + public function getVariantPrice() | ||
| 240 | + { | ||
| 241 | + return $this->variant->price; | ||
| 242 | + } | ||
| 243 | + | ||
| 244 | + public function getPrice() | ||
| 245 | + { | ||
| 246 | + return $this->variant->price; | ||
| 247 | + } | ||
| 248 | + | ||
| 249 | + public function getEnabledVariantPrice() | ||
| 250 | + { | ||
| 251 | + return $this->enabledVariants[ 0 ]->price; | ||
| 252 | + } | ||
| 253 | + | ||
| 254 | + public function getEnabledVariants() | ||
| 255 | + { | ||
| 256 | + return $this->hasMany(ProductVariant::className(), [ 'product_id' => 'product_id' ]) | ||
| 257 | + ->andOnCondition( | ||
| 258 | + [ | ||
| 259 | + '!=', | ||
| 260 | + ProductVariant::tableName() . '.status', | ||
| 261 | + 1, | ||
| 262 | + ] | ||
| 263 | + ) | ||
| 264 | + ->joinWith('image'); | ||
| 265 | + } | ||
| 266 | + | ||
| 267 | + /* | ||
| 268 | + * Get variants grouped by type | ||
| 269 | + */ | ||
| 270 | + public function getEnabledVariantsGrouped() | ||
| 271 | + { | ||
| 272 | + $variants = []; | ||
| 273 | + foreach ($this->enabledVariants as $variant) { | ||
| 274 | + $variants[ $variant->product_variant_type_id ? $variant->product_variant_type_id : 1 ][] = $variant; | ||
| 286 | } | 275 | } |
| 276 | + if (empty( $variants )) { | ||
| 277 | + return []; | ||
| 278 | + } | ||
| 279 | + $ids = array_keys($variants); | ||
| 280 | + $variants_type = []; | ||
| 281 | + foreach (ProductVariantType::find() | ||
| 282 | + ->select( | ||
| 283 | + [ | ||
| 284 | + 'product_variant_type_id', | ||
| 285 | + 'name2', | ||
| 286 | + ] | ||
| 287 | + ) | ||
| 288 | + ->where([ 'product_variant_type_id' => $ids ]) | ||
| 289 | + ->all() as $variant_type) { | ||
| 290 | + $variant_type->_variants = $variants[ $variant_type->product_variant_type_id ]; | ||
| 291 | + $variants_type[] = $variant_type; | ||
| 292 | + } | ||
| 293 | + return $variants_type; | ||
| 287 | } | 294 | } |
| 288 | - return $groups; | ||
| 289 | - } | ||
| 290 | - | ||
| 291 | - public function getActiveProperties($category_id) { | ||
| 292 | - $cacheKey = ['ActiveProperties','id' => $category_id, 'options' =>$this->options, 'product_id' => $this->product_id ]; | ||
| 293 | - | ||
| 294 | - if(!$groups = Yii::$app->cache->get($cacheKey)){ | ||
| 295 | - | 295 | + |
| 296 | + public function setVariants($variants) | ||
| 297 | + { | ||
| 298 | + $this->_variants = $variants; | ||
| 299 | + } | ||
| 300 | + | ||
| 301 | + public function getFullName() | ||
| 302 | + { | ||
| 303 | + $name = ''; | ||
| 304 | + $taxOption = TaxOption::find() | ||
| 305 | + ->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id') | ||
| 306 | + ->innerJoin('tax_group_to_category', 'tax_group.tax_group_id = tax_group_to_category.tax_group_id') | ||
| 307 | + ->where( | ||
| 308 | + [ | ||
| 309 | + 'tax_group_to_category.category_id' => $this->category->category_id, | ||
| 310 | + 'tax_group.use_in_name' => 1, | ||
| 311 | + 'tax_option.tax_option_id' => ArrayHelper::getColumn( | ||
| 312 | + $this->options, | ||
| 313 | + 'tax_option_id' | ||
| 314 | + ), | ||
| 315 | + ] | ||
| 316 | + ) | ||
| 317 | + ->one(); | ||
| 318 | + if($taxOption) { | ||
| 319 | + if(!empty($taxOption->synonym)) { | ||
| 320 | + $taxOption = $taxOption->synonym; | ||
| 321 | + } else { | ||
| 322 | + $taxOption = $taxOption->value; | ||
| 323 | + } | ||
| 324 | + $name .= $taxOption; | ||
| 325 | + } else { | ||
| 326 | + if(!empty($this->category->synonym)) { | ||
| 327 | + $name .= $this->category->synonym; | ||
| 328 | + } else { | ||
| 329 | + $name .= $this->category->name; | ||
| 330 | + } | ||
| 331 | + } | ||
| 332 | + | ||
| 333 | + if (!empty( $this->brand )) { | ||
| 334 | + $name = $name . ' ' . $this->brand->name; | ||
| 335 | + } | ||
| 336 | + $name .= ' ' . $this->name; | ||
| 337 | + return $name; | ||
| 338 | + } | ||
| 339 | + | ||
| 340 | + public function getCategories() | ||
| 341 | + { | ||
| 342 | + return $this->hasMany(Category::className(), [ 'category_id' => 'category_id' ]) | ||
| 343 | + ->viaTable('product_category', [ 'product_id' => 'product_id' ]); | ||
| 344 | + // return $this->getRelations('product_categories'); | ||
| 345 | + } | ||
| 346 | + public function getCategoriesWithName() | ||
| 347 | + { | ||
| 348 | + return $this->hasMany(Category::className(), [ 'category_id' => 'category_id' ]) | ||
| 349 | + ->viaTable('product_category', [ 'product_id' => 'product_id' ]); | ||
| 350 | + // return $this->getRelations('product_categories'); | ||
| 351 | + } | ||
| 352 | + | ||
| 353 | + public function getCategoriesNames() | ||
| 354 | + { | ||
| 355 | + $result = []; | ||
| 356 | + foreach ($this->categories as $category) { | ||
| 357 | + $result[] = $category->name; | ||
| 358 | + } | ||
| 359 | + return $result; | ||
| 360 | + } | ||
| 361 | + | ||
| 362 | + public function getVariantsWithFilters() | ||
| 363 | + { | ||
| 364 | + return $this->hasMany(ProductVariant::className(), [ 'product_id' => 'product_id' ]) | ||
| 365 | + ->with( | ||
| 366 | + [ | ||
| 367 | + 'filters', | ||
| 368 | + 'image', | ||
| 369 | + ] | ||
| 370 | + ); | ||
| 371 | + } | ||
| 372 | + | ||
| 373 | + /** | ||
| 374 | + * @return ActiveQuery | ||
| 375 | + */ | ||
| 376 | + public function getCategory() | ||
| 377 | + { | ||
| 378 | + return $this->hasOne(Category::className(), [ 'category_id' => 'category_id' ]) | ||
| 379 | + ->viaTable('product_category', [ 'product_id' => 'product_id' ]); | ||
| 380 | + } | ||
| 381 | + | ||
| 382 | + public function getOptions() | ||
| 383 | + { | ||
| 384 | + return $this->hasMany(TaxOption::className(), [ 'tax_option_id' => 'option_id' ]) | ||
| 385 | + ->viaTable('product_option', [ 'product_id' => 'product_id' ]); | ||
| 386 | + } | ||
| 387 | + | ||
| 388 | + public function getProperties() | ||
| 389 | + { | ||
| 296 | $groups = $options = []; | 390 | $groups = $options = []; |
| 297 | foreach ($this->options as $option) { | 391 | foreach ($this->options as $option) { |
| 298 | - $options[$option->tax_group_id][] = $option; | 392 | + $options[ $option->tax_group_id ][] = $option; |
| 299 | } | 393 | } |
| 300 | - | ||
| 301 | - $taxGroups = TaxGroup::find()->joinWith('categories')->where(['tax_group.tax_group_id' => array_keys($options), 'tax_group.display' => TRUE, 'category.category_id' => $category_id])->all(); | ||
| 302 | - | ||
| 303 | - foreach ($taxGroups as $group) { | ||
| 304 | - if (!empty($options[$group->tax_group_id])) { | ||
| 305 | - $group->_options = $options[$group->tax_group_id]; | 394 | + foreach (TaxGroup::find() |
| 395 | + ->where([ 'tax_group_id' => array_keys($options) ]) | ||
| 396 | + ->all() as $group) { | ||
| 397 | + if (!empty( $options[ $group->tax_group_id ] )) { | ||
| 398 | + $group->_options = $options[ $group->tax_group_id ]; | ||
| 306 | $groups[] = $group; | 399 | $groups[] = $group; |
| 307 | } | 400 | } |
| 308 | } | 401 | } |
| 309 | - Yii::$app->cache->set($cacheKey,$groups,3600*24); | 402 | + return $groups; |
| 310 | } | 403 | } |
| 311 | - | ||
| 312 | - return $groups; | ||
| 313 | - } | ||
| 314 | - | ||
| 315 | - public function getStocks() { | ||
| 316 | - return $this->hasMany(Stock::className(), ['stock_id' => 'stock_id'])->viaTable(ProductStock::tableName(), ['product_id' => 'product_id']); | ||
| 317 | - } | ||
| 318 | - | ||
| 319 | - | ||
| 320 | - public function getQuantity() { | ||
| 321 | - return ProductStock::find() | ||
| 322 | - ->where(['product_id' => $this->product_id]) | ||
| 323 | - ->sum('quantity'); | ||
| 324 | - } | ||
| 325 | - | ||
| 326 | - | ||
| 327 | - public function beforeSave($insert) | ||
| 328 | - { | ||
| 329 | - | ||
| 330 | - if(parent::beforeSave($insert)){ | ||
| 331 | - | ||
| 332 | - return true; | ||
| 333 | - } | ||
| 334 | - return false; | ||
| 335 | - | ||
| 336 | - | ||
| 337 | - | ||
| 338 | - } | ||
| 339 | - | ||
| 340 | - public function afterSave($insert, $changedAttributes) | ||
| 341 | - { | ||
| 342 | - parent::afterSave($insert, $changedAttributes); | ||
| 343 | - | ||
| 344 | - | ||
| 345 | - if(!empty($this->categories)){ | ||
| 346 | - $categories = Category::findAll($this->categories); | ||
| 347 | - $this->unlinkAll('categories', true); | ||
| 348 | - foreach($categories as $category){ | ||
| 349 | - $this->link('categories', $category); | 404 | + |
| 405 | + public function getActiveProperties($category_id) | ||
| 406 | + { | ||
| 407 | + $cacheKey = [ | ||
| 408 | + 'ActiveProperties', | ||
| 409 | + 'id' => $category_id, | ||
| 410 | + 'options' => $this->options, | ||
| 411 | + 'product_id' => $this->product_id, | ||
| 412 | + ]; | ||
| 413 | + | ||
| 414 | + if (!$groups = Yii::$app->cache->get($cacheKey)) { | ||
| 415 | + | ||
| 416 | + $groups = $options = []; | ||
| 417 | + foreach ($this->options as $option) { | ||
| 418 | + $options[ $option->tax_group_id ][] = $option; | ||
| 419 | + } | ||
| 420 | + | ||
| 421 | + $taxGroups = TaxGroup::find() | ||
| 422 | + ->joinWith('categories') | ||
| 423 | + ->where( | ||
| 424 | + [ | ||
| 425 | + 'tax_group.tax_group_id' => array_keys($options), | ||
| 426 | + 'tax_group.display' => true, | ||
| 427 | + 'category.category_id' => $category_id, | ||
| 428 | + ] | ||
| 429 | + ) | ||
| 430 | + ->all(); | ||
| 431 | + | ||
| 432 | + foreach ($taxGroups as $group) { | ||
| 433 | + if (!empty( $options[ $group->tax_group_id ] )) { | ||
| 434 | + $group->_options = $options[ $group->tax_group_id ]; | ||
| 435 | + $groups[] = $group; | ||
| 436 | + } | ||
| 437 | + } | ||
| 438 | + Yii::$app->cache->set($cacheKey, $groups, 3600 * 24); | ||
| 350 | } | 439 | } |
| 440 | + | ||
| 441 | + return $groups; | ||
| 442 | + } | ||
| 443 | + | ||
| 444 | + public function getStocks() | ||
| 445 | + { | ||
| 446 | + return $this->hasMany(Stock::className(), [ 'stock_id' => 'stock_id' ]) | ||
| 447 | + ->viaTable(ProductStock::tableName(), [ 'product_id' => 'product_id' ]); | ||
| 351 | } | 448 | } |
| 352 | - | ||
| 353 | - if(!empty($this->options)){ | ||
| 354 | - $options = TaxOption::findAll($this->options); | ||
| 355 | - $this->unlinkAll('options',true); | ||
| 356 | - foreach($options as $option){ | ||
| 357 | - $this->link('options', $option); | 449 | + |
| 450 | + public function getQuantity() | ||
| 451 | + { | ||
| 452 | + return ProductStock::find() | ||
| 453 | + ->where([ 'product_id' => $this->product_id ]) | ||
| 454 | + ->sum('quantity'); | ||
| 455 | + } | ||
| 456 | + | ||
| 457 | + public function beforeSave($insert) | ||
| 458 | + { | ||
| 459 | + | ||
| 460 | + if (parent::beforeSave($insert)) { | ||
| 461 | + | ||
| 462 | + return true; | ||
| 358 | } | 463 | } |
| 464 | + return false; | ||
| 465 | + | ||
| 359 | } | 466 | } |
| 360 | - | ||
| 361 | - | ||
| 362 | - if (!empty($this->_variants)) { | ||
| 363 | - $todel = []; | ||
| 364 | - foreach ($this->variants ?: [] as $_variant) { | ||
| 365 | - $todel[$_variant->product_variant_id] = $_variant->product_variant_id; | 467 | + |
| 468 | + public function afterSave($insert, $changedAttributes) | ||
| 469 | + { | ||
| 470 | + parent::afterSave($insert, $changedAttributes); | ||
| 471 | + | ||
| 472 | + if (!empty( $this->categories )) { | ||
| 473 | + $categories = Category::findAll($this->categories); | ||
| 474 | + $this->unlinkAll('categories', true); | ||
| 475 | + foreach ($categories as $category) { | ||
| 476 | + $this->link('categories', $category); | ||
| 477 | + } | ||
| 366 | } | 478 | } |
| 367 | - foreach ($this->_variants as $_variant) { | ||
| 368 | - if (!is_array($_variant)) { | ||
| 369 | - return; | 479 | + |
| 480 | + if (!empty( $this->options )) { | ||
| 481 | + $options = TaxOption::findAll($this->options); | ||
| 482 | + $this->unlinkAll('options', true); | ||
| 483 | + foreach ($options as $option) { | ||
| 484 | + $this->link('options', $option); | ||
| 370 | } | 485 | } |
| 371 | - if (!empty($_variant['product_variant_id'])) { | ||
| 372 | - unset($todel[$_variant['product_variant_id']]); | ||
| 373 | - $model = ProductVariant::findOne($_variant['product_variant_id']); | ||
| 374 | - } else { | ||
| 375 | - $model = new ProductVariant(); | 486 | + } |
| 487 | + | ||
| 488 | + if (!empty( $this->_variants )) { | ||
| 489 | + $todel = []; | ||
| 490 | + foreach ($this->variants ? : [] as $_variant) { | ||
| 491 | + $todel[ $_variant->product_variant_id ] = $_variant->product_variant_id; | ||
| 492 | + } | ||
| 493 | + foreach ($this->_variants as $_variant) { | ||
| 494 | + if (!is_array($_variant)) { | ||
| 495 | + return; | ||
| 496 | + } | ||
| 497 | + if (!empty( $_variant[ 'product_variant_id' ] )) { | ||
| 498 | + unset( $todel[ $_variant[ 'product_variant_id' ] ] ); | ||
| 499 | + $model = ProductVariant::findOne($_variant[ 'product_variant_id' ]); | ||
| 500 | + } else { | ||
| 501 | + $model = new ProductVariant(); | ||
| 502 | + } | ||
| 503 | + $_variant[ 'product_id' ] = $this->product_id; | ||
| 504 | + $model->load([ 'ProductVariant' => $_variant ]); | ||
| 505 | + $model->product_id = $this->product_id; | ||
| 506 | + $model->save(); | ||
| 507 | + } | ||
| 508 | + if (!empty( $todel )) { | ||
| 509 | + ProductVariant::deleteAll([ 'product_variant_id' => $todel ]); | ||
| 376 | } | 510 | } |
| 377 | - $_variant['product_id'] = $this->product_id; | ||
| 378 | - $model->load(['ProductVariant' => $_variant]); | ||
| 379 | - $model->product_id = $this->product_id; | ||
| 380 | - $model->save(); | ||
| 381 | } | 511 | } |
| 382 | - if (!empty($todel)) { | ||
| 383 | - ProductVariant::deleteAll(['product_variant_id' => $todel]); | 512 | + } |
| 513 | + | ||
| 514 | + public function beforeDelete() | ||
| 515 | + { | ||
| 516 | + if (parent::beforeDelete()) { | ||
| 517 | + $this->unlinkAll('categories', true); | ||
| 518 | + $this->unlinkAll('options', true); | ||
| 519 | + ProductImage::deleteAll([ 'product_id' => $this->product_id ]); | ||
| 520 | + | ||
| 521 | + ProductVariant::deleteAll([ 'product_id' => $this->product_id ]); | ||
| 522 | + ProductStock::deleteAll([ 'product_id' => $this->product_id ]); | ||
| 523 | + Share::deleteAll([ 'product_id' => $this->product_id ]); | ||
| 524 | + return true; | ||
| 384 | } | 525 | } |
| 526 | + return false; | ||
| 527 | + | ||
| 385 | } | 528 | } |
| 386 | - } | ||
| 387 | - | ||
| 388 | - public function beforeDelete() { | ||
| 389 | - if(parent::beforeDelete()){ | ||
| 390 | - $this->unlinkAll('categories', true); | ||
| 391 | - $this->unlinkAll('options', true); | ||
| 392 | - ProductImage::deleteAll(['product_id' => $this->product_id]); | ||
| 393 | - | ||
| 394 | - ProductVariant::deleteAll(['product_id' => $this->product_id]); | ||
| 395 | - ProductStock::deleteAll(['product_id' => $this->product_id]); | ||
| 396 | - Share::deleteAll(['product_id' => $this->product_id]); | ||
| 397 | - return true; | ||
| 398 | - } | ||
| 399 | - return false; | ||
| 400 | - | ||
| 401 | - } | ||
| 402 | - | ||
| 403 | - public function imagesUpload() | ||
| 404 | - { | ||
| 405 | - if ($this->validate()) { | ||
| 406 | - $images = []; | ||
| 407 | - foreach ($this->imagesUpload as $image) { | ||
| 408 | - $imageName = $image->baseName .'.'. $image->extension; | ||
| 409 | - $i = 0; | ||
| 410 | - while(file_exists(Yii::getAlias('@imagesDir/products/' . $imageName))) { | ||
| 411 | - $i++; | ||
| 412 | - $imageName = $image->baseName .'_'. $i .'.'. $image->extension; | 529 | + |
| 530 | + public function imagesUpload() | ||
| 531 | + { | ||
| 532 | + if ($this->validate()) { | ||
| 533 | + $images = []; | ||
| 534 | + foreach ($this->imagesUpload as $image) { | ||
| 535 | + $imageName = $image->baseName . '.' . $image->extension; | ||
| 536 | + $i = 0; | ||
| 537 | + while (file_exists(Yii::getAlias('@imagesDir/products/' . $imageName))) { | ||
| 538 | + $i++; | ||
| 539 | + $imageName = $image->baseName . '_' . $i . '.' . $image->extension; | ||
| 540 | + } | ||
| 541 | + $imgDir = Yii::getAlias('@imagesDir/products/'); | ||
| 542 | + if (!is_dir($imgDir)) { | ||
| 543 | + mkdir($imgDir, 0755, true); | ||
| 544 | + } | ||
| 545 | + | ||
| 546 | + $image->saveAs($imgDir . $imageName); | ||
| 547 | + $images[] = $imageName; | ||
| 413 | } | 548 | } |
| 414 | - $imgDir =Yii::getAlias('@imagesDir/products/'); | ||
| 415 | - if(!is_dir($imgDir)) { | ||
| 416 | - mkdir($imgDir, 0755, true); | 549 | + return $images; |
| 550 | + } else { | ||
| 551 | + return false; | ||
| 552 | + } | ||
| 553 | + } | ||
| 554 | + | ||
| 555 | + public function getImagesHTML() | ||
| 556 | + { | ||
| 557 | + $op = []; | ||
| 558 | + if ($this->images) { | ||
| 559 | + foreach ($this->images as $image) { | ||
| 560 | + $op[] = \common\components\artboximage\ArtboxImageHelper::getImage($image->imageUrl, 'admin_thumb'); | ||
| 417 | } | 561 | } |
| 418 | - | ||
| 419 | - | ||
| 420 | - $image->saveAs($imgDir .$imageName); | ||
| 421 | - $images[] = $imageName; | ||
| 422 | } | 562 | } |
| 423 | - return $images; | ||
| 424 | - } else { | ||
| 425 | - return false; | 563 | + return $op; |
| 426 | } | 564 | } |
| 427 | - } | ||
| 428 | - | ||
| 429 | - public function getImagesHTML() { | ||
| 430 | - $op = []; | ||
| 431 | - if ($this->images) { | ||
| 432 | - foreach ($this->images as $image) { | ||
| 433 | - $op[] = \common\components\artboximage\ArtboxImageHelper::getImage($image->imageUrl, 'admin_thumb'); | 565 | + |
| 566 | + public function getImagesConfig() | ||
| 567 | + { | ||
| 568 | + $op = []; | ||
| 569 | + if ($this->images) { | ||
| 570 | + foreach ($this->images as $image) { | ||
| 571 | + $op[] = [ | ||
| 572 | + 'caption' => $image->image, | ||
| 573 | + 'url' => \yii\helpers\Url::to( | ||
| 574 | + [ | ||
| 575 | + '/product/manage/delimg', | ||
| 576 | + 'id' => $image->product_image_id, | ||
| 577 | + ] | ||
| 578 | + ), | ||
| 579 | + 'key' => $image->product_image_id, | ||
| 580 | + 'extra' => [ | ||
| 581 | + 'id' => $image->product_image_id, | ||
| 582 | + ], | ||
| 583 | + ]; | ||
| 584 | + } | ||
| 434 | } | 585 | } |
| 586 | + return $op; | ||
| 435 | } | 587 | } |
| 436 | - return $op; | ||
| 437 | - } | ||
| 438 | - | ||
| 439 | - public function getImagesConfig() { | ||
| 440 | - $op = []; | ||
| 441 | - if ($this->images) { | ||
| 442 | - foreach ($this->images as $image) { | ||
| 443 | - $op[] = [ | ||
| 444 | - 'caption' => $image->image, | ||
| 445 | - 'url' => \yii\helpers\Url::to(['/product/manage/delimg', 'id' => $image->product_image_id]), | ||
| 446 | - 'key' => $image->product_image_id, | ||
| 447 | - 'extra' => [ | ||
| 448 | - 'id' => $image->product_image_id, | ||
| 449 | - ], | ||
| 450 | - ]; | 588 | + |
| 589 | + public function recalculateRating() | ||
| 590 | + { | ||
| 591 | + /** | ||
| 592 | + * @var ProductToRating $averageRating | ||
| 593 | + */ | ||
| 594 | + $average = $this->getComments() | ||
| 595 | + ->joinWith('rating') | ||
| 596 | + ->select([ 'average' => 'avg(artbox_comment_rating.value)::float' ]) | ||
| 597 | + ->scalar(); | ||
| 598 | + if (!$average) { | ||
| 599 | + $average = 0; | ||
| 600 | + } | ||
| 601 | + $averageRating = $this->averageRating; | ||
| 602 | + if (!empty( $averageRating )) { | ||
| 603 | + $averageRating->value = $average; | ||
| 604 | + } else { | ||
| 605 | + $averageRating = new ProductToRating( | ||
| 606 | + [ | ||
| 607 | + 'product_id' => $this->product_id, | ||
| 608 | + 'value' => $average, | ||
| 609 | + ] | ||
| 610 | + ); | ||
| 611 | + } | ||
| 612 | + if ($averageRating->save()) { | ||
| 613 | + return true; | ||
| 614 | + } else { | ||
| 615 | + return false; | ||
| 451 | } | 616 | } |
| 452 | } | 617 | } |
| 453 | - return $op; | ||
| 454 | - } | ||
| 455 | - | ||
| 456 | - public function recalculateRating() { | ||
| 457 | - /** | ||
| 458 | - * @var ProductToRating $averageRating | ||
| 459 | - */ | ||
| 460 | - $average = $this->getComments()->joinWith('rating')->select(['average' => 'avg(artbox_comment_rating.value)::float'])->scalar(); | ||
| 461 | - if(!$average) { | ||
| 462 | - $average = 0; | ||
| 463 | - } | ||
| 464 | - $averageRating = $this->averageRating; | ||
| 465 | - if(!empty($averageRating)) { | ||
| 466 | - $averageRating->value = $average; | ||
| 467 | - } else { | ||
| 468 | - $averageRating = new ProductToRating(['product_id' => $this->product_id, 'value' => $average]); | ||
| 469 | - } | ||
| 470 | - if($averageRating->save()) { | ||
| 471 | - return true; | ||
| 472 | - } else { | ||
| 473 | - return false; | 618 | + |
| 619 | + public function getComments() | ||
| 620 | + { | ||
| 621 | + return $this->hasMany(CommentModel::className(), [ 'entity_id' => 'product_id' ]) | ||
| 622 | + ->where( | ||
| 623 | + [ | ||
| 624 | + 'artbox_comment.entity' => self::className(), | ||
| 625 | + 'artbox_comment.status' => CommentModel::STATUS_ACTIVE, | ||
| 626 | + 'artbox_comment.artbox_comment_pid' => null, | ||
| 627 | + ] | ||
| 628 | + ); | ||
| 474 | } | 629 | } |
| 630 | + | ||
| 631 | + public function getAverageRating() | ||
| 632 | + { | ||
| 633 | + return $this->hasOne(ProductToRating::className(), [ 'product_id' => 'product_id' ]); | ||
| 634 | + } | ||
| 635 | + | ||
| 636 | + public function getTaxGroupsByLevel($level) | ||
| 637 | + { | ||
| 638 | + $categories = ArrayHelper::getColumn($this->categories, 'category_id'); | ||
| 639 | + return TaxGroup::find() | ||
| 640 | + ->distinct() | ||
| 641 | + ->innerJoin( | ||
| 642 | + 'tax_group_to_category', | ||
| 643 | + 'tax_group_to_category.tax_group_id = tax_group.tax_group_id' | ||
| 644 | + ) | ||
| 645 | + ->andWhere([ 'tax_group_to_category.category_id' => $categories ]) | ||
| 646 | + ->andWhere([ 'level' => $level ]); | ||
| 647 | + } | ||
| 648 | + | ||
| 649 | + public function setCategories($values) | ||
| 650 | + { | ||
| 651 | + $this->categories = $values; | ||
| 652 | + } | ||
| 653 | + | ||
| 654 | + public function setOptions($values) | ||
| 655 | + { | ||
| 656 | + $this->options = $values; | ||
| 657 | + } | ||
| 658 | + | ||
| 659 | + public function getFilters() | ||
| 660 | + { | ||
| 661 | + | ||
| 662 | + return $this->hasMany(TaxOption::className(), [ 'tax_option_id' => 'option_id' ]) | ||
| 663 | + ->viaTable('product_option', [ 'product_id' => 'product_id' ]) | ||
| 664 | + ->joinWith('taxGroup'); | ||
| 665 | + } | ||
| 666 | + | ||
| 475 | } | 667 | } |
| 476 | - | ||
| 477 | - public function getComments() { | ||
| 478 | - return $this->hasMany(CommentModel::className(), ['entity_id' => 'product_id'])->where(['artbox_comment.entity' => self::className(), 'artbox_comment.status' => CommentModel::STATUS_ACTIVE, 'artbox_comment.artbox_comment_pid' => NULL]); | ||
| 479 | - } | ||
| 480 | - | ||
| 481 | - public function getAverageRating() { | ||
| 482 | - return $this->hasOne(ProductToRating::className(), ['product_id' => 'product_id']); | ||
| 483 | - } | ||
| 484 | - | ||
| 485 | - public function getTaxGroupsByLevel($level) | ||
| 486 | - { | ||
| 487 | - $categories = ArrayHelper::getColumn($this->categories, 'category_id'); | ||
| 488 | - return TaxGroup::find()->distinct()->innerJoin('tax_group_to_category', 'tax_group_to_category.tax_group_id = tax_group.tax_group_id')->andWhere(['tax_group_to_category.category_id' => $categories])->andWhere(['level' => $level]); | ||
| 489 | - } | ||
| 490 | - | ||
| 491 | - public function setCategories($values) | ||
| 492 | - { | ||
| 493 | - $this->categories = $values; | ||
| 494 | - } | ||
| 495 | - | ||
| 496 | - public function setOptions($values) | ||
| 497 | - { | ||
| 498 | - $this->options = $values; | ||
| 499 | - } | ||
| 500 | - | ||
| 501 | - public function getFilters(){ | ||
| 502 | - | ||
| 503 | - return $this->hasMany(TaxOption::className(), ['tax_option_id' => 'option_id']) | ||
| 504 | - ->viaTable('product_option',[ 'product_id'=> 'product_id']) | ||
| 505 | - ->joinWith('taxGroup'); | ||
| 506 | - } | ||
| 507 | - | ||
| 508 | -} |
common/modules/rubrication/models/TaxGroup.php
| @@ -20,6 +20,7 @@ use Yii; | @@ -20,6 +20,7 @@ use Yii; | ||
| 20 | * @property integer $sort | 20 | * @property integer $sort |
| 21 | * @property boolean $display | 21 | * @property boolean $display |
| 22 | * @property boolean $is_menu | 22 | * @property boolean $is_menu |
| 23 | + * @property boolean $use_in_name | ||
| 23 | * @property TaxGroupToGroup[] $taxGroupToGroups | 24 | * @property TaxGroupToGroup[] $taxGroupToGroups |
| 24 | * @property TaxGroupToGroup[] $taxGroupToGroups0 | 25 | * @property TaxGroupToGroup[] $taxGroupToGroups0 |
| 25 | * @property TaxOption[] $taxOptions | 26 | * @property TaxOption[] $taxOptions |
| @@ -59,11 +60,12 @@ class TaxGroup extends \yii\db\ActiveRecord | @@ -59,11 +60,12 @@ class TaxGroup extends \yii\db\ActiveRecord | ||
| 59 | return [ | 60 | return [ |
| 60 | [['name', 'module'], 'required'], | 61 | [['name', 'module'], 'required'], |
| 61 | [['description', 'settings'], 'string'], | 62 | [['description', 'settings'], 'string'], |
| 62 | - [['hierarchical', 'is_filter', 'display','is_menu'], 'boolean'], | 63 | + [['hierarchical', 'is_filter', 'display','is_menu', 'use_in_name'], 'boolean'], |
| 63 | [['level', 'sort'], 'integer'], | 64 | [['level', 'sort'], 'integer'], |
| 64 | [['alias', 'module'], 'string', 'max' => 50], | 65 | [['alias', 'module'], 'string', 'max' => 50], |
| 65 | [['name'], 'string', 'max' => 255], | 66 | [['name'], 'string', 'max' => 255], |
| 66 | - [['categories'], 'safe'] | 67 | + [['categories'], 'safe'], |
| 68 | + [['use_in_name'], 'default', 'value' => false], | ||
| 67 | ]; | 69 | ]; |
| 68 | } | 70 | } |
| 69 | 71 | ||
| @@ -84,6 +86,7 @@ class TaxGroup extends \yii\db\ActiveRecord | @@ -84,6 +86,7 @@ class TaxGroup extends \yii\db\ActiveRecord | ||
| 84 | 'sort' => 'Sort', | 86 | 'sort' => 'Sort', |
| 85 | 'display' => 'Display', | 87 | 'display' => 'Display', |
| 86 | 'is_menu' => 'Отображать в меню', | 88 | 'is_menu' => 'Отображать в меню', |
| 89 | + 'use_in_name' => 'Использовать в названии', | ||
| 87 | ]; | 90 | ]; |
| 88 | } | 91 | } |
| 89 | 92 |
common/modules/rubrication/models/TaxOption.php
| @@ -20,6 +20,7 @@ use yii\db\ActiveRecord; | @@ -20,6 +20,7 @@ use yii\db\ActiveRecord; | ||
| 20 | * @property integer $default_value | 20 | * @property integer $default_value |
| 21 | * @property integer $name | 21 | * @property integer $name |
| 22 | * @property array $image | 22 | * @property array $image |
| 23 | + * @property string $synonym | ||
| 23 | * | 24 | * |
| 24 | * @property TaxEntityRelation[] $taxEntityRelations | 25 | * @property TaxEntityRelation[] $taxEntityRelations |
| 25 | * @property TaxGroup $taxGroup | 26 | * @property TaxGroup $taxGroup |
| @@ -74,7 +75,7 @@ class TaxOption extends \yii\db\ActiveRecord | @@ -74,7 +75,7 @@ class TaxOption extends \yii\db\ActiveRecord | ||
| 74 | return [ | 75 | return [ |
| 75 | [['tax_group_id','name'], 'required'], | 76 | [['tax_group_id','name'], 'required'], |
| 76 | [['tax_group_id', 'parent_id', 'sort', 'default_value'], 'integer'], | 77 | [['tax_group_id', 'parent_id', 'sort', 'default_value'], 'integer'], |
| 77 | - [['image','alias', 'value'], 'string', 'max' => 255], | 78 | + [['image','alias', 'value', 'synonym'], 'string', 'max' => 255], |
| 78 | [['tax_group_id'], 'exist', 'skipOnError' => true, 'targetClass' => TaxGroup::className(), 'targetAttribute' => ['tax_group_id' => 'tax_group_id']], | 79 | [['tax_group_id'], 'exist', 'skipOnError' => true, 'targetClass' => TaxGroup::className(), 'targetAttribute' => ['tax_group_id' => 'tax_group_id']], |
| 79 | ]; | 80 | ]; |
| 80 | } | 81 | } |
| @@ -92,6 +93,7 @@ class TaxOption extends \yii\db\ActiveRecord | @@ -92,6 +93,7 @@ class TaxOption extends \yii\db\ActiveRecord | ||
| 92 | 'sort' => Yii::t('app', 'Sort'), | 93 | 'sort' => Yii::t('app', 'Sort'), |
| 93 | 'default_value' => Yii::t('app', 'Default Value'), | 94 | 'default_value' => Yii::t('app', 'Default Value'), |
| 94 | 'image' => Yii::t('product', 'Image'), | 95 | 'image' => Yii::t('product', 'Image'), |
| 96 | + 'synonym' => Yii::t('product', 'Синоним'), | ||
| 95 | ]; | 97 | ]; |
| 96 | } | 98 | } |
| 97 | 99 |
common/modules/rubrication/views/tax-group/_form.php
| @@ -37,8 +37,10 @@ use common\components\artboxtree\ArtboxTreeHelper; | @@ -37,8 +37,10 @@ use common\components\artboxtree\ArtboxTreeHelper; | ||
| 37 | <?= $form->field($model, 'is_filter')->checkbox() ?> | 37 | <?= $form->field($model, 'is_filter')->checkbox() ?> |
| 38 | 38 | ||
| 39 | <?= $form->field($model, 'display')->checkbox() ?> | 39 | <?= $form->field($model, 'display')->checkbox() ?> |
| 40 | - | 40 | + |
| 41 | <?= $form->field($model, 'is_menu')->checkbox() ?> | 41 | <?= $form->field($model, 'is_menu')->checkbox() ?> |
| 42 | + | ||
| 43 | + <?= $form->field($model, 'use_in_name')->checkbox() ?> | ||
| 42 | 44 | ||
| 43 | <?= $form->field($model, 'sort')->textInput() ?> | 45 | <?= $form->field($model, 'sort')->textInput() ?> |
| 44 | 46 |
common/modules/rubrication/views/tax-option/_form.php
| @@ -30,8 +30,10 @@ use common\modules\rubrication\helpers\RubricationHelper; | @@ -30,8 +30,10 @@ use common\modules\rubrication\helpers\RubricationHelper; | ||
| 30 | 30 | ||
| 31 | <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?> | 31 | <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?> |
| 32 | <!-- --><?php //require(dirname(__FILE__) .'/value/_fields_'. $group->module .'.php')?> | 32 | <!-- --><?php //require(dirname(__FILE__) .'/value/_fields_'. $group->module .'.php')?> |
| 33 | - | 33 | + |
| 34 | <?= $form->field($model, 'alias')->textInput(['maxlength' => true]) ?> | 34 | <?= $form->field($model, 'alias')->textInput(['maxlength' => true]) ?> |
| 35 | + | ||
| 36 | + <?= $form->field($model, 'synonym')->textInput(['maxlength' => true]) ?> | ||
| 35 | 37 | ||
| 36 | <?php if ($group->hierarchical) { | 38 | <?php if ($group->hierarchical) { |
| 37 | $tree = TaxOption::find()->getTree($model->tax_group_id); | 39 | $tree = TaxOption::find()->getTree($model->tax_group_id); |
console/migrations/yarik/m170302_170344_add_synonym_and_use_in_menu.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use yii\db\Migration; | ||
| 4 | + | ||
| 5 | +class m170302_170344_add_synonym_and_use_in_menu extends Migration | ||
| 6 | +{ | ||
| 7 | + public function up() | ||
| 8 | + { | ||
| 9 | + $this->addColumn('tax_group', 'use_in_name', $this->boolean()->defaultValue(false)); | ||
| 10 | + $this->addColumn('tax_option', 'synonym', $this->string()); | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + public function down() | ||
| 14 | + { | ||
| 15 | + $this->dropColumn('tax_group', 'use_in_menu'); | ||
| 16 | + $this->dropColumn('tax_option', 'synonym'); | ||
| 17 | + } | ||
| 18 | +} |
console/migrations/yarik/m170302_173310_add_category_synonym_column.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use yii\db\Migration; | ||
| 4 | + | ||
| 5 | +class m170302_173310_add_category_synonym_column extends Migration | ||
| 6 | +{ | ||
| 7 | + public function up() | ||
| 8 | + { | ||
| 9 | + $this->addColumn('category', 'synonym', $this->string()); | ||
| 10 | + } | ||
| 11 | + | ||
| 12 | + public function down() | ||
| 13 | + { | ||
| 14 | + $this->dropColumn('category', 'synonym'); | ||
| 15 | + } | ||
| 16 | +} |
frontend/views/catalog/_product_item.php
| @@ -14,7 +14,7 @@ use yii\helpers\Url; | @@ -14,7 +14,7 @@ use yii\helpers\Url; | ||
| 14 | <div class="item_container" > | 14 | <div class="item_container" > |
| 15 | <input class="prodInfo" type="hidden" value="[]"> | 15 | <input class="prodInfo" type="hidden" value="[]"> |
| 16 | <div class="title"> | 16 | <div class="title"> |
| 17 | - <?= Html::a( $model->name, Url::to(['catalog/product', 'product' => $model->alias]), ['class'=>'btn-product-details','data-pjax'=>0, 'itemprop' => 'name'] )?> | 17 | + <?= Html::a( $model->getFullName(), Url::to(['catalog/product', 'product' => $model->alias]), ['class'=>'btn-product-details','data-pjax'=>0, 'itemprop' => 'name'] )?> |
| 18 | </div> | 18 | </div> |
| 19 | <div class="img"> | 19 | <div class="img"> |
| 20 | <a data-pjax=0 class="btn-product-details" | 20 | <a data-pjax=0 class="btn-product-details" |