diff --git a/CatalogUrlManager.php b/CatalogUrlManager.php old mode 100644 new mode 100755 index c9161a4..c9161a4 --- a/CatalogUrlManager.php +++ b/CatalogUrlManager.php diff --git a/behaviors/DefaultVariantBehavior.php b/behaviors/DefaultVariantBehavior.php old mode 100644 new mode 100755 index c52d641..c52d641 --- a/behaviors/DefaultVariantBehavior.php +++ b/behaviors/DefaultVariantBehavior.php diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 index 965ed36..965ed36 --- a/composer.json +++ b/composer.json diff --git a/console/GenerateController.php b/console/GenerateController.php old mode 100644 new mode 100755 index c36f8e8..c36f8e8 --- a/console/GenerateController.php +++ b/console/GenerateController.php diff --git a/controllers/ManageController.php b/controllers/ManageController.php index b3b13e4..7b89685 100755 --- a/controllers/ManageController.php +++ b/controllers/ManageController.php @@ -2,6 +2,7 @@ namespace artweb\artbox\ecommerce\controllers; + use artweb\artbox\ecommerce\models\ProductVideo; use artweb\artbox\language\models\Language; use artweb\artbox\ecommerce\models\Export; use artweb\artbox\ecommerce\models\Import; @@ -147,6 +148,7 @@ 'model' => $model, 'modelLangs' => $model->modelLangs, 'groups' => $groups, + 'videos' => !empty( $model->videos ) ? $model->videos : [ new ProductVideo() ], ] ); } @@ -354,7 +356,7 @@ throw new \HttpRequestException('Must be AJAX'); } } - + /** * Perform export * @@ -397,7 +399,7 @@ if (( $model = Product::find() ->where([ 'id' => $id ]) ->with('lang') - ->one() ) !== null + ->one() ) !== NULL ) { return $model; } else { diff --git a/models/Product.php b/models/Product.php index 3e7ddd1..0325c6f 100755 --- a/models/Product.php +++ b/models/Product.php @@ -21,6 +21,7 @@ * * @property integer $brand_id * @property integer $id + * @property ProductVideo[] $videos * @property Category $category * @property Category[] $categories * @property ProductVariant $variant @@ -340,8 +341,12 @@ public function getFullName():string { $name = ''; - if (!empty($this->category->lang->category_synonym)) $name = $name . $this->category->lang->category_synonym . ' '; - if (!empty($this->brand)) $name = $name . $this->brand->lang->title . ' '; + if (!empty( $this->category->lang->category_synonym )) { + $name = $name . $this->category->lang->category_synonym . ' '; + } + if (!empty( $this->brand )) { + $name = $name . $this->brand->lang->title . ' '; + } $name .= $this->lang->title; return $name; } @@ -455,6 +460,11 @@ return $groups; } + public function getVideos() + { + return $this->hasMany(ProductVideo::className(), [ 'product_id' => 'id' ]); + } + /** * Get Stock query where current Product is in stock * diff --git a/models/ProductFrontendSearch.php b/models/ProductFrontendSearch.php old mode 100644 new mode 100755 index 0f0258e..0f0258e --- a/models/ProductFrontendSearch.php +++ b/models/ProductFrontendSearch.php diff --git a/models/ProductToRating.php b/models/ProductToRating.php old mode 100644 new mode 100755 index 820cfcb..820cfcb --- a/models/ProductToRating.php +++ b/models/ProductToRating.php diff --git a/models/ProductVariant.php b/models/ProductVariant.php index 1e5731a..6e3f409 100755 --- a/models/ProductVariant.php +++ b/models/ProductVariant.php @@ -67,6 +67,10 @@ */ class ProductVariant extends ActiveRecord { + + public $customOption = []; + + /** * @var int[] $options */ @@ -113,7 +117,7 @@ 'model' => ProductImage::className(), 'config' => [ 'caption' => 'image', - 'delete_action' => '/product/variant/delete-image', + 'delete_action' => 'variant/delete-image', 'id' => 'id', ], ], @@ -275,6 +279,28 @@ return $this->hasMany(TaxOption::className(), [ 'id' => 'option_id' ]) ->viaTable('product_variant_option', [ 'product_variant_id' => 'id' ]); } + + /** + * Get one variant's option whith needed conditions, or random if condition is empty + * + * @param array $conditions + * + * @return ActiveQuery + */ + public function getOption(array $conditions = []) + { + $query = $this->hasOne(TaxOption::className(), [ 'id' => 'option_id' ]) + ->viaTable('product_variant_option', [ 'product_variant_id' => 'id' ]); + foreach ($conditions as $condition) + { + if (!empty($condition) && is_array($condition)) + { + $query->andFilterWhere($condition); + } + } + + return $query; + } /** * Get TaxOptions with preloaded TaxGroups for current ProductVariant @@ -307,13 +333,15 @@ { $this->options = $values; } - + /** * Get all TaxGroups for current ProductVariant filled with $customOptions that satisfy current ProductVariant * - * @return TaxGroup[] + * @param array $conditions + * + * @return \artweb\artbox\ecommerce\models\TaxGroup[] */ - public function getProperties() + public function getProperties(array $conditions = []) { $groups = $options = []; foreach ($this->getOptions() @@ -324,11 +352,18 @@ */ $options[ $option->tax_group_id ][] = $option; } - foreach (TaxGroup::find() + $query = TaxGroup::find() ->where([ 'tax_group.id' => array_keys($options) ]) ->orderBy([ 'sort' => SORT_ASC ]) - ->with('lang') - ->all() as $group) { + ->with('lang'); + + if (!empty($conditions)) { + foreach ($conditions as $condition) { + $query->andFilterWhere($condition); + } + } + foreach ( + $query->all() as $group) { /** * @var TaxGroup $group */ diff --git a/models/ProductVideo.php b/models/ProductVideo.php new file mode 100644 index 0000000..f13fb22 --- /dev/null +++ b/models/ProductVideo.php @@ -0,0 +1,69 @@ + 255, + ], + [ + [ 'product_id' ], + 'exist', + 'skipOnError' => true, + 'targetClass' => Product::className(), + 'targetAttribute' => [ 'product_id' => 'id' ], + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => \Yii::t('app', 'ID'), + 'product_id' => \Yii::t('app', 'Product ID'), + 'url' => \Yii::t('app', 'Url'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getProduct() + { + return $this->hasOne(Product::className(), [ 'id' => 'product_id' ]); + } + } diff --git a/models/StockLang.php b/models/StockLang.php old mode 100644 new mode 100755 index 4d86f5a..4d86f5a --- a/models/StockLang.php +++ b/models/StockLang.php diff --git a/models/TaxGroup.php b/models/TaxGroup.php index 575494b..ca4a5d3 100755 --- a/models/TaxGroup.php +++ b/models/TaxGroup.php @@ -24,6 +24,7 @@ * @property TaxOption[] $options * @property TaxOption[] $customOptions * @property string $alias + * @property integer $position * * From language behavior * * @property TaxGroupLang $lang * @property TaxGroupLang[] $langs @@ -94,6 +95,7 @@ [ 'level', 'sort', + 'position', ], 'integer', ], @@ -116,6 +118,7 @@ 'display' => 'Display', 'is_menu' => 'Отображать в меню', 'level' => 'уровень', + 'ppsition' => 'Позиция', ]; } diff --git a/views/manage/_form.php b/views/manage/_form.php index 535a184..d9b708a 100755 --- a/views/manage/_form.php +++ b/views/manage/_form.php @@ -1,9 +1,11 @@ registerJs($js, View::POS_END); ?>