Commit 0f852b5118a92f18e22cedfbd4a93310ef1763f6

Authored by Administrator
1 parent 103e8126

29.06.16

common/modules/product/CatalogUrlManager.php
@@ -47,9 +47,7 @@ class CatalogUrlManager implements UrlRuleInterface { @@ -47,9 +47,7 @@ class CatalogUrlManager implements UrlRuleInterface {
47 // Filter 47 // Filter
48 if (strpos($paths[2], 'filter:') === 0) { 48 if (strpos($paths[2], 'filter:') === 0) {
49 $this->parseFilter($paths[2], $params); 49 $this->parseFilter($paths[2], $params);
50 - }/* elseif (strpos($paths[2], 'word:') === 0) {  
51 - $params['word'] = substr($paths[2], 5);  
52 - }*/ 50 + }
53 else { 51 else {
54 throw new HttpException(404 ,'Page not found'); 52 throw new HttpException(404 ,'Page not found');
55 } 53 }
@@ -106,15 +104,6 @@ class CatalogUrlManager implements UrlRuleInterface { @@ -106,15 +104,6 @@ class CatalogUrlManager implements UrlRuleInterface {
106 } else { 104 } else {
107 $url = 'catalog/'; 105 $url = 'catalog/';
108 } 106 }
109 - /*if (!empty($params['word'])) {  
110 - if (!is_array($params['word'])) {  
111 - $params['word'] = [$params['word']];  
112 - }  
113 - $url .= 'word:'. implode(';', $params['word']);  
114 - }  
115 - if (isset($params['word'])) {  
116 - unset($params['word']);  
117 - }*/  
118 107
119 $this->setFilterUrl($params, $url); 108 $this->setFilterUrl($params, $url);
120 109
common/modules/product/controllers/VariantController.php
@@ -157,11 +157,14 @@ class VariantController extends Controller @@ -157,11 +157,14 @@ class VariantController extends Controller
157 $stock->name = $ProductStock['name']; 157 $stock->name = $ProductStock['name'];
158 $stock->save(); 158 $stock->save();
159 } 159 }
  160 +
160 $psModel = ProductStock::find()->where(['product_variant_id'=>$model->product_variant_id, 'stock_id' =>$stock->stock_id ]); 161 $psModel = ProductStock::find()->where(['product_variant_id'=>$model->product_variant_id, 'stock_id' =>$stock->stock_id ]);
161 if(!$psModel instanceof ProductStock){ 162 if(!$psModel instanceof ProductStock){
162 $psModel = new ProductStock; 163 $psModel = new ProductStock;
163 $psModel->load(['ProductStock'=>$ProductStock]); 164 $psModel->load(['ProductStock'=>$ProductStock]);
164 $psModel->stock_id = $stock->stock_id; 165 $psModel->stock_id = $stock->stock_id;
  166 + $psModel->product_variant_id = $model->product_variant_id;
  167 + $psModel->product_id = $model->product->product_id;
165 $psModel->save(); 168 $psModel->save();
166 } else { 169 } else {
167 $psModel->load(['ProductStock'=>$ProductStock]); 170 $psModel->load(['ProductStock'=>$ProductStock]);
@@ -171,26 +174,13 @@ class VariantController extends Controller @@ -171,26 +174,13 @@ class VariantController extends Controller
171 } 174 }
172 175
173 176
  177 +
