diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php index e5b2eec..72bb94b 100755 --- a/common/modules/product/models/Category.php +++ b/common/modules/product/models/Category.php @@ -8,6 +8,7 @@ use common\components\artboxtree\ArtboxTreeHelper; use common\modules\relation\relationBehavior; use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; use Yii; +use yii\base\ErrorException; /** * This is the model class for table "category". @@ -28,6 +29,7 @@ use Yii; * @property boolean $populary * * @property CategoryName $categoryName + * @property Product[] $products * @property ProductUnit $productUnit * @property CategoryName[] $categoryNames * @property ProductCategory[] $productCategories @@ -202,4 +204,12 @@ class Category extends \yii\db\ActiveRecord } return false; } + + public function beforeDelete() + { + if ( ($count = $this->getProducts()->count()) > 0) { + throw new ErrorException('С категорией "'. $this->name .'" связанно '. $count .' товаров. Удаление невозможно.'); + return false; + } + } } diff --git a/common/modules/product/views/manage/_form.php b/common/modules/product/views/manage/_form.php index 0df3752..a0ee409 100755 --- a/common/modules/product/views/manage/_form.php +++ b/common/modules/product/views/manage/_form.php @@ -23,8 +23,9 @@ use kartik\select2\Select2; field($model, 'name')->textInput(['maxlength' => true]) ?> - field($model, 'is_top')->checkbox() ?> - field($model, 'is_new')->checkbox() ?> + field($model, 'is_top')->checkbox(['label' => 'ТОП']) ?> + field($model, 'is_new')->checkbox(['label' => 'Новинка']) ?> + field($model, 'akciya')->checkbox(['label' => 'Акционный']) ?> field($model, 'description')->widget(\mihaildev\ckeditor\CKEditor::className(),['editorOptions' => [ 'preset' => 'full', 'inline' => false, ], ]); ?> field($model, 'video')->textarea(); ?> -- libgit2 0.21.4