Commit 1aafb42deaed272d031969699a7d89d8015176ff
1 parent
0da76e63
-
Showing
4 changed files
with
42 additions
and
23 deletions
Show diff stats
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 |
... | ... | @@ -203,4 +205,12 @@ class Category extends \yii\db\ActiveRecord |
203 | 205 | } |
204 | 206 | return false; |
205 | 207 | } |
208 | + | |
209 | + public function beforeDelete() | |
210 | + { | |
211 | + if ( ($count = $this->getProducts()->count()) > 0) { | |
212 | + throw new ErrorException('С категорией "'. $this->name .'" связанно <strong>'. $count .'</strong> товаров. Удаление невозможно.'); | |
213 | + return false; | |
214 | + } | |
215 | + } | |
206 | 216 | } | ... | ... |
common/modules/product/models/Product.php
... | ... | @@ -233,7 +233,20 @@ class Product extends \yii\db\ActiveRecord |
233 | 233 | |
234 | 234 | public function getOptions() { |
235 | 235 | return $this->hasMany(TaxOption::className(), ['tax_option_id' => 'option_id'])->viaTable('product_option', ['product_id' => 'product_id']); |
236 | -// return $this->getRelations('product_option'); | |
236 | + } | |
237 | + | |
238 | + public function getProperties() { | |
239 | + $groups = $options = []; | |
240 | + foreach ($this->options as $option) { | |
241 | + $options[$option->tax_group_id][] = $option; | |
242 | + } | |
243 | + foreach (TaxGroup::find()->where(['tax_group_id' => array_keys($options)])->all() as $group) { | |
244 | + if (!empty($options[$group->tax_group_id])) { | |
245 | + $group->_options = $options[$group->tax_group_id]; | |
246 | + $groups[] = $group; | |
247 | + } | |
248 | + } | |
249 | + return $groups; | |
237 | 250 | } |
238 | 251 | |
239 | 252 | public function getStocks() { |
... | ... | @@ -374,18 +387,4 @@ class Product extends \yii\db\ActiveRecord |
374 | 387 | } |
375 | 388 | return $op; |
376 | 389 | } |
377 | - | |
378 | - public function getProperties() { | |
379 | - $groups = $options = []; | |
380 | - foreach ($this->options as $option) { | |
381 | - $options[$option->tax_group_id][] = $option; | |
382 | - } | |
383 | - foreach (TaxGroup::find()->where(['tax_group_id' => array_keys($options)])->all() as $group) { | |
384 | - if (!empty($options[$group->tax_group_id])) { | |
385 | - $group->_options = $options[$group->tax_group_id]; | |
386 | - $groups[] = $group; | |
387 | - } | |
388 | - } | |
389 | - return $groups; | |
390 | - } | |
391 | 390 | } | ... | ... |
common/modules/product/views/manage/import-process.php
... | ... | @@ -17,8 +17,6 @@ $this->registerJs(" |
17 | 17 | |
18 | 18 | doImport(); |
19 | 19 | |
20 | -// $('ul#process-result').prepend('<li style="color: green; font-weight: bold">Импорт завершен</li>'); | |
21 | - | |
22 | 20 | function doImport(from) { |
23 | 21 | from = typeof(from) != 'undefined' ? from : 0; |
24 | 22 | console.log('go', from); |
... | ... | @@ -35,7 +33,6 @@ $this->registerJs(" |
35 | 33 | |
36 | 34 | var per = Math.round(100*data.from/data.totalsize)+'%'; |
37 | 35 | $('#progressbar div').css({width: per}); |
38 | -// $('#progressbar .ui-progressbar-value').html(per); | |
39 | 36 | |
40 | 37 | if(data != false && !data.end) |
41 | 38 | { |
... | ... | @@ -43,6 +40,7 @@ $this->registerJs(" |
43 | 40 | } |
44 | 41 | else |
45 | 42 | { |
43 | + $('ul#process-result').prepend('<li>Импорт цен успешно завершен!</li>'); | |
46 | 44 | progressbar.hide('fast'); |
47 | 45 | in_process = false; |
48 | 46 | } |
... | ... | @@ -62,7 +60,7 @@ $this->registerJs(" |
62 | 60 | <?= \yii\jui\ProgressBar::widget([ |
63 | 61 | 'clientOptions' => [ |
64 | 62 | 'value' => 100, |
65 | - 'label' => 'ddd' | |
63 | + 'label' => '' | |
66 | 64 | ], |
67 | 65 | 'options' => [ |
68 | 66 | 'id' => 'progressbar' | ... | ... |
console/controllers/ImportController.php
... | ... | @@ -23,23 +23,35 @@ class ImportController extends Controller { |
23 | 23 | private function getProductsFile($file_type = 'uploadFileProducts') { |
24 | 24 | $filename = Yii::getAlias('@uploadDir') .'/'. Yii::getAlias('@'. $file_type); |
25 | 25 | if (!is_file($filename)) { |
26 | - $this->stderr("File $filename not found"); | |
27 | - return FALSE; | |
26 | + $this->stderr('Task already executed'); | |
27 | + return Controller::EXIT_CODE_ERROR; | |
28 | 28 | } |
29 | 29 | return fopen ($filename, 'r'); |
30 | 30 | } |
31 | 31 | |
32 | 32 | public function actionProducts() { |
33 | + if (file_exists(Yii::getAlias('@uploadDir/goProducts.lock'))) { | |
34 | + $this->errors[] = 'Task already executed'; | |
35 | + return Controller::EXIT_CODE_ERROR; | |
36 | + } | |
37 | + $ff = fopen(Yii::getAlias('@uploadDir/goProducts.lock'), 'w+'); | |
38 | + fclose($ff); | |
33 | 39 | $model = new Import(); |
34 | 40 | $data = $model->goProducts(0, null); |
35 | - | |
41 | + unlink(Yii::getAlias('@uploadDir/goProducts.lock')); | |
36 | 42 | return Controller::EXIT_CODE_NORMAL; |
37 | 43 | } |
38 | 44 | |
39 | 45 | public function actionPrices() { |
46 | + if (file_exists(Yii::getAlias('@uploadDir/goPrices.lock'))) { | |
47 | + $this->stderr('Task already executed'); | |
48 | + return Controller::EXIT_CODE_ERROR; | |
49 | + } | |
50 | + $ff = fopen(Yii::getAlias('@uploadDir/goPrices.lock'), 'w+'); | |
51 | + fclose($ff); | |
40 | 52 | $model = new Import(); |
41 | 53 | $data = $model->goPrices(0, null); |
42 | - | |
54 | + unlink(Yii::getAlias('@uploadDir/goPrices.lock')); | |
43 | 55 | return Controller::EXIT_CODE_NORMAL; |
44 | 56 | } |
45 | 57 | ... | ... |