Commit 20e5163fe80ccdb2c39284006f5f8e2061a09a65

Authored by Karnovsky A
1 parent be12ad11

-

common/modules/product/models/Category.php
... ... @@ -8,6 +8,7 @@ use common\components\artboxtree\ArtboxTreeHelper;
8 8 use common\modules\relation\relationBehavior;
9 9 use common\modules\rubrication\behaviors\ArtboxSynonymBehavior;
10 10 use Yii;
  11 +use yii\base\ErrorException;
11 12  
12 13 /**
13 14 * This is the model class for table "category".
... ... @@ -28,6 +29,7 @@ use Yii;
28 29 * @property boolean $populary
29 30 *
30 31 * @property CategoryName $categoryName
  32 + * @property Product[] $products
31 33 * @property ProductUnit $productUnit
32 34 * @property CategoryName[] $categoryNames
33 35 * @property ProductCategory[] $productCategories
... ... @@ -202,4 +204,12 @@ class Category extends \yii\db\ActiveRecord
202 204 }
203 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 23  
24 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 30 <?= $form->field($model, 'description')->widget(\mihaildev\ckeditor\CKEditor::className(),['editorOptions' => [ 'preset' => 'full', 'inline' => false, ], ]); ?>
30 31 <?= $form->field($model, 'video')->textarea(); ?>
... ...