174 } 178 }
175 return $this->redirect(['index', 'product_id'=>$product_id]); 179 return $this->redirect(['index', 'product_id'=>$product_id]);
176 180
177 181
178 182
179 183
180 -// $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload');  
181 -// if ($model->save()) {  
182 -// if ( ($images = $model->imagesUpload()) !== FALSE) {  
183 -// foreach ($images as $image) {  
184 -// $imageModel = new ProductImage();  
185 -// $imageModel->product_id = $model->product_id;  
186 -// $imageModel->product_variant_id = $model->product_variant_id;  
187 -// $imageModel->image = $image;  
188 -// $imageModel->save();  
189 -// }  
190 -// }  
191 -//  
192 -// return $this->redirect(['index', 'product_id' => $product_id]);  
193 -// }  
194 } else { 184 } else {
195 $groups = $model->category-> getTaxGroupsByLevel(1); 185 $groups = $model->category-> getTaxGroupsByLevel(1);
196 186
common/modules/product/models/ProductVariant.php
@@ -259,19 +259,19 @@ class ProductVariant extends \yii\db\ActiveRecord @@ -259,19 +259,19 @@ class ProductVariant extends \yii\db\ActiveRecord
259 return $this->hasOne(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']); 259 return $this->hasOne(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']);
260 } 260 }
261 261
262 - public function afterSave($insert, $changedAttributes)  
263 - {  
264 - if (!is_null($this->stocks)) {  
265 - //ProductStock::deleteAll(['product_variant_id' => $this->product_variant_id]);  
266 - $values = [];  
267 - foreach ($this->stocks as $id => $quantity) {  
268 - $productStock = ProductStock::find()->where(['product_variant_id' => $this->product_variant_id, 'stock_id' => $id])->one();  
269 - $productStock->quantity = $quantity;  
270 - $productStock->save();  
271 - }  
272 - }  
273 - parent::afterSave($insert, $changedAttributes);  
274 - } 262 +// public function afterSave($insert, $changedAttributes)
  263 +// {
  264 +// if (!is_null($this->stocks)) {
  265 +// //ProductStock::deleteAll(['product_variant_id' => $this->product_variant_id]);
  266 +// $values = [];
  267 +// foreach ($this->stocks as $id => $quantity) {
  268 +// $productStock = ProductStock::find()->where(['product_variant_id' => $this->product_variant_id, 'stock_id' => $id])->one();
  269 +// $productStock->quantity = $quantity;
  270 +// $productStock->save();
  271 +// }
  272 +// }
  273 +// parent::afterSave($insert, $changedAttributes);
  274 +// }
