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,6 +8,7 @@ use common\components\artboxtree\ArtboxTreeHelper; | ||
8 | use common\modules\relation\relationBehavior; | 8 | use common\modules\relation\relationBehavior; |
9 | use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; | 9 | use common\modules\rubrication\behaviors\ArtboxSynonymBehavior; |
10 | use Yii; | 10 | use Yii; |
11 | +use yii\base\ErrorException; | ||
11 | 12 | ||
12 | /** | 13 | /** |
13 | * This is the model class for table "category". | 14 | * This is the model class for table "category". |
@@ -28,6 +29,7 @@ use Yii; | @@ -28,6 +29,7 @@ use Yii; | ||
28 | * @property boolean $populary | 29 | * @property boolean $populary |
29 | * | 30 | * |
30 | * @property CategoryName $categoryName | 31 | * @property CategoryName $categoryName |
32 | + * @property Product[] $products | ||
31 | * @property ProductUnit $productUnit | 33 | * @property ProductUnit $productUnit |
32 | * @property CategoryName[] $categoryNames | 34 | * @property CategoryName[] $categoryNames |
33 | * @property ProductCategory[] $productCategories | 35 | * @property ProductCategory[] $productCategories |
@@ -203,4 +205,12 @@ class Category extends \yii\db\ActiveRecord | @@ -203,4 +205,12 @@ class Category extends \yii\db\ActiveRecord | ||
203 | } | 205 | } |
204 | return false; | 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,7 +233,20 @@ class Product extends \yii\db\ActiveRecord | ||
233 | 233 | ||
234 | public function getOptions() { | 234 | public function getOptions() { |
235 | return $this->hasMany(TaxOption::className(), ['tax_option_id' => 'option_id'])->viaTable('product_option', ['product_id' => 'product_id']); | 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 | public function getStocks() { | 252 | public function getStocks() { |
@@ -374,18 +387,4 @@ class Product extends \yii\db\ActiveRecord | @@ -374,18 +387,4 @@ class Product extends \yii\db\ActiveRecord | ||
374 | } | 387 | } |
375 | return $op; | 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,8 +17,6 @@ $this->registerJs(" | ||
17 | 17 | ||
18 | doImport(); | 18 | doImport(); |
19 | 19 | ||
20 | -// $('ul#process-result').prepend('<li style="color: green; font-weight: bold">Импорт завершен</li>'); | ||
21 | - | ||
22 | function doImport(from) { | 20 | function doImport(from) { |
23 | from = typeof(from) != 'undefined' ? from : 0; | 21 | from = typeof(from) != 'undefined' ? from : 0; |
24 | console.log('go', from); | 22 | console.log('go', from); |
@@ -35,7 +33,6 @@ $this->registerJs(" | @@ -35,7 +33,6 @@ $this->registerJs(" | ||
35 | 33 | ||
36 | var per = Math.round(100*data.from/data.totalsize)+'%'; | 34 | var per = Math.round(100*data.from/data.totalsize)+'%'; |
37 | $('#progressbar div').css({width: per}); | 35 | $('#progressbar div').css({width: per}); |
38 | -// $('#progressbar .ui-progressbar-value').html(per); | ||
39 | 36 | ||
40 | if(data != false && !data.end) | 37 | if(data != false && !data.end) |
41 | { | 38 | { |
@@ -43,6 +40,7 @@ $this->registerJs(" | @@ -43,6 +40,7 @@ $this->registerJs(" | ||
43 | } | 40 | } |
44 | else | 41 | else |
45 | { | 42 | { |
43 | + $('ul#process-result').prepend('<li>Импорт цен успешно завершен!</li>'); | ||
46 | progressbar.hide('fast'); | 44 | progressbar.hide('fast'); |
47 | in_process = false; | 45 | in_process = false; |
48 | } | 46 | } |
@@ -62,7 +60,7 @@ $this->registerJs(" | @@ -62,7 +60,7 @@ $this->registerJs(" | ||
62 | <?= \yii\jui\ProgressBar::widget([ | 60 | <?= \yii\jui\ProgressBar::widget([ |
63 | 'clientOptions' => [ | 61 | 'clientOptions' => [ |
64 | 'value' => 100, | 62 | 'value' => 100, |
65 | - 'label' => 'ddd' | 63 | + 'label' => '' |
66 | ], | 64 | ], |
67 | 'options' => [ | 65 | 'options' => [ |
68 | 'id' => 'progressbar' | 66 | 'id' => 'progressbar' |
console/controllers/ImportController.php
@@ -23,23 +23,35 @@ class ImportController extends Controller { | @@ -23,23 +23,35 @@ class ImportController extends Controller { | ||
23 | private function getProductsFile($file_type = 'uploadFileProducts') { | 23 | private function getProductsFile($file_type = 'uploadFileProducts') { |
24 | $filename = Yii::getAlias('@uploadDir') .'/'. Yii::getAlias('@'. $file_type); | 24 | $filename = Yii::getAlias('@uploadDir') .'/'. Yii::getAlias('@'. $file_type); |
25 | if (!is_file($filename)) { | 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 | return fopen ($filename, 'r'); | 29 | return fopen ($filename, 'r'); |
30 | } | 30 | } |
31 | 31 | ||
32 | public function actionProducts() { | 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 | $model = new Import(); | 39 | $model = new Import(); |
34 | $data = $model->goProducts(0, null); | 40 | $data = $model->goProducts(0, null); |
35 | - | 41 | + unlink(Yii::getAlias('@uploadDir/goProducts.lock')); |
36 | return Controller::EXIT_CODE_NORMAL; | 42 | return Controller::EXIT_CODE_NORMAL; |
37 | } | 43 | } |
38 | 44 | ||
39 | public function actionPrices() { | 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 | $model = new Import(); | 52 | $model = new Import(); |
41 | $data = $model->goPrices(0, null); | 53 | $data = $model->goPrices(0, null); |
42 | - | 54 | + unlink(Yii::getAlias('@uploadDir/goPrices.lock')); |
43 | return Controller::EXIT_CODE_NORMAL; | 55 | return Controller::EXIT_CODE_NORMAL; |
44 | } | 56 | } |
45 | 57 |