Commit 9c7c486e7e9b7e662bd113a6bf73ca90e3ec596a

Authored by Administrator
1 parent 3a7e43ce

20.07.16

Showing 1 changed file with 6 additions and 8 deletions   Show diff stats
common/modules/product/models/Category.php
... ... @@ -138,10 +138,9 @@ class Category extends \yii\db\ActiveRecord
138 138 }
139 139  
140 140 public function getProducts() {
141   -// return $this->hasMany(Product::className(), ['product_id' => 'product_id'])
142   -// ->viaTable('product_category', ['category_id' => 'category_id'])
143   -// ->andOnCondition(['!=', ProductVariant::tableName() .'.stock', 0]);
144   - return $this->getRelations('product_categories');
  141 + return $this->hasMany(Product::className(), ['product_id' => 'product_id'])
  142 + ->viaTable('product_category', ['category_id' => 'category_id']);
  143 +// return $this->getRelations('product_categories');
145 144 }
146 145  
147 146 /**
... ... @@ -216,9 +215,8 @@ class Category extends \yii\db\ActiveRecord
216 215  
217 216 public function beforeDelete()
218 217 {
219   - if ( ($count = $this->getProducts()->count()) > 0) {
220   - throw new ErrorException('С категорией "'. $this->name .'" связанно <strong>'. $count .'</strong> товаров. Удаление невозможно.');
221   - return false;
222   - }
  218 + print_r($this->products);
  219 + die();
223 220 }
  221 +
224 222 }
... ...