Compare View
Commits (2)
Showing
6 changed files
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/import.php renamed to common/modules/product/models/Import.php
| ... | ... | @@ -63,8 +63,7 @@ class Import extends Model { |
| 63 | 63 | return FALSE; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - $filesize = filesize(Yii::getAlias('@uploadDir') .'/'. Yii::getAlias('@uploadFileProducts')); | |
| 67 | - | |
| 66 | + $filesize = filesize(Yii::getAlias('@uploadDir') .'/'. Yii::getAlias('@uploadFilePrices')); | |
| 68 | 67 | if ($from) { |
| 69 | 68 | fseek($handle, $from); |
| 70 | 69 | } |
| ... | ... | @@ -97,28 +96,29 @@ class Import extends Model { |
| 97 | 96 | // товары в пути |
| 98 | 97 | if (empty ($city_name)) |
| 99 | 98 | { |
| 100 | - $this->saveNotFoundRecord ( | |
| 101 | - [$modification_code, $product_title], | |
| 102 | - Yii::getAlias('@uploadFilePricesAway') | |
| 103 | - ); | |
| 99 | +// $this->saveNotFoundRecord ( | |
| 100 | +// [$modification_code, $product_title], | |
| 101 | +// Yii::getAlias('@uploadFilePricesAway') | |
| 102 | +// ); | |
| 104 | 103 | |
| 105 | 104 | $this->output[] = 'Товар '. $product_title . ' в пути'; |
| 106 | 105 | |
| 107 | 106 | continue; |
| 108 | 107 | } |
| 109 | 108 | |
| 110 | - if ( ($productVariant = ProductVariant::find()->filterWhere(['sku' => trim($modification_code)])->one()) === null ) { | |
| 109 | + if ( ($productVariant = ProductVariant::find()->filterWhere(['sku' => $modification_code])->one()) === null ) { | |
| 111 | 110 | // 'Нет даной модификации в базе'; |
| 112 | - $this->saveNotFoundRecord ( | |
| 113 | - [$modification_code, $product_title], | |
| 114 | - Yii::getAlias('@uploadFilePricesNoVariant') | |
| 115 | - ); | |
| 111 | +// $this->saveNotFoundRecord ( | |
| 112 | +// [$modification_code, $product_title], | |
| 113 | +// Yii::getAlias('@uploadFilePricesNoVariant') | |
| 114 | +// ); | |
| 116 | 115 | |
| 117 | 116 | $this->output[] = 'Для товара '. $product_title . ' не найдено соотвествие'; |
| 118 | 117 | |
| 119 | 118 | continue; |
| 120 | 119 | } |
| 121 | 120 | |
| 121 | + | |
| 122 | 122 | $quantity = 0; |
| 123 | 123 | |
| 124 | 124 | // ===== Set stock ==== |
| ... | ... | @@ -161,7 +161,6 @@ class Import extends Model { |
| 161 | 161 | |
| 162 | 162 | if ($result['end']) { |
| 163 | 163 | unlink(Yii::getAlias('@uploadDir') .'/'. Yii::getAlias('@uploadFilePrices')); |
| 164 | - $this->output[] = '<font style="color:green; font-weight: bold">Импорт цен успешно завершен!</font>'; | |
| 165 | 164 | } |
| 166 | 165 | |
| 167 | 166 | return $result; | ... | ... |
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/models/ProductVariantTypeSearch.php
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace common\modules\product\models; | |
| 4 | + | |
| 5 | +use Yii; | |
| 6 | +use yii\base\Model; | |
| 7 | +use yii\data\ActiveDataProvider; | |
| 8 | +use common\modules\product\models\ProductVariantType; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * ProductVariantTypeSearch represents the model behind the search form about `common\modules\product\models\ProductVariantType`. | |
| 12 | + */ | |
| 13 | +class ProductVariantTypeSearch extends ProductVariantType | |
| 14 | +{ | |
| 15 | + /** | |
| 16 | + * @inheritdoc | |
| 17 | + */ | |
| 18 | + public function rules() | |
| 19 | + { | |
| 20 | + return [ | |
| 21 | + [['product_variant_type_id'], 'integer'], | |
| 22 | + [['name', 'name2'], 'safe'], | |
| 23 | + ]; | |
| 24 | + } | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * @inheritdoc | |
| 28 | + */ | |
| 29 | + public function scenarios() | |
| 30 | + { | |
| 31 | + // bypass scenarios() implementation in the parent class | |
| 32 | + return Model::scenarios(); | |
| 33 | + } | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * Creates data provider instance with search query applied | |
| 37 | + * | |
| 38 | + * @param array $params | |
| 39 | + * | |
| 40 | + * @return ActiveDataProvider | |
| 41 | + */ | |
| 42 | + public function search($params) | |
| 43 | + { | |
| 44 | + $query = ProductVariantType::find(); | |
| 45 | + | |
| 46 | + // add conditions that should always apply here | |
| 47 | + | |
| 48 | + $dataProvider = new ActiveDataProvider([ | |
| 49 | + 'query' => $query, | |
| 50 | + ]); | |
| 51 | + | |
| 52 | + $this->load($params); | |
| 53 | + | |
| 54 | + if (!$this->validate()) { | |
| 55 | + // uncomment the following line if you do not want to return any records when validation fails | |
| 56 | + // $query->where('0=1'); | |
| 57 | + return $dataProvider; | |
| 58 | + } | |
| 59 | + | |
| 60 | + // grid filtering conditions | |
| 61 | + $query->andFilterWhere([ | |
| 62 | + 'product_variant_type_id' => $this->product_variant_type_id, | |
| 63 | + ]); | |
| 64 | + | |
| 65 | + $query->andFilterWhere(['like', 'name', $this->name]) | |
| 66 | + ->andFilterWhere(['like', 'name2', $this->name2]); | |
| 67 | + | |
| 68 | + return $dataProvider; | |
| 69 | + } | |
| 70 | +} | ... | ... |
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 | ... | ... |