Compare View

switch
from
...
to
 
Commits (2)
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/import.php renamed to common/modules/product/models/Import.php
@@ -63,8 +63,7 @@ class Import extends Model { @@ -63,8 +63,7 @@ class Import extends Model {
63 return FALSE; 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 if ($from) { 67 if ($from) {
69 fseek($handle, $from); 68 fseek($handle, $from);
70 } 69 }
@@ -97,28 +96,29 @@ class Import extends Model { @@ -97,28 +96,29 @@ class Import extends Model {
97 // товары в пути 96 // товары в пути
98 if (empty ($city_name)) 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 $this->output[] = 'Товар '. $product_title . ' в пути'; 104 $this->output[] = 'Товар '. $product_title . ' в пути';
106 105
107 continue; 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 $this->output[] = 'Для товара '. $product_title . ' не найдено соотвествие'; 116 $this->output[] = 'Для товара '. $product_title . ' не найдено соотвествие';
118 117
119 continue; 118 continue;
120 } 119 }
121 120
  121 +
122 $quantity = 0; 122 $quantity = 0;
123 123
124 // ===== Set stock ==== 124 // ===== Set stock ====
@@ -161,7 +161,6 @@ class Import extends Model { @@ -161,7 +161,6 @@ class Import extends Model {
161 161
162 if ($result['end']) { 162 if ($result['end']) {
163 unlink(Yii::getAlias('@uploadDir') .'/'. Yii::getAlias('@uploadFilePrices')); 163 unlink(Yii::getAlias('@uploadDir') .'/'. Yii::getAlias('@uploadFilePrices'));
164 - $this->output[] = '<font style="color:green; font-weight: bold">Импорт цен успешно завершен!</font>';  
165 } 164 }
166 165
167 return $result; 166 return $result;
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/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-&gt;registerJs(&quot; @@ -17,8 +17,6 @@ $this-&gt;registerJs(&quot;
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-&gt;registerJs(&quot; @@ -35,7 +33,6 @@ $this-&gt;registerJs(&quot;
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-&gt;registerJs(&quot; @@ -43,6 +40,7 @@ $this-&gt;registerJs(&quot;
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-&gt;registerJs(&quot; @@ -62,7 +60,7 @@ $this-&gt;registerJs(&quot;
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