diff --git a/common/modules/product/helpers/ProductHelper.php b/common/modules/product/helpers/ProductHelper.php
index f8a6ec2..2fc32e5 100755
--- a/common/modules/product/helpers/ProductHelper.php
+++ b/common/modules/product/helpers/ProductHelper.php
@@ -5,6 +5,7 @@ namespace common\modules\product\helpers;
use common\modules\product\models\Brand;
use common\modules\product\models\Category;
use common\modules\product\models\Product;
+use common\modules\product\models\ProductVariant;
use yii\base\Object;
use Yii;
@@ -69,7 +70,8 @@ class ProductHelper extends Object {
public static function getLastProducts($as_object = false) {
$last_products = Yii::$app->session->get('last_products', []);
if ($as_object) {
- $last_products = array_reverse(Product::find()->where(['product_id' => $last_products])->all());
+ $last_products = array_reverse(Product::find()->where([Product::tableName() .'.product_id' => $last_products])->all());
+// $last_products = array_reverse(Product::find()->joinWith('variants')->where([Product::tableName() .'.product_id' => $last_products])->andWhere(['!=', ProductVariant::tableName() .'.stock', 0])->all());
}
return $last_products;
}
@@ -86,6 +88,6 @@ class ProductHelper extends Object {
$data = ['akciya' => true];
break;
}
- return Product::find()->where($data)->limit($count)/*->orderBy($sort)*/->all();
+ return Product::find()->joinWith('variants')->where($data)->andWhere(['!=', ProductVariant::tableName() .'.stock', 0])->limit($count)/*->orderBy($sort)*/->all();
}
}
\ No newline at end of file
diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php
index 9907ecb..8b5357c 100755
--- a/common/modules/product/models/Category.php
+++ b/common/modules/product/models/Category.php
@@ -134,8 +134,11 @@ class Category extends \yii\db\ActiveRecord
}
public function getProducts() {
-// return $this->hasMany(Product::className(), ['product_id' => 'product_id'])->viaTable('product_category', ['category_id' => 'category_id']);
- return $this->getRelations('product_categories');
+ return $this->hasMany(Product::className(), ['product_id' => 'product_id'])
+ ->viaTable('product_category', ['category_id' => 'category_id'])
+ ->with(['variants'])
+ ->andOnCondition(['!=', ProductVariant::tableName() .'.stock', 0]);
+// return $this->getRelations('product_categories');
}
/**
diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php
index f28f911..6efdb51 100755
--- a/common/modules/product/models/Product.php
+++ b/common/modules/product/models/Product.php
@@ -144,14 +144,24 @@ 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']);
}
+ /**
+ * @return \yii\db\ActiveQuery
+ */
+ public function getEnabledVariant()
+ {
+ return $this->hasOne(ProductVariant::className(), ['product_id' => 'product_id'])->andOnCondition(['!=', ProductVariant::tableName() .'.stock', 0]);
+ }
public function getVariantPrice() {
return $this->variant->price;
}
+ public function getEnabledVariantPrice() {
+ return $this->enabledVariant->price;
+ }
+
/**
* @return \yii\db\ActiveQuery
*/
@@ -162,14 +172,7 @@ class Product extends \yii\db\ActiveRecord
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]);
+ return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id'])->andOnCondition(['!=', ProductVariant::tableName() .'.stock', 0]);
}
public function setVariants($variants) {
diff --git a/console/controllers/ImportController.php b/console/controllers/ImportController.php
index bf6acbb..9e77457 100755
--- a/console/controllers/ImportController.php
+++ b/console/controllers/ImportController.php
@@ -416,7 +416,7 @@ class ImportController extends Controller {
while (($data = fgetcsv ($handle, 10000, ";")) !== FALSE) {
$j++;
-// if ($j > 10) {
+// if ($j > 1) {
// return TRUE;
// }
@@ -429,14 +429,20 @@ class ImportController extends Controller {
// данные строк
$modification_code = @$data[0];
- $price = floatval(@$data[1]);
- $price_promo = floatval(@$data[2]);
+ $_price = floatval(@$data[1]);
+ $_price_promo = floatval(@$data[2]);
$count = intval(@$data[3]);
$city_name = @$data[4];
$product_title = @$data[5];
+ // @todo refactory this code
+ $price = $_price_promo > 0 ? $_price_promo : $_price;
+ $price_promo = $_price_promo > 0 ? $_price : $_price_promo;
+
+ $modification_code = trim($modification_code);
+
if (empty ($modification_code)) {
- CONTINUE;
+ continue;
}
// товары в пути
if (empty ($city_name))
@@ -446,28 +452,28 @@ class ImportController extends Controller {
Yii::getAlias('@uploadFilePricesAway')
);
-// $this->stdout("Товар $product_title в пути\n");
+ $this->stdout("~ Товар $product_title в пути\n");
- CONTINUE;
+ continue;
}
- if ( ($productVariant = ProductVariant::find()->filterWhere(['ilike', 'sku', trim($modification_code)])->one()) === null ) {
+ if ( ($productVariant = ProductVariant::find()->filterWhere(['sku' => $modification_code])->one()) === null ) {
// 'Нет даной модификации в базе';
$this->saveNotFoundRecord (
[$modification_code, $product_title],
Yii::getAlias('@uploadFilePricesNoVariant')
);
-// $this->stdout("Для товара $product_title (#$modification_code) не найдено соотвествия\n");
+ $this->stdout("- Для товара $product_title (#$modification_code) не найдено соотвествия\n");
- CONTINUE;
+ continue;
}
$quantity = 0;
// ===== Set stock ====
if ( $city_name ) {
- if ( ($stock = Stock::find()->filterWhere(['ilike', 'name', trim($city_name)])->one()) === null ) {
+ if ( ($stock = Stock::find()->filterWhere(['name' => trim($city_name)])->one()) === null ) {
// Create stock
$stock = new Stock();
$stock->name = trim($city_name);
@@ -484,7 +490,7 @@ class ImportController extends Controller {
$productVariant->save();
-// $this->stdout("Товар $product_title успешно сохранен\n");
+ $this->stdout("+ Товар $product_title успешно сохранен\n");
}
fclose ($handle);
diff --git a/frontend/controllers/CatalogController.php b/frontend/controllers/CatalogController.php
index b301f01..7184ed6 100755
--- a/frontend/controllers/CatalogController.php
+++ b/frontend/controllers/CatalogController.php
@@ -108,20 +108,6 @@ class CatalogController extends \yii\web\Controller
if ( !empty($filter['options']) ) {
$params['options'] = $filter['options'];
- /*$optionQuery = TaxOption::find();
- $optionQuery->select('tax_option_id');
- $optionQuery->innerJoinWith('group');
- foreach ($filter['options'] as $option_key => $option_values) {
- $optionQuery->orWhere([
- 'tax_group_id' => $option_key,
- 'alias' => $filter['options']
- ]);
- }
- $options = ->where(['in', 'alias', $filter['options']])->all();
- $params['options'] = [];
- foreach ($options as $option) {
- $params['options'][] = $option->tax_option_id;
- }*/
}
if ( !empty($filter['prices']) ) {
diff --git a/frontend/models/ProductFrontendSearch.php b/frontend/models/ProductFrontendSearch.php
index 801e2a1..45bd4ae 100755
--- a/frontend/models/ProductFrontendSearch.php
+++ b/frontend/models/ProductFrontendSearch.php
@@ -54,14 +54,10 @@ class ProductFrontendSearch extends Product {
} else {
$query = Product::find();
}
- $query->joinWith(['variant', 'brand', 'brand.brandName', 'category', 'category.categoryName']);
+ $query->joinWith(['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' => [
diff --git a/frontend/views/catalog/product.php b/frontend/views/catalog/product.php
index 9b3c566..5bce498 100755
--- a/frontend/views/catalog/product.php
+++ b/frontend/views/catalog/product.php
@@ -13,7 +13,7 @@ $this->title = $product->fullname;
//}
$this->params['breadcrumbs'][] = ['label' => 'Каталог', 'url' => ['catalog/category']];
$this->params['breadcrumbs'][] = ['label' => $product->category->categoryName->value, 'url' => ['catalog/category', 'category' => $product->category]];
-$this->params['breadcrumbs'][] = $product->fullname .' #'. $product->variant->sku;
+$this->params['breadcrumbs'][] = $product->fullname .' #'. $product->enabledVariant->sku;
$this->registerJs ('
@@ -96,8 +96,7 @@ $this->registerJs ("
= $product->fullname ?>
Цветовые решения
- variants as $variant): ?>
- quantity == 0) continue;?>
+ enabledVariants as $variant): ?>
-
registerJs ("
diff --git a/frontend/views/catalog/product_item.php b/frontend/views/catalog/product_item.php
index c9aaf3e..fc1027a 100755
--- a/frontend/views/catalog/product_item.php
+++ b/frontend/views/catalog/product_item.php
@@ -5,8 +5,8 @@ use yii\helpers\Url;
-
is_top) || !empty($product->is_new) || !empty($product->akciya)) :?>
@@ -25,7 +25,7 @@ use yii\helpers\Url;
= $product->fullname ?>
@@ -35,12 +35,12 @@ use yii\helpers\Url;
echo '
';
echo '
';
// есть скидка
- if ($product->variant->price_old != 0 && $product->variant->price_old != $product->variant->price)
+ if ($product->enabledVariant->price_old != 0 && $product->enabledVariant->price_old != $product->enabledVariant->price)
{
- echo ''.$product->variant->price_old.' грн. ';
+ echo ''.$product->enabledVariant->price_old.' грн. ';
}
- echo $product->variant->price.' грн.
';
+ echo $product->enabledVariant->price.'
грн.';
echo '
';
@@ -49,13 +49,12 @@ use yii\helpers\Url;
Купить
enabledVariants as $variant) : ?>
- quantity == 0) continue;?>
image)) :?>
-
';
echo '
'
?>
-= \frontend\widgets\Rubrics::widget(['wrapper' => 'rubrics', 'includes' => [136,137,138,139,140]])?>
+= \frontend\widgets\Rubrics::widget(['wrapper' => 'rubrics', 'includes' => [130,131,132,133,134]])?>
= \common\modules\product\widgets\specialProducts::widget(['type' => 'promo'])?>
= \common\modules\product\widgets\specialProducts::widget(['type' => 'new'])?>
--
libgit2 0.21.4