Commit 9428f76b51069cd52948e57e2f75aa1bc00d32bb
Merge remote-tracking branch 'origin/master'
Showing
5 changed files
with
27 additions
and
15 deletions
Show diff stats
backend/controllers/BrandController.php
@@ -79,6 +79,7 @@ class BrandController extends Controller | @@ -79,6 +79,7 @@ class BrandController extends Controller | ||
79 | { | 79 | { |
80 | $model = new Brand(); | 80 | $model = new Brand(); |
81 | if ($model->load(Yii::$app->request->post()) && $model->save()) { | 81 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
82 | + exit; | ||
82 | 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)); | 83 | 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)); |
83 | } else { | 84 | } else { |
84 | return $this->render('create', [ | 85 | return $this->render('create', [ |
common/modules/product/models/Brand.php
@@ -27,12 +27,6 @@ class Brand extends \yii\db\ActiveRecord | @@ -27,12 +27,6 @@ class Brand extends \yii\db\ActiveRecord | ||
27 | public function behaviors() | 27 | public function behaviors() |
28 | { | 28 | { |
29 | return [ | 29 | return [ |
30 | - 'slug' => [ | ||
31 | - 'class' => Slug::className(), | ||
32 | - 'in_attribute' => 'name', | ||
33 | - 'out_attribute' => 'alias', | ||
34 | - 'translit' => true | ||
35 | - ], | ||
36 | 'artboxsynonym' => [ | 30 | 'artboxsynonym' => [ |
37 | 'class' => ArtboxSynonymBehavior::className(), | 31 | 'class' => ArtboxSynonymBehavior::className(), |
38 | 'keyNameValue' => 'brand_name_id', | 32 | 'keyNameValue' => 'brand_name_id', |
@@ -40,8 +34,13 @@ class Brand extends \yii\db\ActiveRecord | @@ -40,8 +34,13 @@ class Brand extends \yii\db\ActiveRecord | ||
40 | 'valueOptionId' => 'brand_id', | 34 | 'valueOptionId' => 'brand_id', |
41 | 'valueFields' => [ // postKey => DBFieldName | 35 | 'valueFields' => [ // postKey => DBFieldName |
42 | 'name' => 'value' | 36 | 'name' => 'value' |
37 | + ], | ||
38 | + 'slug' => [ | ||
39 | + 'valueKeyName' => 'value', | ||
40 | + 'slugKeyName' => 'alias', | ||
41 | + 'translit' => true | ||
43 | ] | 42 | ] |
44 | - ] | 43 | + ], |
45 | ]; | 44 | ]; |
46 | } | 45 | } |
47 | 46 | ||
@@ -112,6 +111,6 @@ class Brand extends \yii\db\ActiveRecord | @@ -112,6 +111,6 @@ class Brand extends \yii\db\ActiveRecord | ||
112 | } | 111 | } |
113 | 112 | ||
114 | public function getName() { | 113 | public function getName() { |
115 | - return empty($this->brandName) ? null : $this->brandName->value; | 114 | + return empty($this->brand_name_id) ? null : $this->brandName->value; |
116 | } | 115 | } |
117 | } | 116 | } |
common/modules/product/models/Category.php
@@ -42,12 +42,6 @@ class Category extends \yii\db\ActiveRecord | @@ -42,12 +42,6 @@ class Category extends \yii\db\ActiveRecord | ||
42 | 'keyNameGroup' => null, | 42 | 'keyNameGroup' => null, |
43 | 'keyNamePath' => 'path', | 43 | 'keyNamePath' => 'path', |
44 | ], | 44 | ], |
45 | - 'slug' => [ | ||
46 | - 'class' => RuSlug::className(), | ||
47 | - 'in_attribute' => 'name', | ||
48 | - 'out_attribute' => 'alias', | ||
49 | - 'translit' => true | ||
50 | - ], | ||
51 | 'artboxsynonym' => [ | 45 | 'artboxsynonym' => [ |
52 | 'class' => ArtboxSynonymBehavior::className(), | 46 | 'class' => ArtboxSynonymBehavior::className(), |
53 | 'keyNameValue' => 'category_name_id', | 47 | 'keyNameValue' => 'category_name_id', |
@@ -55,6 +49,11 @@ class Category extends \yii\db\ActiveRecord | @@ -55,6 +49,11 @@ class Category extends \yii\db\ActiveRecord | ||
55 | 'valueOptionId' => 'category_id', | 49 | 'valueOptionId' => 'category_id', |
56 | 'valueFields' => [ // postKey => DBFieldName | 50 | 'valueFields' => [ // postKey => DBFieldName |
57 | 'name' => 'value' | 51 | 'name' => 'value' |
52 | + ], | ||
53 | + 'slug' => [ | ||
54 | + 'valueKeyName' => 'value', | ||
55 | + 'slugKeyName' => 'alias', | ||
56 | + 'translit' => true | ||
58 | ] | 57 | ] |
59 | ], | 58 | ], |
60 | [ | 59 | [ |
common/modules/rubrication/behaviors/ArtboxSynonymBehavior.php
@@ -3,11 +3,13 @@ | @@ -3,11 +3,13 @@ | ||
3 | namespace common\modules\rubrication\behaviors; | 3 | namespace common\modules\rubrication\behaviors; |
4 | 4 | ||
5 | use common\modules\rubrication\models\TaxValueString; | 5 | use common\modules\rubrication\models\TaxValueString; |
6 | +use dosamigos\transliterator\TransliteratorHelper; | ||
6 | use yii\base\Behavior; | 7 | use yii\base\Behavior; |
7 | use yii\base\Exception; | 8 | use yii\base\Exception; |
8 | use yii\db\ActiveRecord; | 9 | use yii\db\ActiveRecord; |
9 | use Yii; | 10 | use Yii; |
10 | use yii\helpers\ArrayHelper; | 11 | use yii\helpers\ArrayHelper; |
12 | +use yii\helpers\Inflector; | ||
11 | use yii\web\NotFoundHttpException; | 13 | use yii\web\NotFoundHttpException; |
12 | 14 | ||
13 | class ArtboxSynonymBehavior extends Behavior { | 15 | class ArtboxSynonymBehavior extends Behavior { |
@@ -23,6 +25,8 @@ class ArtboxSynonymBehavior extends Behavior { | @@ -23,6 +25,8 @@ class ArtboxSynonymBehavior extends Behavior { | ||
23 | 25 | ||
24 | public $values = []; | 26 | public $values = []; |
25 | 27 | ||
28 | + public $slug = null; | ||
29 | + | ||
26 | /** | 30 | /** |
27 | * @param ActiveRecord $owner | 31 | * @param ActiveRecord $owner |
28 | * @throws Exception | 32 | * @throws Exception |
@@ -84,6 +88,7 @@ class ArtboxSynonymBehavior extends Behavior { | @@ -84,6 +88,7 @@ class ArtboxSynonymBehavior extends Behavior { | ||
84 | $valueModel->setAttribute($this->valueOptionId, $this->owner->getAttribute($this->keyNameId)); | 88 | $valueModel->setAttribute($this->valueOptionId, $this->owner->getAttribute($this->keyNameId)); |
85 | $valueModel->save(); | 89 | $valueModel->save(); |
86 | $this->owner->setAttribute($this->keyNameValue, $valueModel->getAttribute($this->valuePKey)); | 90 | $this->owner->setAttribute($this->keyNameValue, $valueModel->getAttribute($this->valuePKey)); |
91 | + $this->owner->{$this->slug['slugKeyName']} = $this->slugify($valueModel->{$this->slug['valueKeyName']}); | ||
87 | $this->owner->save(false); | 92 | $this->owner->save(false); |
88 | } | 93 | } |
89 | 94 | ||
@@ -111,6 +116,9 @@ class ArtboxSynonymBehavior extends Behavior { | @@ -111,6 +116,9 @@ class ArtboxSynonymBehavior extends Behavior { | ||
111 | if ($isave) { | 116 | if ($isave) { |
112 | $valueModel->setAttribute($this->valueOptionId, $this->owner->getAttribute($this->keyNameId)); | 117 | $valueModel->setAttribute($this->valueOptionId, $this->owner->getAttribute($this->keyNameId)); |
113 | $valueModel->save(); | 118 | $valueModel->save(); |
119 | + if (!empty($this->slug) && empty($this->owner->getAttribute($this->slug['slugKeyName']))) { | ||
120 | + $this->owner->{$this->slug['slugKeyName']} = $this->slugify($valueModel->{$this->slug['valueKeyName']}); | ||
121 | + } | ||
114 | } | 122 | } |
115 | } | 123 | } |
116 | 124 | ||
@@ -122,6 +130,11 @@ class ArtboxSynonymBehavior extends Behavior { | @@ -122,6 +130,11 @@ class ArtboxSynonymBehavior extends Behavior { | ||
122 | ]); | 130 | ]); |
123 | } | 131 | } |
124 | 132 | ||
133 | + private function slugify( $slug ) | ||
134 | + { | ||
135 | + return Inflector::slug( TransliteratorHelper::process( $slug ), '-', true ); | ||
136 | + } | ||
137 | + | ||
125 | /** | 138 | /** |
126 | * @inheritdoc | 139 | * @inheritdoc |
127 | */ | 140 | */ |
common/translation/ru/product.php