diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php index b3ca7cc..6cc697f 100755 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -127,8 +127,8 @@ class Product extends \yii\db\ActiveRecord */ public function getImageUrl() { - // return a default image placeholder if your source image is not found - return !empty($this->image) ? $this->image->imageUrl : '/images/no_photo.png'; + $image = empty($this->variant) ? null : $this->variant->image; + return !empty($image) ? $image->imageUrl : '/images/no_photo.png'; } /** @@ -136,7 +136,7 @@ class Product extends \yii\db\ActiveRecord */ public function getImages() { - return $this->hasMany(ProductImage::className(), ['product_id' => 'product_id']); + return $this->hasMany(ProductImage::className(), ['product_id' => 'product_id'])->filterWhere(['is', 'product_variant_id', NULL]); } /** @@ -144,7 +144,7 @@ class Product extends \yii\db\ActiveRecord */ public function getVariant() { - return $this->hasOne(ProductVariant::className(), ['product_id' => 'product_id']); + return $this->hasOne(ProductVariant::className(), ['product_id' => 'product_id'])->orderBy('product_variant.product_variant_id', SORT_ASC); } public function getVariantPrice() { @@ -215,27 +215,29 @@ class Product extends \yii\db\ActiveRecord // // } - $todel = []; - foreach ($this->variants ? : [] as $_variant) { - $todel[$_variant->product_variant_id] = $_variant->product_variant_id; - } - foreach ($this->_variants as $_variant) { - if (!is_array($_variant)) { - return; + if (!empty($this->_variants)) { + $todel = []; + foreach ($this->variants ?: [] as $_variant) { + $todel[$_variant->product_variant_id] = $_variant->product_variant_id; } - if (!empty($_variant['product_variant_id'])) { - unset($todel[$_variant['product_variant_id']]); - $model = ProductVariant::findOne($_variant['product_variant_id']); - } else { - $model = new ProductVariant(); + foreach ($this->_variants as $_variant) { + if (!is_array($_variant)) { + return; + } + if (!empty($_variant['product_variant_id'])) { + unset($todel[$_variant['product_variant_id']]); + $model = ProductVariant::findOne($_variant['product_variant_id']); + } else { + $model = new ProductVariant(); + } + $_variant['product_id'] = $this->product_id; + $model->load(['ProductVariant' => $_variant]); + $model->product_id = $this->product_id; + $model->save(); + } + if (!empty($todel)) { + ProductVariant::deleteAll(['product_variant_id' => $todel]); } - $_variant['product_id'] = $this->product_id; - $model->load(['ProductVariant' => $_variant]); - $model->product_id = $this->product_id; - $model->save(); - } - if (!empty($todel)) { - ProductVariant::deleteAll(['product_variant_id' => $todel]); } } diff --git a/common/modules/product/models/ProductSearch.php b/common/modules/product/models/ProductSearch.php index 44a49e6..314d941 100755 --- a/common/modules/product/models/ProductSearch.php +++ b/common/modules/product/models/ProductSearch.php @@ -14,6 +14,8 @@ use yii\web\NotFoundHttpException; class ProductSearch extends Product { public $brand_name; + public $brand_id; + public $category_id; public $category_name; public $variant_sku; @@ -23,7 +25,7 @@ class ProductSearch extends Product public function rules() { return [ - [['name', 'brand_name', 'category_name', 'variant_sku'], 'safe'], + [['name', 'brand_name', 'brand_id', 'category_id', 'category_name', 'variant_sku'], 'safe'], [['tax_brand_id', 'product_id'], 'integer'], [['is_top', 'is_new', 'akciya'], 'boolean'], ]; @@ -49,17 +51,16 @@ class ProductSearch extends Product { $query = Product::find(); - // add conditions that should always apply here + $query->joinWith(['brand', 'brand.brandNames', 'categories', 'categories.categoryNames', 'variant']); + + $query->groupBy(['product.product_id']); + $query->orderBy('product.product_id', 'DESC'); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); - $this->load($params); - - if (!$this->validate()) { - // uncomment the following line if you do not want to return any records when validation fails - // $query->where('0=1'); + if ( !($this->load($params) && $this->validate()) ) { return $dataProvider; } @@ -77,8 +78,6 @@ class ProductSearch extends Product ] ]); - $query->joinWith(['brand', 'brand.brandNames', 'categories', 'categories.categoryNames', 'variant']); - if (isset($this->is_top)) { $query->andFilterWhere([ 'is_top' => (bool)$this->is_top, @@ -95,18 +94,16 @@ class ProductSearch extends Product ]); } $query->andFilterWhere([ - 'tax_brand_id' => $this->tax_brand_id, - 'product_id' => $this->product_id, + 'product.brand_id' => $this->brand_id, + 'product.product_id' => $this->product_id, + 'product_category.category_id' => $this->category_id ]); - $query->andFilterWhere(['ilike', 'name', $this->name]); + $query->andFilterWhere(['ilike', 'product.name', $this->name]); $query->andFilterWhere(['ilike', 'brand_name.value', $this->brand_name]); $query->andFilterWhere(['ilike', 'category_name.value', $this->category_name]); $query->andFilterWhere(['ilike', 'product_variant.sku', $this->variant_sku]); - $query->groupBy(['product.product_id']); - $query->orderBy('product.product_id', 'DESC'); - return $dataProvider; } diff --git a/common/modules/product/models/ProductVariant.php b/common/modules/product/models/ProductVariant.php index feecd22..bddce79 100755 --- a/common/modules/product/models/ProductVariant.php +++ b/common/modules/product/models/ProductVariant.php @@ -111,7 +111,7 @@ class ProductVariant extends \yii\db\ActiveRecord } public function getStock_caption() { - return is_null($this->stock) ? '∞' : intval($this->stock); + return is_null($this->stock) ? '∞' : ($this->stock > 0 ? Yii::t('product', 'Enable') : Yii::t('product', 'Disable')); // intval($this->stock); } /** diff --git a/common/modules/product/views/manage/index.php b/common/modules/product/views/manage/index.php index b21de4a..5fc4527 100755 --- a/common/modules/product/views/manage/index.php +++ b/common/modules/product/views/manage/index.php @@ -2,6 +2,11 @@ use yii\helpers\Html; use yii\grid\GridView; +use yii\helpers\ArrayHelper; +use kartik\select2\Select2; +use common\components\artboxtree\ArtboxTreeHelper; +use common\modules\product\helpers\ProductHelper; + /* @var $this yii\web\View */ /* @var $searchModel common\modules\product\models\ProductSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ @@ -28,11 +33,45 @@ $this->params['breadcrumbs'][] = $this->title; 'label' => Yii::t('product', 'Brand'), 'attribute' => 'brand_name', 'value' => 'brand.name', + 'format' => 'raw', + 'filter' => Select2::widget([ + 'model' => $searchModel, + 'attribute' => 'brand_id', + 'data' => ArrayHelper::map(ProductHelper::getBrands()->all(), 'brand_id', 'name'), + 'language' => 'ru', + 'options' => [ + 'placeholder' => Yii::t('product', 'Select brand'), + 'multiple' => false, + ], + 'pluginOptions' => [ + 'allowClear' => true + ], + ]) ], [ 'label' => Yii::t('product', 'Category'), 'attribute' => 'category_name', - 'value' => 'category.name', + 'value' => function($model) { + $categories = []; + foreach ($model->categories as $category) { + $categories[] = $category->name; + } + return implode(", ", $categories); + }, + 'format' => 'raw', + 'filter' => Select2::widget([ + 'model' => $searchModel, + 'attribute' => 'category_id', + 'data' => ArtboxTreeHelper::treeMap(ProductHelper::getCategories(), 'category_id', 'name'), + 'language' => 'ru', + 'options' => [ + 'placeholder' => Yii::t('product', 'Select category'), + 'multiple' => false, + ], + 'pluginOptions' => [ + 'allowClear' => true + ], + ]) ], [ 'label' => Yii::t('product', 'SKU'), @@ -40,9 +79,12 @@ $this->params['breadcrumbs'][] = $this->title; 'value' => 'variant.sku', ], 'variant.price', - 'variant.stock_caption', - - + 'variant.price_old', + [ + 'label' => Yii::t('product', 'Stock'), + 'attribute' => 'variant_stock', + 'value' => 'variant.stock_caption', + ], [ 'class' => 'yii\grid\ActionColumn', 'template' => '{view} |{is_top} {is_new} {akciya} | {update} {delete}', diff --git a/common/modules/product/widgets/views/product_smart.php b/common/modules/product/widgets/views/product_smart.php index d0ed55f..3f061a1 100755 --- a/common/modules/product/widgets/views/product_smart.php +++ b/common/modules/product/widgets/views/product_smart.php @@ -12,6 +12,19 @@ use yii\helpers\Url; imageUrl, 'list')?> + is_top) || !empty($product->is_new) || !empty($product->akciya)) :?> + + -
+

- registerJs($js, View::POS_READY); -?> \ No newline at end of file +?> + diff --git a/common/translation/ru/product.php b/common/translation/ru/product.php index b786b0e..f2910c1 100755 --- a/common/translation/ru/product.php +++ b/common/translation/ru/product.php @@ -13,4 +13,17 @@ return [ 'Top products' => 'Популярные', 'Brands' => 'Бренды', 'Brand' => 'Бренд', + 'Categories' => 'Категории', + 'Category' => 'Категория', + 'Select brand' => 'Выберите бренд', + 'Select category' => 'Выберите категорию', + 'SKU' => 'Артикул', + 'Stock' => 'Остаток', + 'Price' => 'Цена', + 'Price Old' => 'Старая Цена', + 'Products' => 'Товары', + 'Product' => 'Товар', + 'Create Product' => 'Создать Товар', + 'Enable' => 'Доступно', + 'Disable' => 'Отсутсвует', ]; \ No newline at end of file diff --git a/composer_2.phar b/composer_2.phar new file mode 100644 index 0000000..946d4d1 Binary files /dev/null and b/composer_2.phar differ diff --git a/frontend/models/ProductFrontendSearch.php b/frontend/models/ProductFrontendSearch.php index d4b4954..3f3876a 100755 --- a/frontend/models/ProductFrontendSearch.php +++ b/frontend/models/ProductFrontendSearch.php @@ -51,18 +51,18 @@ class ProductFrontendSearch extends Product { } else { $query = Product::find(); } - $query->joinWith('variant'); - $query->joinWith('brand'); - $query->joinWith('image'); - $query->joinWith('categories'); - if (empty($_GET['sort']) || ($_GET['sort'] != 'price' && $_GET['sort'] != '-price')) { - $query->groupBy('product.product_id'); - } + $query->with(['variant', 'variant.image', 'brand', 'brand.brandName', 'category', 'category.categoryName']); + + $query->groupBy('product.product_id'); + +// if (empty($_GET['sort']) || ($_GET['sort'] != 'price' && $_GET['sort'] != '-price')) { +// $query->groupBy('product.product_id'); +// } $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ - 'pageSize' => 15, + 'pageSize' => 16, ], 'sort' => [ 'attributes' => [ diff --git a/frontend/views/catalog/product.php b/frontend/views/catalog/product.php index 06b01e4..da2ba47 100755 --- a/frontend/views/catalog/product.php +++ b/frontend/views/catalog/product.php @@ -160,7 +160,7 @@ $this->registerJs (" video)) :?>
  • Видео
    - false, 'url' => $product->video]); ?> + video, 'video, 'video : \cics\widgets\VideoEmbed::widget(['responsive' => false, 'url' => $product->video]); ?>
  • @@ -182,6 +182,11 @@ $this->registerJs ("
    + + 'promo'])?> + 'new'])?> + 'top'])?> + registerJs (" diff --git a/frontend/views/catalog/product_item.php b/frontend/views/catalog/product_item.php index 5f8162b..1b34e9b 100755 --- a/frontend/views/catalog/product_item.php +++ b/frontend/views/catalog/product_item.php @@ -6,19 +6,19 @@ use yii\helpers\Url;
    - variant->image->imageUrl, 'list')?> + variant->imageUrl, 'list')?>
    is_top) || !empty($product->is_new) || !empty($product->akciya)) :?> @@ -54,11 +54,13 @@ use yii\helpers\Url;
    \ No newline at end of file -- libgit2 0.21.4