From 0b8441f2aa956c0e9402b4c5e228615f142ceaf2 Mon Sep 17 00:00:00 2001 From: Karnovsky A Date: Tue, 3 May 2016 08:51:03 +0300 Subject: [PATCH] Karnovsky-02052016 --- backend/controllers/BrandController.php | 1 + common/modules/product/models/Brand.php | 15 +++++++-------- common/modules/product/models/Category.php | 11 +++++------ common/modules/rubrication/behaviors/ArtboxSynonymBehavior.php | 13 +++++++++++++ common/translation/ru/product.php | 2 +- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/backend/controllers/BrandController.php b/backend/controllers/BrandController.php index d3eb8c2..60b51d6 100755 --- a/backend/controllers/BrandController.php +++ b/backend/controllers/BrandController.php @@ -79,6 +79,7 @@ class BrandController extends Controller { $model = new Brand(); if ($model->load(Yii::$app->request->post()) && $model->save()) { + exit; return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect(['view', 'id' => $model->brand_id]) : $this->redirect(array_merge(['create'], Yii::$app->request->queryParams)); } else { return $this->render('create', [ diff --git a/common/modules/product/models/Brand.php b/common/modules/product/models/Brand.php index 1e0c7f4..f2fbde7 100755 --- a/common/modules/product/models/Brand.php +++ b/common/modules/product/models/Brand.php @@ -27,12 +27,6 @@ class Brand extends \yii\db\ActiveRecord public function behaviors() { return [ - 'slug' => [ - 'class' => Slug::className(), - 'in_attribute' => 'name', - 'out_attribute' => 'alias', - 'translit' => true - ], 'artboxsynonym' => [ 'class' => ArtboxSynonymBehavior::className(), 'keyNameValue' => 'brand_name_id', @@ -40,8 +34,13 @@ class Brand extends \yii\db\ActiveRecord 'valueOptionId' => 'brand_id', 'valueFields' => [ // postKey => DBFieldName 'name' => 'value' + ], + 'slug' => [ + 'valueKeyName' => 'value', + 'slugKeyName' => 'alias', + 'translit' => true ] - ] + ], ]; } @@ -112,6 +111,6 @@ class Brand extends \yii\db\ActiveRecord } public function getName() { - return empty($this->brandName) ? null : $this->brandName->value; + return empty($this->brand_name_id) ? null : $this->brandName->value; } } diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php index f474cee..fd6549b 100755 --- a/common/modules/product/models/Category.php +++ b/common/modules/product/models/Category.php @@ -42,12 +42,6 @@ class Category extends \yii\db\ActiveRecord 'keyNameGroup' => null, 'keyNamePath' => 'path', ], - 'slug' => [ - 'class' => RuSlug::className(), - 'in_attribute' => 'name', - 'out_attribute' => 'alias', - 'translit' => true - ], 'artboxsynonym' => [ 'class' => ArtboxSynonymBehavior::className(), 'keyNameValue' => 'category_name_id', @@ -55,6 +49,11 @@ class Category extends \yii\db\ActiveRecord 'valueOptionId' => 'category_id', 'valueFields' => [ // postKey => DBFieldName 'name' => 'value' + ], + 'slug' => [ + 'valueKeyName' => 'value', + 'slugKeyName' => 'alias', + 'translit' => true ] ], [ diff --git a/common/modules/rubrication/behaviors/ArtboxSynonymBehavior.php b/common/modules/rubrication/behaviors/ArtboxSynonymBehavior.php index 0775d69..5fe2bed 100755 --- a/common/modules/rubrication/behaviors/ArtboxSynonymBehavior.php +++ b/common/modules/rubrication/behaviors/ArtboxSynonymBehavior.php @@ -3,11 +3,13 @@ namespace common\modules\rubrication\behaviors; use common\modules\rubrication\models\TaxValueString; +use dosamigos\transliterator\TransliteratorHelper; use yii\base\Behavior; use yii\base\Exception; use yii\db\ActiveRecord; use Yii; use yii\helpers\ArrayHelper; +use yii\helpers\Inflector; use yii\web\NotFoundHttpException; class ArtboxSynonymBehavior extends Behavior { @@ -23,6 +25,8 @@ class ArtboxSynonymBehavior extends Behavior { public $values = []; + public $slug = null; + /** * @param ActiveRecord $owner * @throws Exception @@ -84,6 +88,7 @@ class ArtboxSynonymBehavior extends Behavior { $valueModel->setAttribute($this->valueOptionId, $this->owner->getAttribute($this->keyNameId)); $valueModel->save(); $this->owner->setAttribute($this->keyNameValue, $valueModel->getAttribute($this->valuePKey)); + $this->owner->{$this->slug['slugKeyName']} = $this->slugify($valueModel->{$this->slug['valueKeyName']}); $this->owner->save(false); } @@ -111,6 +116,9 @@ class ArtboxSynonymBehavior extends Behavior { if ($isave) { $valueModel->setAttribute($this->valueOptionId, $this->owner->getAttribute($this->keyNameId)); $valueModel->save(); + if (!empty($this->slug) && empty($this->owner->getAttribute($this->slug['slugKeyName']))) { + $this->owner->{$this->slug['slugKeyName']} = $this->slugify($valueModel->{$this->slug['valueKeyName']}); + } } } @@ -122,6 +130,11 @@ class ArtboxSynonymBehavior extends Behavior { ]); } + private function slugify( $slug ) + { + return Inflector::slug( TransliteratorHelper::process( $slug ), '-', true ); + } + /** * @inheritdoc */ diff --git a/common/translation/ru/product.php b/common/translation/ru/product.php index ca98483..cd47b48 100644 --- a/common/translation/ru/product.php +++ b/common/translation/ru/product.php @@ -1,4 +1,4 @@ -` 'Категории', 'Create Category' => 'Создать Категорию', -- libgit2 0.21.4