From 1e55b4b87ef6db37cb7d3a89bc3c35653d89a625 Mon Sep 17 00:00:00 2001 From: Karnovsky A Date: Mon, 30 May 2016 09:03:05 +0300 Subject: [PATCH] - --- common/modules/product/models/Product.php | 22 +++++++++++++++++++++- common/modules/product/models/ProductVariant.php | 6 ++++-- frontend/views/catalog/catalog.php | 2 +- frontend/views/catalog/product.php | 5 +---- frontend/views/catalog/product_item.php | 3 ++- frontend/views/site/index.php | 2 +- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php index 111bb54..f28f911 100755 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -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'])->where(['product_variant_id' => null]); } /** @@ -144,12 +144,14 @@ class Product extends \yii\db\ActiveRecord */ public function getVariant() { +// return ProductVariant::find()->filterWhere([ProductVariant::tableName() .'.product_id' => Product::tableName() .'.product_id'])->where('>', ProductVariant::tableName() .'.stock', 0); return $this->hasOne(ProductVariant::className(), ['product_id' => 'product_id']); } public function getVariantPrice() { return $this->variant->price; } + /** * @return \yii\db\ActiveQuery */ @@ -158,6 +160,18 @@ class Product extends \yii\db\ActiveRecord return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id']); } + public function getEnabledVariants() + { + /*$result = []; + foreach ($this->variants as $variant) { + if (is_null($variant->stock) || $variant->stock > 0) { + $result[] = $variant; + } + } + return $result;*/ + return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id'])->where(['!=', ProductVariant::tableName() .'.stock', 0]); + } + public function setVariants($variants) { $this->_variants = $variants; } @@ -201,6 +215,12 @@ class Product extends \yii\db\ActiveRecord return new ProductQuery(get_called_class()); } + public function getQuantity() { + return ProductStock::find() + ->where(['product_id' => $this->product_id]) + ->sum('quantity'); + } + public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); diff --git a/common/modules/product/models/ProductVariant.php b/common/modules/product/models/ProductVariant.php index 7bbbfc8..90f3b64 100755 --- a/common/modules/product/models/ProductVariant.php +++ b/common/modules/product/models/ProductVariant.php @@ -108,12 +108,14 @@ class ProductVariant extends \yii\db\ActiveRecord return $this->hasOne(Product::className(), ['product_id' => 'product_id']); } + public function getProductStock() { + return $this->hasMany(ProductStock::className(), ['product_variant_id' => 'product_variant_id']); + } + public function getQuantity() { return ProductStock::find() ->where(['product_variant_id' => $this->product_variant_id]) ->sum('quantity'); -// return $this->hasMany(Stock::className(), ['stock_id' => 'stock_id'])->viaTable(ProductStock::tableName(), ['product_id' => 'product_id'])->sum(ProductStock::tableName() .'.quantity') > 0; -// return $this->stock !== 0; } public function getStock_caption() { diff --git a/frontend/views/catalog/catalog.php b/frontend/views/catalog/catalog.php index cffd4e4..0484e39 100644 --- a/frontend/views/catalog/catalog.php +++ b/frontend/views/catalog/catalog.php @@ -17,7 +17,7 @@ $this->params['breadcrumbs'][] = ['label' => 'Каталог'];

Каталог

- 'rubrics', 'includes' => [124,125,126,127,128]])?> + 'rubrics', 'includes' => [136,137,138,139,140]])?>
diff --git a/frontend/views/catalog/product.php b/frontend/views/catalog/product.php index b0bb01d..9b3c566 100755 --- a/frontend/views/catalog/product.php +++ b/frontend/views/catalog/product.php @@ -97,7 +97,7 @@ $this->registerJs ("
Цветовые решения