diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php index 9be052a..062accf 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 @@ -203,4 +205,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/models/Product.php b/common/modules/product/models/Product.php index af8ecb0..d4f24c9 100755 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -233,7 +233,20 @@ class Product extends \yii\db\ActiveRecord public function getOptions() { return $this->hasMany(TaxOption::className(), ['tax_option_id' => 'option_id'])->viaTable('product_option', ['product_id' => 'product_id']); -// return $this->getRelations('product_option'); + } + + public function getProperties() { + $groups = $options = []; + foreach ($this->options as $option) { + $options[$option->tax_group_id][] = $option; + } + foreach (TaxGroup::find()->where(['tax_group_id' => array_keys($options)])->all() as $group) { + if (!empty($options[$group->tax_group_id])) { + $group->_options = $options[$group->tax_group_id]; + $groups[] = $group; + } + } + return $groups; } public function getStocks() { @@ -374,18 +387,4 @@ class Product extends \yii\db\ActiveRecord } return $op; } - - public function getProperties() { - $groups = $options = []; - foreach ($this->options as $option) { - $options[$option->tax_group_id][] = $option; - } - foreach (TaxGroup::find()->where(['tax_group_id' => array_keys($options)])->all() as $group) { - if (!empty($options[$group->tax_group_id])) { - $group->_options = $options[$group->tax_group_id]; - $groups[] = $group; - } - } - return $groups; - } } diff --git a/common/modules/product/views/manage/import-process.php b/common/modules/product/views/manage/import-process.php index 206ae65..af24fce 100644 --- a/common/modules/product/views/manage/import-process.php +++ b/common/modules/product/views/manage/import-process.php @@ -17,8 +17,6 @@ $this->registerJs(" doImport(); -// $('ul#process-result').prepend('
  • Импорт завершен
  • '); - function doImport(from) { from = typeof(from) != 'undefined' ? from : 0; console.log('go', from); @@ -35,7 +33,6 @@ $this->registerJs(" var per = Math.round(100*data.from/data.totalsize)+'%'; $('#progressbar div').css({width: per}); -// $('#progressbar .ui-progressbar-value').html(per); if(data != false && !data.end) { @@ -43,6 +40,7 @@ $this->registerJs(" } else { + $('ul#process-result').prepend('
  • Импорт цен успешно завершен!
  • '); progressbar.hide('fast'); in_process = false; } @@ -62,7 +60,7 @@ $this->registerJs(" [ 'value' => 100, - 'label' => 'ddd' + 'label' => '' ], 'options' => [ 'id' => 'progressbar' diff --git a/console/controllers/ImportController.php b/console/controllers/ImportController.php index 78efc93..89ec367 100755 --- a/console/controllers/ImportController.php +++ b/console/controllers/ImportController.php @@ -23,23 +23,35 @@ class ImportController extends Controller { private function getProductsFile($file_type = 'uploadFileProducts') { $filename = Yii::getAlias('@uploadDir') .'/'. Yii::getAlias('@'. $file_type); if (!is_file($filename)) { - $this->stderr("File $filename not found"); - return FALSE; + $this->stderr('Task already executed'); + return Controller::EXIT_CODE_ERROR; } return fopen ($filename, 'r'); } public function actionProducts() { + if (file_exists(Yii::getAlias('@uploadDir/goProducts.lock'))) { + $this->errors[] = 'Task already executed'; + return Controller::EXIT_CODE_ERROR; + } + $ff = fopen(Yii::getAlias('@uploadDir/goProducts.lock'), 'w+'); + fclose($ff); $model = new Import(); $data = $model->goProducts(0, null); - + unlink(Yii::getAlias('@uploadDir/goProducts.lock')); return Controller::EXIT_CODE_NORMAL; } public function actionPrices() { + if (file_exists(Yii::getAlias('@uploadDir/goPrices.lock'))) { + $this->stderr('Task already executed'); + return Controller::EXIT_CODE_ERROR; + } + $ff = fopen(Yii::getAlias('@uploadDir/goPrices.lock'), 'w+'); + fclose($ff); $model = new Import(); $data = $model->goPrices(0, null); - + unlink(Yii::getAlias('@uploadDir/goPrices.lock')); return Controller::EXIT_CODE_NORMAL; } -- libgit2 0.21.4