From 466144f8e553921568d6c907b14f6ec4b6e49f80 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 4 Aug 2016 15:43:31 +0300 Subject: [PATCH] 20.07.16 --- backend/views/seo-dynamic/_form.php | 13 ------------- frontend/controllers/CatalogController.php | 14 +++++++++----- frontend/widgets/Seo.php | 51 +++++++++++++++++++++++++++++++++------------------ 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/backend/views/seo-dynamic/_form.php b/backend/views/seo-dynamic/_form.php index 18c366d..d39755b 100755 --- a/backend/views/seo-dynamic/_form.php +++ b/backend/views/seo-dynamic/_form.php @@ -22,19 +22,6 @@ use yii\widgets\ActiveForm; field($model, 'param')->textInput(['maxlength' => true]) ?> - field($model, 'param')->dropDownList([ -// 'filter' => 'filter' -// ],[ 'prompt' => 'Выберите параметр...']); ?> - -field($model, 'filter_mod') -// ->radioList( -// ['onefilter' => 'One filter', 'twofilters' => 'Two filters', 'brand_assigment' => 'Brand and assignment '] -// ) -// ->label(false); -// ?> - - field($model, 'key')->textInput(['maxlength' => true]) ?> field($model, 'fields')->textInput(['maxlength' => true]) ?> diff --git a/frontend/controllers/CatalogController.php b/frontend/controllers/CatalogController.php index cd36d01..23c1efb 100755 --- a/frontend/controllers/CatalogController.php +++ b/frontend/controllers/CatalogController.php @@ -37,6 +37,7 @@ class CatalogController extends \yii\web\Controller /** @var Category $category */ $category = Yii::$app->request->get('category'); $filter = Yii::$app->request->get('filters', []); + $filter_check = $filter; if (empty($category->category_id) && empty($word)) { return $this->render( @@ -50,6 +51,7 @@ class CatalogController extends \yii\web\Controller $optionsList = ArrayHelper::getColumn(TaxGroup::find()->where(['is_filter' => 'TRUE'])->all(),'alias'); if ( !empty($filter['brands']) ) { + unset($filter_check['brands']); $brands = Brand::find()->select('brand_id')->where(['in', 'alias', $filter['brands']])->all(); $params['brands'] = []; foreach ($brands as $brand) { @@ -58,6 +60,7 @@ class CatalogController extends \yii\web\Controller } if ( !empty($filter['special']) ) { + unset($filter_check['special']); if (!is_array($filter['special'])) { $filter['special'] = [$filter['special']]; } @@ -73,12 +76,8 @@ class CatalogController extends \yii\web\Controller } -// if ( !empty($filter['options']) ) { -// $params['options'] = $filter['options']; -// } - - if ( !empty($filter['prices']) ) { + unset($filter_check['prices']); $params['prices'] = $filter['prices']; } @@ -87,11 +86,16 @@ class CatalogController extends \yii\web\Controller foreach($optionsList as $optionList){ if(isset($filter[$optionList])){ + unset($filter_check[$optionList]); $params[$optionList] = $filter[$optionList]; } } + if(!empty($filter_check)){ + $filter = array_diff_key($filter,$filter_check); + Yii::$app->response->redirect(['catalog/category', 'category' => $category, 'filters' =>$filter],301); + } $productModel = new ProductFrontendSearch(); //$productQuery = $productModel->getSearchQuery($category, $params); diff --git a/frontend/widgets/Seo.php b/frontend/widgets/Seo.php index e5a4fff..69b5fff 100755 --- a/frontend/widgets/Seo.php +++ b/frontend/widgets/Seo.php @@ -4,8 +4,10 @@ namespace frontend\widgets; use common\models\SeoDynamic; use common\modules\product\models\Brand; +use common\modules\rubrication\models\TaxGroup; use common\modules\rubrication\models\TaxOption; use yii\base\Widget; +use yii\helpers\ArrayHelper; use yii\helpers\Html; class Seo extends Widget @@ -148,31 +150,34 @@ class Seo extends Widget $array['brand'] = $model->name; } - if (isset($filter["pol"]) && count($filter["pol"]) == 1) { - $model = TaxOption::find()->where(['alias' => $filter["pol"]])->one(); - $array['sex'] = $model->value->value; + $optionsList = ArrayHelper::getColumn(TaxGroup::find()->where(['is_filter' => 'TRUE'])->all(),'alias'); - } + foreach($optionsList as $optionList){ - if (isset($filter["naznacenie"]) && count($filter["naznacenie"]) == 1) { - $model = TaxOption::find()->where(['alias' => $filter["naznacenie"]])->one(); - $array['naz'] = $model->value->value; + if (isset($filter[$optionList]) && count($filter[$optionList]) == 1) { - } + $model = TaxOption::find()->where(['alias' =>$filter[$optionList]])->one(); + $array[$optionList] = $model->value->value; + + + } - if (isset($filter["god"]) && count($filter["god"]) == 1) { - $model = TaxOption::find()->where(['alias' => $filter["god"]])->one(); - $array['year'] = $model->value->value; } - return $this->getTitleString($array); + $title_string = $this->getTitleString($array); + + if($title_string){ + return $title_string; + } - } else if (!empty($title)) { + } + + if (!empty($title)) { return $title; } else { return $this->project_name; @@ -291,6 +296,11 @@ class Seo extends Widget } + protected function findSeoByDynamicForFilters(){ + return SeoDynamic::find()->joinWith('seoCategory')->where(['param' =>'filters'])->one(); + } + + protected function getViewData() { $params = $this->getView()->params; @@ -331,12 +341,17 @@ class Seo extends Widget } public function getTitleString($array){ - $template = "{category} {naz} {brand} {sex} {year} купить в Украине, Киев, Харькове - цены, фото, отзывы | Rukzachok.com.ua"; - foreach ($array as $field_name => $field_value) { - $template = str_replace('{' . $field_name . '}', mb_strtolower($field_value), $template); + + $template = SeoDynamic::find()->select('title')->where(['param' =>'filters'])->one(); + if($template instanceof SeoDynamic){ + foreach ($array as $field_name => $field_value) { + $template->title = str_replace('{' . $field_name . '}', mb_strtolower($field_value), $template->title); + } + $template = preg_replace('/\{.[^\}]*\}\s/','',$template->title); + return $template; } - $template = preg_replace('/\{.[^\}]*\}\s/','',$template); - return $template; + + return false; } -- libgit2 0.21.4