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