Commit d48d8bc0ba7c3135780371616275c602541a3236
1 parent
1e55b4b8
-
Showing
9 changed files
with
50 additions
and
56 deletions
Show diff stats
common/modules/product/helpers/ProductHelper.php
| @@ -5,6 +5,7 @@ namespace common\modules\product\helpers; | @@ -5,6 +5,7 @@ namespace common\modules\product\helpers; | ||
| 5 | use common\modules\product\models\Brand; | 5 | use common\modules\product\models\Brand; |
| 6 | use common\modules\product\models\Category; | 6 | use common\modules\product\models\Category; |
| 7 | use common\modules\product\models\Product; | 7 | use common\modules\product\models\Product; |
| 8 | +use common\modules\product\models\ProductVariant; | ||
| 8 | use yii\base\Object; | 9 | use yii\base\Object; |
| 9 | use Yii; | 10 | use Yii; |
| 10 | 11 | ||
| @@ -69,7 +70,8 @@ class ProductHelper extends Object { | @@ -69,7 +70,8 @@ class ProductHelper extends Object { | ||
| 69 | public static function getLastProducts($as_object = false) { | 70 | public static function getLastProducts($as_object = false) { |
| 70 | $last_products = Yii::$app->session->get('last_products', []); | 71 | $last_products = Yii::$app->session->get('last_products', []); |
| 71 | if ($as_object) { | 72 | if ($as_object) { |
| 72 | - $last_products = array_reverse(Product::find()->where(['product_id' => $last_products])->all()); | 73 | + $last_products = array_reverse(Product::find()->where([Product::tableName() .'.product_id' => $last_products])->all()); |
| 74 | +// $last_products = array_reverse(Product::find()->joinWith('variants')->where([Product::tableName() .'.product_id' => $last_products])->andWhere(['!=', ProductVariant::tableName() .'.stock', 0])->all()); | ||
| 73 | } | 75 | } |
| 74 | return $last_products; | 76 | return $last_products; |
| 75 | } | 77 | } |
| @@ -86,6 +88,6 @@ class ProductHelper extends Object { | @@ -86,6 +88,6 @@ class ProductHelper extends Object { | ||
| 86 | $data = ['akciya' => true]; | 88 | $data = ['akciya' => true]; |
| 87 | break; | 89 | break; |
| 88 | } | 90 | } |
| 89 | - return Product::find()->where($data)->limit($count)/*->orderBy($sort)*/->all(); | 91 | + return Product::find()->joinWith('variants')->where($data)->andWhere(['!=', ProductVariant::tableName() .'.stock', 0])->limit($count)/*->orderBy($sort)*/->all(); |
| 90 | } | 92 | } |
| 91 | } | 93 | } |
| 92 | \ No newline at end of file | 94 | \ No newline at end of file |
common/modules/product/models/Category.php
| @@ -134,8 +134,11 @@ class Category extends \yii\db\ActiveRecord | @@ -134,8 +134,11 @@ class Category extends \yii\db\ActiveRecord | ||
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | public function getProducts() { | 136 | public function getProducts() { |
| 137 | -// return $this->hasMany(Product::className(), ['product_id' => 'product_id'])->viaTable('product_category', ['category_id' => 'category_id']); | ||
| 138 | - return $this->getRelations('product_categories'); | 137 | + return $this->hasMany(Product::className(), ['product_id' => 'product_id']) |
| 138 | + ->viaTable('product_category', ['category_id' => 'category_id']) | ||
| 139 | + ->with(['variants']) | ||
| 140 | + ->andOnCondition(['!=', ProductVariant::tableName() .'.stock', 0]); | ||
| 141 | +// return $this->getRelations('product_categories'); | ||
| 139 | } | 142 | } |
| 140 | 143 | ||
| 141 | /** | 144 | /** |
common/modules/product/models/Product.php
| @@ -144,14 +144,24 @@ class Product extends \yii\db\ActiveRecord | @@ -144,14 +144,24 @@ class Product extends \yii\db\ActiveRecord | ||
| 144 | */ | 144 | */ |
| 145 | public function getVariant() | 145 | public function getVariant() |
| 146 | { | 146 | { |
| 147 | -// return ProductVariant::find()->filterWhere([ProductVariant::tableName() .'.product_id' => Product::tableName() .'.product_id'])->where('>', ProductVariant::tableName() .'.stock', 0); | ||
| 148 | return $this->hasOne(ProductVariant::className(), ['product_id' => 'product_id']); | 147 | return $this->hasOne(ProductVariant::className(), ['product_id' => 'product_id']); |
| 149 | } | 148 | } |
| 150 | 149 | ||
| 150 | + /** | ||
| 151 | + * @return \yii\db\ActiveQuery | ||
| 152 | + */ | ||
| 153 | + public function getEnabledVariant() | ||
| 154 | + { | ||
| 155 | + return $this->hasOne(ProductVariant::className(), ['product_id' => 'product_id'])->andOnCondition(['!=', ProductVariant::tableName() .'.stock', 0]); | ||
| 156 | + } | ||
| 151 | public function getVariantPrice() { | 157 | public function getVariantPrice() { |
| 152 | return $this->variant->price; | 158 | return $this->variant->price; |
| 153 | } | 159 | } |
| 154 | 160 | ||
| 161 | + public function getEnabledVariantPrice() { | ||
| 162 | + return $this->enabledVariant->price; | ||
| 163 | + } | ||
| 164 | + | ||
| 155 | /** | 165 | /** |
| 156 | * @return \yii\db\ActiveQuery | 166 | * @return \yii\db\ActiveQuery |
| 157 | */ | 167 | */ |
| @@ -162,14 +172,7 @@ class Product extends \yii\db\ActiveRecord | @@ -162,14 +172,7 @@ class Product extends \yii\db\ActiveRecord | ||
| 162 | 172 | ||
| 163 | public function getEnabledVariants() | 173 | public function getEnabledVariants() |
| 164 | { | 174 | { |
| 165 | - /*$result = []; | ||
| 166 | - foreach ($this->variants as $variant) { | ||
| 167 | - if (is_null($variant->stock) || $variant->stock > 0) { | ||
| 168 | - $result[] = $variant; | ||
| 169 | - } | ||
| 170 | - } | ||
| 171 | - return $result;*/ | ||
| 172 | - return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id'])->where(['!=', ProductVariant::tableName() .'.stock', 0]); | 175 | + return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id'])->andOnCondition(['!=', ProductVariant::tableName() .'.stock', 0]); |
| 173 | } | 176 | } |
| 174 | 177 | ||
| 175 | public function setVariants($variants) { | 178 | public function setVariants($variants) { |
console/controllers/ImportController.php
| @@ -416,7 +416,7 @@ class ImportController extends Controller { | @@ -416,7 +416,7 @@ class ImportController extends Controller { | ||
| 416 | 416 | ||
| 417 | while (($data = fgetcsv ($handle, 10000, ";")) !== FALSE) { | 417 | while (($data = fgetcsv ($handle, 10000, ";")) !== FALSE) { |
| 418 | $j++; | 418 | $j++; |
| 419 | -// if ($j > 10) { | 419 | +// if ($j > 1) { |
| 420 | // return TRUE; | 420 | // return TRUE; |
| 421 | // } | 421 | // } |
| 422 | 422 | ||
| @@ -429,14 +429,20 @@ class ImportController extends Controller { | @@ -429,14 +429,20 @@ class ImportController extends Controller { | ||
| 429 | 429 | ||
| 430 | // данные строк | 430 | // данные строк |
| 431 | $modification_code = @$data[0]; | 431 | $modification_code = @$data[0]; |
| 432 | - $price = floatval(@$data[1]); | ||
| 433 | - $price_promo = floatval(@$data[2]); | 432 | + $_price = floatval(@$data[1]); |
| 433 | + $_price_promo = floatval(@$data[2]); | ||
| 434 | $count = intval(@$data[3]); | 434 | $count = intval(@$data[3]); |
| 435 | $city_name = @$data[4]; | 435 | $city_name = @$data[4]; |
| 436 | $product_title = @$data[5]; | 436 | $product_title = @$data[5]; |
| 437 | 437 | ||
| 438 | + // @todo refactory this code | ||
| 439 | + $price = $_price_promo > 0 ? $_price_promo : $_price; | ||
| 440 | + $price_promo = $_price_promo > 0 ? $_price : $_price_promo; | ||
| 441 | + | ||
| 442 | + $modification_code = trim($modification_code); | ||
| 443 | + | ||
| 438 | if (empty ($modification_code)) { | 444 | if (empty ($modification_code)) { |
| 439 | - CONTINUE; | 445 | + continue; |
| 440 | } | 446 | } |
| 441 | // товары в пути | 447 | // товары в пути |
| 442 | if (empty ($city_name)) | 448 | if (empty ($city_name)) |
| @@ -446,28 +452,28 @@ class ImportController extends Controller { | @@ -446,28 +452,28 @@ class ImportController extends Controller { | ||
| 446 | Yii::getAlias('@uploadFilePricesAway') | 452 | Yii::getAlias('@uploadFilePricesAway') |
| 447 | ); | 453 | ); |
| 448 | 454 | ||
| 449 | -// $this->stdout("Товар $product_title в пути\n"); | 455 | + $this->stdout("~ Товар $product_title в пути\n"); |
| 450 | 456 | ||
| 451 | - CONTINUE; | 457 | + continue; |
| 452 | } | 458 | } |
| 453 | 459 | ||
| 454 | - if ( ($productVariant = ProductVariant::find()->filterWhere(['ilike', 'sku', trim($modification_code)])->one()) === null ) { | 460 | + if ( ($productVariant = ProductVariant::find()->filterWhere(['sku' => $modification_code])->one()) === null ) { |
| 455 | // 'Нет даной модификации в базе'; | 461 | // 'Нет даной модификации в базе'; |
| 456 | $this->saveNotFoundRecord ( | 462 | $this->saveNotFoundRecord ( |
| 457 | [$modification_code, $product_title], | 463 | [$modification_code, $product_title], |
| 458 | Yii::getAlias('@uploadFilePricesNoVariant') | 464 | Yii::getAlias('@uploadFilePricesNoVariant') |
| 459 | ); | 465 | ); |
| 460 | 466 | ||
| 461 | -// $this->stdout("Для товара $product_title (#$modification_code) не найдено соотвествия\n"); | 467 | + $this->stdout("- Для товара $product_title (#$modification_code) не найдено соотвествия\n"); |
| 462 | 468 | ||
| 463 | - CONTINUE; | 469 | + continue; |
| 464 | } | 470 | } |
| 465 | 471 | ||
| 466 | $quantity = 0; | 472 | $quantity = 0; |
| 467 | 473 | ||
| 468 | // ===== Set stock ==== | 474 | // ===== Set stock ==== |
| 469 | if ( $city_name ) { | 475 | if ( $city_name ) { |
| 470 | - if ( ($stock = Stock::find()->filterWhere(['ilike', 'name', trim($city_name)])->one()) === null ) { | 476 | + if ( ($stock = Stock::find()->filterWhere(['name' => trim($city_name)])->one()) === null ) { |
| 471 | // Create stock | 477 | // Create stock |
| 472 | $stock = new Stock(); | 478 | $stock = new Stock(); |
| 473 | $stock->name = trim($city_name); | 479 | $stock->name = trim($city_name); |
| @@ -484,7 +490,7 @@ class ImportController extends Controller { | @@ -484,7 +490,7 @@ class ImportController extends Controller { | ||
| 484 | 490 | ||
| 485 | $productVariant->save(); | 491 | $productVariant->save(); |
| 486 | 492 | ||
| 487 | -// $this->stdout("Товар $product_title успешно сохранен\n"); | 493 | + $this->stdout("+ Товар $product_title успешно сохранен\n"); |
| 488 | } | 494 | } |
| 489 | fclose ($handle); | 495 | fclose ($handle); |
| 490 | 496 |
frontend/controllers/CatalogController.php
| @@ -108,20 +108,6 @@ class CatalogController extends \yii\web\Controller | @@ -108,20 +108,6 @@ class CatalogController extends \yii\web\Controller | ||
| 108 | 108 | ||
| 109 | if ( !empty($filter['options']) ) { | 109 | if ( !empty($filter['options']) ) { |
| 110 | $params['options'] = $filter['options']; | 110 | $params['options'] = $filter['options']; |
| 111 | - /*$optionQuery = TaxOption::find(); | ||
| 112 | - $optionQuery->select('tax_option_id'); | ||
| 113 | - $optionQuery->innerJoinWith('group'); | ||
| 114 | - foreach ($filter['options'] as $option_key => $option_values) { | ||
| 115 | - $optionQuery->orWhere([ | ||
| 116 | - 'tax_group_id' => $option_key, | ||
| 117 | - 'alias' => $filter['options'] | ||
| 118 | - ]); | ||
| 119 | - } | ||
| 120 | - $options = ->where(['in', 'alias', $filter['options']])->all(); | ||
| 121 | - $params['options'] = []; | ||
| 122 | - foreach ($options as $option) { | ||
| 123 | - $params['options'][] = $option->tax_option_id; | ||
| 124 | - }*/ | ||
| 125 | } | 111 | } |
| 126 | 112 | ||
| 127 | if ( !empty($filter['prices']) ) { | 113 | if ( !empty($filter['prices']) ) { |
frontend/models/ProductFrontendSearch.php
| @@ -54,14 +54,10 @@ class ProductFrontendSearch extends Product { | @@ -54,14 +54,10 @@ class ProductFrontendSearch extends Product { | ||
| 54 | } else { | 54 | } else { |
| 55 | $query = Product::find(); | 55 | $query = Product::find(); |
| 56 | } | 56 | } |
| 57 | - $query->joinWith(['variant', 'brand', 'brand.brandName', 'category', 'category.categoryName']); | 57 | + $query->joinWith(['variant', 'image', 'brand', 'brand.brandName', 'category', 'category.categoryName']); |
| 58 | 58 | ||
| 59 | $query->groupBy('product.product_id'); | 59 | $query->groupBy('product.product_id'); |
| 60 | 60 | ||
| 61 | -// if (empty($_GET['sort']) || ($_GET['sort'] != 'price' && $_GET['sort'] != '-price')) { | ||
| 62 | -// $query->groupBy('product.product_id'); | ||
| 63 | -// } | ||
| 64 | - | ||
| 65 | $dataProvider = new ActiveDataProvider([ | 61 | $dataProvider = new ActiveDataProvider([ |
| 66 | 'query' => $query, | 62 | 'query' => $query, |
| 67 | 'pagination' => [ | 63 | 'pagination' => [ |
frontend/views/catalog/product.php
| @@ -13,7 +13,7 @@ $this->title = $product->fullname; | @@ -13,7 +13,7 @@ $this->title = $product->fullname; | ||
| 13 | //} | 13 | //} |
| 14 | $this->params['breadcrumbs'][] = ['label' => 'Каталог', 'url' => ['catalog/category']]; | 14 | $this->params['breadcrumbs'][] = ['label' => 'Каталог', 'url' => ['catalog/category']]; |
| 15 | $this->params['breadcrumbs'][] = ['label' => $product->category->categoryName->value, 'url' => ['catalog/category', 'category' => $product->category]]; | 15 | $this->params['breadcrumbs'][] = ['label' => $product->category->categoryName->value, 'url' => ['catalog/category', 'category' => $product->category]]; |
| 16 | -$this->params['breadcrumbs'][] = $product->fullname .' #'. $product->variant->sku; | 16 | +$this->params['breadcrumbs'][] = $product->fullname .' #'. $product->enabledVariant->sku; |
| 17 | 17 | ||
| 18 | $this->registerJs (' | 18 | $this->registerJs (' |
| 19 | 19 | ||
| @@ -96,8 +96,7 @@ $this->registerJs (" | @@ -96,8 +96,7 @@ $this->registerJs (" | ||
| 96 | <h1><?= $product->fullname ?></h1> | 96 | <h1><?= $product->fullname ?></h1> |
| 97 | <div class="begin">Цветовые решения</div> | 97 | <div class="begin">Цветовые решения</div> |
| 98 | <ul class="product_mod"> | 98 | <ul class="product_mod"> |
| 99 | - <?php foreach ($product->variants as $variant): ?> | ||
| 100 | - <?php if ($variant->quantity == 0) continue;?> | 99 | + <?php foreach ($product->enabledVariants as $variant): ?> |
| 101 | <li> | 100 | <li> |
| 102 | <a id='m<?= $variant->product_variant_id ?>' href="#<?=$variant->product_variant_id ?>" | 101 | <a id='m<?= $variant->product_variant_id ?>' href="#<?=$variant->product_variant_id ?>" |
| 103 | data-cost="<?= $variant->price ?>" | 102 | data-cost="<?= $variant->price ?>" |
| @@ -166,7 +165,7 @@ $this->registerJs (" | @@ -166,7 +165,7 @@ $this->registerJs (" | ||
| 166 | <div class="content"> | 165 | <div class="content"> |
| 167 | <div class="pic"> | 166 | <div class="pic"> |
| 168 | <center> | 167 | <center> |
| 169 | - <a href="#" rel="shadowbox[gal]" id="picoriginal"><?= \common\components\artboximage\ArtboxImageHelper::getImage($product->variant->imageUrl, 'product_view',['id'=>'pic'])?></a> | 168 | + <a href="#" rel="shadowbox[gal]" id="picoriginal"><?= \common\components\artboximage\ArtboxImageHelper::getImage($product->enabledVariant->imageUrl, 'product_view',['id'=>'pic'])?></a> |
| 170 | </center> | 169 | </center> |
| 171 | </div> | 170 | </div> |
| 172 | <ul class="product_colors"> | 171 | <ul class="product_colors"> |
frontend/views/catalog/product_item.php
| @@ -5,8 +5,8 @@ use yii\helpers\Url; | @@ -5,8 +5,8 @@ use yii\helpers\Url; | ||
| 5 | <li class="item"> | 5 | <li class="item"> |
| 6 | <div class="boxitem"> | 6 | <div class="boxitem"> |
| 7 | <div class="pixbox"> | 7 | <div class="pixbox"> |
| 8 | - <a href="<?= Url::to(['catalog/product', 'product' => $product,'#' => 'm' .$product->variant->product_variant_id]) ?>"> | ||
| 9 | - <?= \common\components\artboximage\ArtboxImageHelper::getImage($product->variant->imageUrl, 'list')?> | 8 | + <a href="<?= Url::to(['catalog/product', 'product' => $product,'#' => 'm' .$product->enabledVariant->product_variant_id]) ?>"> |
| 9 | + <?= \common\components\artboximage\ArtboxImageHelper::getImage($product->enabledVariant->imageUrl, 'list')?> | ||
| 10 | </a> | 10 | </a> |
| 11 | </div> | 11 | </div> |
| 12 | <?php if(!empty($product->is_top) || !empty($product->is_new) || !empty($product->akciya)) :?> | 12 | <?php if(!empty($product->is_top) || !empty($product->is_new) || !empty($product->akciya)) :?> |
| @@ -25,7 +25,7 @@ use yii\helpers\Url; | @@ -25,7 +25,7 @@ use yii\helpers\Url; | ||
| 25 | <a href="<?= Url::to([ | 25 | <a href="<?= Url::to([ |
| 26 | 'catalog/product', | 26 | 'catalog/product', |
| 27 | 'product' => $product, | 27 | 'product' => $product, |
| 28 | - '#' => 'm' .$product->variant->product_variant_id]) | 28 | + '#' => 'm' .$product->enabledVariant->product_variant_id]) |
| 29 | ?>" | 29 | ?>" |
| 30 | class="name"><?= $product->fullname ?> | 30 | class="name"><?= $product->fullname ?> |
| 31 | </a> | 31 | </a> |
| @@ -35,12 +35,12 @@ use yii\helpers\Url; | @@ -35,12 +35,12 @@ use yii\helpers\Url; | ||
| 35 | echo '<div class="cost-block">'; | 35 | echo '<div class="cost-block">'; |
| 36 | echo '<p class="cost">'; | 36 | echo '<p class="cost">'; |
| 37 | // есть скидка | 37 | // есть скидка |
| 38 | - if ($product->variant->price_old != 0 && $product->variant->price_old != $product->variant->price) | 38 | + if ($product->enabledVariant->price_old != 0 && $product->enabledVariant->price_old != $product->enabledVariant->price) |
| 39 | { | 39 | { |
| 40 | - echo '<strike><span id=\'old_cost\'>'.$product->variant->price_old.'</span> грн.</strike> '; | 40 | + echo '<strike><span id=\'old_cost\'>'.$product->enabledVariant->price_old.'</span> грн.</strike> '; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | - echo $product->variant->price.' <span>грн.</span></p>'; | 43 | + echo $product->enabledVariant->price.' <span>грн.</span></p>'; |
| 44 | 44 | ||
| 45 | echo '</div>'; | 45 | echo '</div>'; |
| 46 | 46 | ||
| @@ -49,13 +49,12 @@ use yii\helpers\Url; | @@ -49,13 +49,12 @@ use yii\helpers\Url; | ||
| 49 | <a href="<?= Url::to([ | 49 | <a href="<?= Url::to([ |
| 50 | 'catalog/product', | 50 | 'catalog/product', |
| 51 | 'product' => $product, | 51 | 'product' => $product, |
| 52 | - '#' => 'm' .$product->variant->product_variant_id]) | 52 | + '#' => 'm' .$product->enabledVariant->product_variant_id]) |
| 53 | ?>" class="link_buy">Купить</a> | 53 | ?>" class="link_buy">Купить</a> |
| 54 | 54 | ||
| 55 | <div class="mycarousel"> | 55 | <div class="mycarousel"> |
| 56 | <ul class="jcarousel jcarousel-skin-tango"> | 56 | <ul class="jcarousel jcarousel-skin-tango"> |
| 57 | <?php foreach ($product->enabledVariants as $variant) : ?> | 57 | <?php foreach ($product->enabledVariants as $variant) : ?> |
| 58 | - <?php if ($variant->quantity == 0) continue;?> | ||
| 59 | <?php if (!empty($variant->image)) :?> | 58 | <?php if (!empty($variant->image)) :?> |
| 60 | <li> | 59 | <li> |
| 61 | <a href="<?= Url::to([ | 60 | <a href="<?= Url::to([ |
frontend/views/site/index.php
| @@ -30,7 +30,7 @@ echo '<div class="home_banner_up">'; | @@ -30,7 +30,7 @@ echo '<div class="home_banner_up">'; | ||
| 30 | echo '</div>' | 30 | echo '</div>' |
| 31 | ?> | 31 | ?> |
| 32 | 32 | ||
| 33 | -<?= \frontend\widgets\Rubrics::widget(['wrapper' => 'rubrics', 'includes' => [136,137,138,139,140]])?> | 33 | +<?= \frontend\widgets\Rubrics::widget(['wrapper' => 'rubrics', 'includes' => [130,131,132,133,134]])?> |
| 34 | 34 | ||
| 35 | <?= \common\modules\product\widgets\specialProducts::widget(['type' => 'promo'])?> | 35 | <?= \common\modules\product\widgets\specialProducts::widget(['type' => 'promo'])?> |
| 36 | <?= \common\modules\product\widgets\specialProducts::widget(['type' => 'new'])?> | 36 | <?= \common\modules\product\widgets\specialProducts::widget(['type' => 'new'])?> |