Commit 20e5163fe80ccdb2c39284006f5f8e2061a09a65
1 parent
be12ad11
-
Showing
2 changed files
with
13 additions
and
2 deletions
Show diff stats
common/modules/product/models/Category.php
@@ -8,6 +8,7 @@ use common\components\artboxtree\ArtboxTreeHelper; | @@ -8,6 +8,7 @@ use common\components\artboxtree\ArtboxTreeHelper; | ||
8 | use common\modules\relation\relationBehavior; | 8 | use common\modules\relation\relationBehavior; |
9 | use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; | 9 | use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; |
10 | use Yii; | 10 | use Yii; |
11 | +use yii\base\ErrorException; | ||
11 | 12 | ||
12 | /** | 13 | /** |
13 | * This is the model class for table "category". | 14 | * This is the model class for table "category". |
@@ -28,6 +29,7 @@ use Yii; | @@ -28,6 +29,7 @@ use Yii; | ||
28 | * @property boolean $populary | 29 | * @property boolean $populary |
29 | * | 30 | * |
30 | * @property CategoryName $categoryName | 31 | * @property CategoryName $categoryName |
32 | + * @property Product[] $products | ||
31 | * @property ProductUnit $productUnit | 33 | * @property ProductUnit $productUnit |
32 | * @property CategoryName[] $categoryNames | 34 | * @property CategoryName[] $categoryNames |
33 | * @property ProductCategory[] $productCategories | 35 | * @property ProductCategory[] $productCategories |
@@ -202,4 +204,12 @@ class Category extends \yii\db\ActiveRecord | @@ -202,4 +204,12 @@ class Category extends \yii\db\ActiveRecord | ||
202 | } | 204 | } |
203 | return false; | 205 | return false; |
204 | } | 206 | } |
207 | + | ||
208 | + public function beforeDelete() | ||
209 | + { | ||
210 | + if ( ($count = $this->getProducts()->count()) > 0) { | ||
211 | + throw new ErrorException('С категорией "'. $this->name .'" связанно <strong>'. $count .'</strong> товаров. Удаление невозможно.'); | ||
212 | + return false; | ||
213 | + } | ||
214 | + } | ||
205 | } | 215 | } |
common/modules/product/views/manage/_form.php
@@ -23,8 +23,9 @@ use kartik\select2\Select2; | @@ -23,8 +23,9 @@ use kartik\select2\Select2; | ||
23 | 23 | ||
24 | <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?> | 24 | <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?> |
25 | 25 | ||
26 | - <?= $form->field($model, 'is_top')->checkbox() ?> | ||
27 | - <?= $form->field($model, 'is_new')->checkbox() ?> | 26 | + <?= $form->field($model, 'is_top')->checkbox(['label' => 'ТОП']) ?> |
27 | + <?= $form->field($model, 'is_new')->checkbox(['label' => 'Новинка']) ?> | ||
28 | + <?= $form->field($model, 'akciya')->checkbox(['label' => 'Акционный']) ?> | ||
28 | 29 | ||
29 | <?= $form->field($model, 'description')->widget(\mihaildev\ckeditor\CKEditor::className(),['editorOptions' => [ 'preset' => 'full', 'inline' => false, ], ]); ?> | 30 | <?= $form->field($model, 'description')->widget(\mihaildev\ckeditor\CKEditor::className(),['editorOptions' => [ 'preset' => 'full', 'inline' => false, ], ]); ?> |
30 | <?= $form->field($model, 'video')->textarea(); ?> | 31 | <?= $form->field($model, 'video')->textarea(); ?> |