275 275
276 public function beforeDelete() { 276 public function beforeDelete() {
277 ProductImage::deleteAll(['product_variant_id' => $this->product_variant_id]); 277 ProductImage::deleteAll(['product_variant_id' => $this->product_variant_id]);
common/translation/ru/product.php
@@ -24,8 +24,8 @@ return [ @@ -24,8 +24,8 @@ return [
24 'Price Old' => 'Старая Цена', 24 'Price Old' => 'Старая Цена',
25 'Products' => 'Товары', 25 'Products' => 'Товары',
26 'Product' => 'Товар', 26 'Product' => 'Товар',
27 - 'Variants' => 'Модифицкации',  
28 - 'Variant' => 'Модифицкация', 27 + 'Variants' => 'Модификации',
  28 + 'Variant' => 'Модификация',
29 'Create Product' => 'Создать Товар', 29 'Create Product' => 'Создать Товар',
30 'Enable' => 'Доступно', 30 'Enable' => 'Доступно',
31 'Disable' => 'Отсутсвует', 31 'Disable' => 'Отсутсвует',
frontend/config/main.php
@@ -83,6 +83,7 @@ return [ @@ -83,6 +83,7 @@ return [
83 'priceparam.xml' => 'site/priceparam', 83 'priceparam.xml' => 'site/priceparam',
84 'price.xml' => 'site/price', 84 'price.xml' => 'site/price',
85 'smstest' => 'site/sms', 85 'smstest' => 'site/sms',
  86 + 'search' => 'search/index',
86 // 'catalog' => 'catalog/all', 87 // 'catalog' => 'catalog/all',
87 // 'catalog/<translit:\w+>' => 'catalog/index', 88 // 'catalog/<translit:\w+>' => 'catalog/index',
88 // 'products/search' => 'products/search', 89 // 'products/search' => 'products/search',
frontend/controllers/CatalogController.php
@@ -36,7 +36,6 @@ class CatalogController extends \yii\web\Controller @@ -36,7 +36,6 @@ class CatalogController extends \yii\web\Controller
36 /** @var Category $category */ 36 /** @var Category $category */
37 $category = Yii::$app->request->get('category'); 37 $category = Yii::$app->request->get('category');
38 $filter = Yii::$app->request->get('filter', []); 38 $filter = Yii::$app->request->get('filter', []);
39 - $word = trim(Yii::$app->request->get('word', ''));  
40 39
41 if (empty($category->category_id) && empty($word)) { 40 if (empty($category->category_id) && empty($word)) {
42 return $this->render( 41 return $this->render(
@@ -44,116 +43,78 @@ class CatalogController extends \yii\web\Controller @@ -44,116 +43,78 @@ class CatalogController extends \yii\web\Controller
44 ); 43 );
45 } 44 }
46 45
47 - if (!empty($word))  
48 - {  
49 - $params = [];  
50 46
51 - $params['keywords'] = explode(' ', preg_replace("|[\s,.!:&?~();-]|i", " ", $word));  
52 - foreach($params['keywords'] as $i => &$keyword) {  
53 - $keyword = trim($keyword);  
54 - if (empty($keyword)) {  
55 - unset($params['keywords'][$i]);  
56 - }  
57 - }  
58 -  
59 - $productModel = new ProductFrontendSearch();  
60 - $productProvider = $productModel->search($category, $params); 47 + $params = [];
61 48
62 - $categoriesQuery = Category::find()  
63 - ->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() .'.category_id = '. Category::tableName() .'.category_id')  
64 - ->innerJoin(Product::tableName(), Product::tableName() .'.product_id = '. ProductCategory::tableName() .'.product_id')  
65 - ->innerJoin(ProductVariant::tableName(), ProductVariant::tableName() .'.product_id = '. ProductCategory::tableName() .'.product_id');  
66 - foreach ($params['keywords'] as $keyword) {  
67 - $categoriesQuery->andWhere(['ilike', 'product.name', $keyword]); 49 + if ( !empty($filter['brands']) ) {
  50 + $brands = Brand::find()->select('brand_id')->where(['in', 'alias', $filter['brands']])->all();
  51 + $params['brands'] = [];
  52 + foreach ($brands as $brand) {
  53 + $params['brands'][] = $brand->brand_id;
68 } 54 }
69 - $categoriesQuery->andWhere(['!=', ProductVariant::tableName() .'.stock', 0]);  
70 - $categories = $categoriesQuery->all();  
71 -  
72 - return $this->render(  
73 - 'search',  
74 - [  
75 - 'keywords' => $params['keywords'],  
76 - 'category' => $category,  
77 - 'productModel' => $productModel,  
78 - 'productProvider' => $productProvider,  
79 - 'categories' => $categories,  
80 - ]  
81 - );  
82 -  
83 } 55 }
84 - else  
85 - {  
86 - $params = [];  
87 -  
88 - if ( !empty($filter['brands']) ) {  
89 - $brands = Brand::find()->select('brand_id')->where(['in', 'alias', $filter['brands']])->all();  
90 - $params['brands'] = [];  
91 - foreach ($brands as $brand) {  
92 - $params['brands'][] = $brand->brand_id;  
93 - }  
94 - }  
95 -  
96 - if ( !empty($filter['special']) ) {  
97 - if (!is_array($filter['special'])) {  
98 - $filter['special'] = [$filter['special']];  
99 - }  
100 - if (in_array('new', $filter['special'])) {  
101 - $params['special']['is_new'] = true;  
102 - }  
103 - if (in_array('top', $filter['special'])) {  
104 - $params['special']['is_top'] = true;  
105 - }  
106 - if (in_array('promo', $filter['special'])) {  
107 - $params['special']['akciya'] = true;  
108 - }  
109 - }  
110 56
111 - if ( !empty($filter['options']) ) {  
112 - $params['options'] = $filter['options']; 57 + if ( !empty($filter['special']) ) {
  58 + if (!is_array($filter['special'])) {
  59 + $filter['special'] = [$filter['special']];
113 } 60 }
114 -  
115 - if ( !empty($filter['prices']) ) {  
116 - $params['prices'] = $filter['prices']; 61 + if (in_array('new', $filter['special'])) {
  62 + $params['special']['is_new'] = true;
117 } 63 }
118 -  
119 - $productModel = new ProductFrontendSearch();  
120 - $productQuery = $productModel->getSearchQuery($category, $params);  
121 - $productProvider = $productModel->search($category, $params);  
122 -  
123 - $brandModel = new BrandSearch();  
124 - $brands = $brandModel->getBrands($category, $params)->all();  
125 -  
126 - $optionsQuery = $productModel->optionsForCategory($category, $params);  
127 - $groups = [];  
128 - foreach ($optionsQuery->all() as $option) {  
129 - if (!isset($groups[$option->tax_group_id])) {  
130 - $groups[$option->tax_group_id] = $option->taxGroup;  
131 - $groups[$option->tax_group_id]->_options = [];  
132 - }  
133 - $groups[$option->tax_group_id]->_options[] = $option; 64 + if (in_array('top', $filter['special'])) {
  65 + $params['special']['is_top'] = true;
134 } 66 }
135 - foreach($groups as $i => $group) {  
136 - if (empty($group->_options))  
137 - unset($groups[$i]); 67 + if (in_array('promo', $filter['special'])) {
  68 + $params['special']['akciya'] = true;
138 } 69 }
  70 + }
139 71
140 - $priceLimits = $productModel->priceLimits($category, $params); 72 + if ( !empty($filter['options']) ) {
  73 + $params['options'] = $filter['options'];
  74 + }
141 75
142 - return $this->render(  
143 - 'products',  
144 - [  
145 - 'category' => $category,  
146 - 'brandModel' => $brandModel,  
147 - 'brands' => $brands,  
148 - 'filter' => $filter,  
149 - 'params' => $params,  
150 - 'productModel' => $productModel,  
151 - 'productProvider' => $productProvider,  
152 - 'groups' => $groups,  
153 - 'priceLimits' => $priceLimits,  
154 - ]  
155 - ); 76 + if ( !empty($filter['prices']) ) {
  77 + $params['prices'] = $filter['prices'];
156 } 78 }
  79 +
  80 + $productModel = new ProductFrontendSearch();
  81 + $productQuery = $productModel->getSearchQuery($category, $params);
  82 + $productProvider = $productModel->search($category, $params);
  83 +
  84 + $brandModel = new BrandSearch();
  85 + $brands = $brandModel->getBrands($category, $params)->all();
  86 +
  87 + $optionsQuery = $productModel->optionsForCategory($category, $params);
  88 + $groups = [];
  89 + foreach ($optionsQuery->all() as $option) {
  90 + if (!isset($groups[$option->tax_group_id])) {
  91 + $groups[$option->tax_group_id] = $option->taxGroup;
  92 + $groups[$option->tax_group_id]->_options = [];
  93 + }
  94 + $groups[$option->tax_group_id]->_options[] = $option;
  95 + }
  96 + foreach($groups as $i => $group) {
  97 + if (empty($group->_options))
  98 + unset($groups[$i]);
  99 + }
  100 +
  101 + $priceLimits = $productModel->priceLimits($category, $params);
  102 +
  103 + return $this->render(
  104 + 'products',
  105 + [
  106 + 'category' => $category,
  107 + 'brandModel' => $brandModel,
  108 + 'brands' => $brands,
  109 + 'filter' => $filter,
  110 + 'params' => $params,
  111 + 'productModel' => $productModel,
  112 + 'productProvider' => $productProvider,
  113 + 'groups' => $groups,
  114 + 'priceLimits' => $priceLimits,
  115 + ]
  116 + );
  117 +
157 } 118 }
158 119
159 public function actionProduct() 120 public function actionProduct()
frontend/controllers/SearchController.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace frontend\controllers;
  4 +use frontend\models\ProductFrontendSearch;
  5 +use Yii;
  6 +use common\modules\product\models\Category;
  7 +use common\modules\product\models\Product;
  8 +use common\modules\product\models\ProductCategory;
  9 +use common\modules\product\models\ProductVariant;
  10 +use yii\web\HttpException;
  11 +
  12 +class SearchController extends \yii\web\Controller
  13 +{
  14 + public function actionIndex()
  15 + {
  16 +
  17 + $word = trim(Yii::$app->request->get('word', ''));
  18 +
  19 + if (!empty($word))
  20 + {
  21 + $params = [];
  22 +
  23 + $params['keywords'] = explode(' ', preg_replace("|[\s,.!:&?~();-]|i", " ", $word));
  24 + foreach($params['keywords'] as $i => &$keyword) {
  25 + $keyword = trim($keyword);
  26 + if (empty($keyword)) {
  27 + unset($params['keywords'][$i]);
  28 + }
  29 + }
  30 +
  31 + $productModel = new ProductFrontendSearch();
  32 + $productProvider = $productModel->search(null, $params);
  33 +
  34 + $categoriesQuery = Category::find()
  35 + ->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() .'.category_id = '. Category::tableName() .'.category_id')
  36 + ->innerJoin(Product::tableName(), Product::tableName() .'.product_id = '. ProductCategory::tableName() .'.product_id')
  37 + ->innerJoin(ProductVariant::tableName(), ProductVariant::tableName() .'.product_id = '. ProductCategory::tableName() .'.product_id');
  38 + foreach ($params['keywords'] as $keyword) {
  39 + $categoriesQuery->andWhere(['ilike', 'product.name', $keyword]);
  40 + }
  41 + $categoriesQuery->andWhere(['!=', ProductVariant::tableName() .'.stock', 0]);
  42 + $categories = $categoriesQuery->all();
  43 +
  44 + return $this->render(
  45 + 'index',
  46 + [
  47 + 'keywords' => $params['keywords'],
  48 + 'productModel' => $productModel,
  49 + 'productProvider' => $productProvider,
  50 + 'categories' => $categories,
  51 + ]
  52 + );
  53 + }
  54 + else
  55 + {
  56 + throw new HttpException(404, 'Данной странице не существует!');
  57 + }
  58 + }
  59 +}
0 \ No newline at end of file 60 \ No newline at end of file
frontend/views/catalog/_catalog_box.php
@@ -15,6 +15,6 @@ use app\models\Catalog; @@ -15,6 +15,6 @@ use app\models\Catalog;
15 </ul> 15 </ul>
16 <?endif;?> 16 <?endif;?>
17 </li> 17 </li>
18 - <?endforeach;?>  
19 - </ul> 18 + <?endforeach;?>
  19 + </ul>
20 </div></div> 20 </div></div>
21 \ No newline at end of file 21 \ No newline at end of file
frontend/views/catalog/products.php
1 <?php 1 <?php
  2 +
2 /** @var $this \yii\web\View */ 3 /** @var $this \yii\web\View */
3 /** @var $productProvider \yii\data\ActiveDataProvider */ 4 /** @var $productProvider \yii\data\ActiveDataProvider */
4 5
frontend/views/layouts/main.php
@@ -157,7 +157,7 @@ $this-&gt;registerJsFile (Yii::$app-&gt;request-&gt;baseUrl . &#39;/js/fix_height.js&#39;, [&#39;posi @@ -157,7 +157,7 @@ $this-&gt;registerJsFile (Yii::$app-&gt;request-&gt;baseUrl . &#39;/js/fix_height.js&#39;, [&#39;posi
157 <div class="both"></div> 157 <div class="both"></div>
158 </div> 158 </div>
159 <div class="search"> 159 <div class="search">
160 - <form method="get" action="/catalog"> 160 + <form method="get" action="/search">
161 <input type="text" name="word" value='<?= ! empty($_GET['word']) ? Html::encode ($_GET['word']) : '' ?>'/><input 161 <input type="text" name="word" value='<?= ! empty($_GET['word']) ? Html::encode ($_GET['word']) : '' ?>'/><input
162 type="submit" value=" "/> 162 type="submit" value=" "/>
163 </form> 163 </form>
frontend/views/catalog/search.php renamed to frontend/views/search/index.php
@@ -12,18 +12,13 @@ $page_data = [ @@ -12,18 +12,13 @@ $page_data = [
12 ]; 12 ];
13 13
14 $this->params['breadcrumbs'][] = ['label' => 'Поиск', 'url' => ['catalog/category', 'word' => implode(' ', $keywords)]]; 14 $this->params['breadcrumbs'][] = ['label' => 'Поиск', 'url' => ['catalog/category', 'word' => implode(' ', $keywords)]];
15 -if (!empty($category)) {  
16 - $this->params['breadcrumbs'][] = $category->categoryName->value;  
17 - $page_data['category'] = $category->name;  
18 -}  
19 15
20 -$this->title = Yii::t('product', "Search for \"{keywords}\"". (empty($category) ? '' : ' in category \"{category}\"'), $page_data);  
21 16
22 //$this->params['seo']['seo_text'] = 'TEST SEO TEXT'; 17 //$this->params['seo']['seo_text'] = 'TEST SEO TEXT';
23 //$this->params['seo']['h1'] = 'TEST H1'; 18 //$this->params['seo']['h1'] = 'TEST H1';
24 //$this->params['seo']['description'] = 'TEST DESCRIPTION'; 19 //$this->params['seo']['description'] = 'TEST DESCRIPTION';
25 //$this->params['seo']['fields']['name'] = 'TEST NAME FROM FIELD'; 20 //$this->params['seo']['fields']['name'] = 'TEST NAME FROM FIELD';
26 -//$this->params['seo']['key']= 'product_list'; 21 +$this->params['seo']['meta']= 'noindex,follow';
27 ?> 22 ?>
28 23
29 <nav class="bread-crumbs"> 24 <nav class="bread-crumbs">
frontend/widgets/Seo.php
@@ -277,6 +277,7 @@ class Seo extends Widget @@ -277,6 +277,7 @@ class Seo extends Widget
277 $query = SeoDynamic::find()->joinWith('seoCategory')->where(['controller' => \Yii::$app->controller->id, 'action' => \Yii::$app->controller->action->id, 'key' => $this->key]); 277 $query = SeoDynamic::find()->joinWith('seoCategory')->where(['controller' => \Yii::$app->controller->id, 'action' => \Yii::$app->controller->action->id, 'key' => $this->key]);
278 } else { 278 } else {
279 279
  280 +
280 $query = SeoDynamic::find()->joinWith('seoCategory')->where(['controller' => \Yii::$app->controller->id, 'action' => \Yii::$app->controller->action->id]); 281 $query = SeoDynamic::find()->joinWith('seoCategory')->where(['controller' => \Yii::$app->controller->id, 'action' => \Yii::$app->controller->action->id]);
281 } 282 }
282 283