diff --git a/common/modules/product/CatalogUrlManager.php b/common/modules/product/CatalogUrlManager.php index 68b754f..6bbcdea 100755 --- a/common/modules/product/CatalogUrlManager.php +++ b/common/modules/product/CatalogUrlManager.php @@ -47,9 +47,7 @@ class CatalogUrlManager implements UrlRuleInterface { // Filter if (strpos($paths[2], 'filter:') === 0) { $this->parseFilter($paths[2], $params); - }/* elseif (strpos($paths[2], 'word:') === 0) { - $params['word'] = substr($paths[2], 5); - }*/ + } else { throw new HttpException(404 ,'Page not found'); } @@ -106,15 +104,6 @@ class CatalogUrlManager implements UrlRuleInterface { } else { $url = 'catalog/'; } - /*if (!empty($params['word'])) { - if (!is_array($params['word'])) { - $params['word'] = [$params['word']]; - } - $url .= 'word:'. implode(';', $params['word']); - } - if (isset($params['word'])) { - unset($params['word']); - }*/ $this->setFilterUrl($params, $url); diff --git a/common/modules/product/controllers/VariantController.php b/common/modules/product/controllers/VariantController.php index c855a83..ea44623 100755 --- a/common/modules/product/controllers/VariantController.php +++ b/common/modules/product/controllers/VariantController.php @@ -157,11 +157,14 @@ class VariantController extends Controller $stock->name = $ProductStock['name']; $stock->save(); } + $psModel = ProductStock::find()->where(['product_variant_id'=>$model->product_variant_id, 'stock_id' =>$stock->stock_id ]); if(!$psModel instanceof ProductStock){ $psModel = new ProductStock; $psModel->load(['ProductStock'=>$ProductStock]); $psModel->stock_id = $stock->stock_id; + $psModel->product_variant_id = $model->product_variant_id; + $psModel->product_id = $model->product->product_id; $psModel->save(); } else { $psModel->load(['ProductStock'=>$ProductStock]); @@ -171,26 +174,13 @@ class VariantController extends Controller } + } return $this->redirect(['index', 'product_id'=>$product_id]); -// $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); -// if ($model->save()) { -// if ( ($images = $model->imagesUpload()) !== FALSE) { -// foreach ($images as $image) { -// $imageModel = new ProductImage(); -// $imageModel->product_id = $model->product_id; -// $imageModel->product_variant_id = $model->product_variant_id; -// $imageModel->image = $image; -// $imageModel->save(); -// } -// } -// -// return $this->redirect(['index', 'product_id' => $product_id]); -// } } else { $groups = $model->category-> getTaxGroupsByLevel(1); diff --git a/common/modules/product/models/ProductVariant.php b/common/modules/product/models/ProductVariant.php index f084f64..2211d5e 100755 --- a/common/modules/product/models/ProductVariant.php +++ b/common/modules/product/models/ProductVariant.php @@ -259,19 +259,19 @@ class ProductVariant extends \yii\db\ActiveRecord return $this->hasOne(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']); } - public function afterSave($insert, $changedAttributes) - { - if (!is_null($this->stocks)) { - //ProductStock::deleteAll(['product_variant_id' => $this->product_variant_id]); - $values = []; - foreach ($this->stocks as $id => $quantity) { - $productStock = ProductStock::find()->where(['product_variant_id' => $this->product_variant_id, 'stock_id' => $id])->one(); - $productStock->quantity = $quantity; - $productStock->save(); - } - } - parent::afterSave($insert, $changedAttributes); - } +// public function afterSave($insert, $changedAttributes) +// { +// if (!is_null($this->stocks)) { +// //ProductStock::deleteAll(['product_variant_id' => $this->product_variant_id]); +// $values = []; +// foreach ($this->stocks as $id => $quantity) { +// $productStock = ProductStock::find()->where(['product_variant_id' => $this->product_variant_id, 'stock_id' => $id])->one(); +// $productStock->quantity = $quantity; +// $productStock->save(); +// } +// } +// parent::afterSave($insert, $changedAttributes); +// } public function beforeDelete() { ProductImage::deleteAll(['product_variant_id' => $this->product_variant_id]); diff --git a/common/translation/ru/product.php b/common/translation/ru/product.php index 61312a6..ca15056 100755 --- a/common/translation/ru/product.php +++ b/common/translation/ru/product.php @@ -24,8 +24,8 @@ return [ 'Price Old' => 'Старая Цена', 'Products' => 'Товары', 'Product' => 'Товар', - 'Variants' => 'Модифицкации', - 'Variant' => 'Модифицкация', + 'Variants' => 'Модификации', + 'Variant' => 'Модификация', 'Create Product' => 'Создать Товар', 'Enable' => 'Доступно', 'Disable' => 'Отсутсвует', diff --git a/frontend/config/main.php b/frontend/config/main.php index 5379da0..5f40326 100755 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -83,6 +83,7 @@ return [ 'priceparam.xml' => 'site/priceparam', 'price.xml' => 'site/price', 'smstest' => 'site/sms', + 'search' => 'search/index', // 'catalog' => 'catalog/all', // 'catalog/' => 'catalog/index', // 'products/search' => 'products/search', diff --git a/frontend/controllers/CatalogController.php b/frontend/controllers/CatalogController.php index f536f0d..1fa4c4e 100755 --- a/frontend/controllers/CatalogController.php +++ b/frontend/controllers/CatalogController.php @@ -36,7 +36,6 @@ class CatalogController extends \yii\web\Controller /** @var Category $category */ $category = Yii::$app->request->get('category'); $filter = Yii::$app->request->get('filter', []); - $word = trim(Yii::$app->request->get('word', '')); if (empty($category->category_id) && empty($word)) { return $this->render( @@ -44,116 +43,78 @@ class CatalogController extends \yii\web\Controller ); } - if (!empty($word)) - { - $params = []; - $params['keywords'] = explode(' ', preg_replace("|[\s,.!:&?~();-]|i", " ", $word)); - foreach($params['keywords'] as $i => &$keyword) { - $keyword = trim($keyword); - if (empty($keyword)) { - unset($params['keywords'][$i]); - } - } - - $productModel = new ProductFrontendSearch(); - $productProvider = $productModel->search($category, $params); + $params = []; - $categoriesQuery = Category::find() - ->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() .'.category_id = '. Category::tableName() .'.category_id') - ->innerJoin(Product::tableName(), Product::tableName() .'.product_id = '. ProductCategory::tableName() .'.product_id') - ->innerJoin(ProductVariant::tableName(), ProductVariant::tableName() .'.product_id = '. ProductCategory::tableName() .'.product_id'); - foreach ($params['keywords'] as $keyword) { - $categoriesQuery->andWhere(['ilike', 'product.name', $keyword]); + if ( !empty($filter['brands']) ) { + $brands = Brand::find()->select('brand_id')->where(['in', 'alias', $filter['brands']])->all(); + $params['brands'] = []; + foreach ($brands as $brand) { + $params['brands'][] = $brand->brand_id; } - $categoriesQuery->andWhere(['!=', ProductVariant::tableName() .'.stock', 0]); - $categories = $categoriesQuery->all(); - - return $this->render( - 'search', - [ - 'keywords' => $params['keywords'], - 'category' => $category, - 'productModel' => $productModel, - 'productProvider' => $productProvider, - 'categories' => $categories, - ] - ); - } - else - { - $params = []; - - if ( !empty($filter['brands']) ) { - $brands = Brand::find()->select('brand_id')->where(['in', 'alias', $filter['brands']])->all(); - $params['brands'] = []; - foreach ($brands as $brand) { - $params['brands'][] = $brand->brand_id; - } - } - - if ( !empty($filter['special']) ) { - if (!is_array($filter['special'])) { - $filter['special'] = [$filter['special']]; - } - if (in_array('new', $filter['special'])) { - $params['special']['is_new'] = true; - } - if (in_array('top', $filter['special'])) { - $params['special']['is_top'] = true; - } - if (in_array('promo', $filter['special'])) { - $params['special']['akciya'] = true; - } - } - if ( !empty($filter['options']) ) { - $params['options'] = $filter['options']; + if ( !empty($filter['special']) ) { + if (!is_array($filter['special'])) { + $filter['special'] = [$filter['special']]; } - - if ( !empty($filter['prices']) ) { - $params['prices'] = $filter['prices']; + if (in_array('new', $filter['special'])) { + $params['special']['is_new'] = true; } - - $productModel = new ProductFrontendSearch(); - $productQuery = $productModel->getSearchQuery($category, $params); - $productProvider = $productModel->search($category, $params); - - $brandModel = new BrandSearch(); - $brands = $brandModel->getBrands($category, $params)->all(); - - $optionsQuery = $productModel->optionsForCategory($category, $params); - $groups = []; - foreach ($optionsQuery->all() as $option) { - if (!isset($groups[$option->tax_group_id])) { - $groups[$option->tax_group_id] = $option->taxGroup; - $groups[$option->tax_group_id]->_options = []; - } - $groups[$option->tax_group_id]->_options[] = $option; + if (in_array('top', $filter['special'])) { + $params['special']['is_top'] = true; } - foreach($groups as $i => $group) { - if (empty($group->_options)) - unset($groups[$i]); + if (in_array('promo', $filter['special'])) { + $params['special']['akciya'] = true; } + } - $priceLimits = $productModel->priceLimits($category, $params); + if ( !empty($filter['options']) ) { + $params['options'] = $filter['options']; + } - return $this->render( - 'products', - [ - 'category' => $category, - 'brandModel' => $brandModel, - 'brands' => $brands, - 'filter' => $filter, - 'params' => $params, - 'productModel' => $productModel, - 'productProvider' => $productProvider, - 'groups' => $groups, - 'priceLimits' => $priceLimits, - ] - ); + if ( !empty($filter['prices']) ) { + $params['prices'] = $filter['prices']; } + + $productModel = new ProductFrontendSearch(); + $productQuery = $productModel->getSearchQuery($category, $params); + $productProvider = $productModel->search($category, $params); + + $brandModel = new BrandSearch(); + $brands = $brandModel->getBrands($category, $params)->all(); + + $optionsQuery = $productModel->optionsForCategory($category, $params); + $groups = []; + foreach ($optionsQuery->all() as $option) { + if (!isset($groups[$option->tax_group_id])) { + $groups[$option->tax_group_id] = $option->taxGroup; + $groups[$option->tax_group_id]->_options = []; + } + $groups[$option->tax_group_id]->_options[] = $option; + } + foreach($groups as $i => $group) { + if (empty($group->_options)) + unset($groups[$i]); + } + + $priceLimits = $productModel->priceLimits($category, $params); + + return $this->render( + 'products', + [ + 'category' => $category, + 'brandModel' => $brandModel, + 'brands' => $brands, + 'filter' => $filter, + 'params' => $params, + 'productModel' => $productModel, + 'productProvider' => $productProvider, + 'groups' => $groups, + 'priceLimits' => $priceLimits, + ] + ); + } public function actionProduct() diff --git a/frontend/controllers/SearchController.php b/frontend/controllers/SearchController.php new file mode 100644 index 0000000..b46fff5 --- /dev/null +++ b/frontend/controllers/SearchController.php @@ -0,0 +1,59 @@ +request->get('word', '')); + + if (!empty($word)) + { + $params = []; + + $params['keywords'] = explode(' ', preg_replace("|[\s,.!:&?~();-]|i", " ", $word)); + foreach($params['keywords'] as $i => &$keyword) { + $keyword = trim($keyword); + if (empty($keyword)) { + unset($params['keywords'][$i]); + } + } + + $productModel = new ProductFrontendSearch(); + $productProvider = $productModel->search(null, $params); + + $categoriesQuery = Category::find() + ->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() .'.category_id = '. Category::tableName() .'.category_id') + ->innerJoin(Product::tableName(), Product::tableName() .'.product_id = '. ProductCategory::tableName() .'.product_id') + ->innerJoin(ProductVariant::tableName(), ProductVariant::tableName() .'.product_id = '. ProductCategory::tableName() .'.product_id'); + foreach ($params['keywords'] as $keyword) { + $categoriesQuery->andWhere(['ilike', 'product.name', $keyword]); + } + $categoriesQuery->andWhere(['!=', ProductVariant::tableName() .'.stock', 0]); + $categories = $categoriesQuery->all(); + + return $this->render( + 'index', + [ + 'keywords' => $params['keywords'], + 'productModel' => $productModel, + 'productProvider' => $productProvider, + 'categories' => $categories, + ] + ); + } + else + { + throw new HttpException(404, 'Данной странице не существует!'); + } + } +} \ No newline at end of file diff --git a/frontend/views/catalog/_catalog_box.php b/frontend/views/catalog/_catalog_box.php index 14a47bc..fa669ce 100755 --- a/frontend/views/catalog/_catalog_box.php +++ b/frontend/views/catalog/_catalog_box.php @@ -15,6 +15,6 @@ use app\models\Catalog; - - + + \ No newline at end of file diff --git a/frontend/views/catalog/products.php b/frontend/views/catalog/products.php index c1310a9..c2b5057 100755 --- a/frontend/views/catalog/products.php +++ b/frontend/views/catalog/products.php @@ -1,4 +1,5 @@ implode(' ', $keywords), -]; - -$this->params['breadcrumbs'][] = ['label' => 'Поиск', 'url' => ['catalog/category', 'word' => implode(' ', $keywords)]]; -if (!empty($category)) { - $this->params['breadcrumbs'][] = $category->categoryName->value; - $page_data['category'] = $category->name; -} - -$this->title = Yii::t('product', "Search for \"{keywords}\"". (empty($category) ? '' : ' in category \"{category}\"'), $page_data); - -//$this->params['seo']['seo_text'] = 'TEST SEO TEXT'; -//$this->params['seo']['h1'] = 'TEST H1'; -//$this->params['seo']['description'] = 'TEST DESCRIPTION'; -//$this->params['seo']['fields']['name'] = 'TEST NAME FROM FIELD'; -//$this->params['seo']['key']= 'product_list'; -?> - - - -
- -
-
-
-
Категории
-
    - category_id == $_category->category_id; - $option_url = $checked ? Url::to(['catalog/category', 'word' => implode(' ', $keywords)]) : Url::to(['catalog/category', 'category' => $_category, 'word' => implode(' ', $keywords)]); - ?> -
  • - onchange="document.location=''" /> - name?> -
  • - -
-
-
-
- -
-

Поиск

-
-
-
    - models as $product) :?> - render('/catalog/product_item.php', ['product' => $product])?> - -
-
-
-
-
\ No newline at end of file diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index fe16015..4e9a7b9 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -157,7 +157,7 @@ $this->registerJsFile (Yii::$app->request->baseUrl . '/js/fix_height.js', ['posi