Commit 424ec7e0b4d2ebeacedd1107084b40f691cc36cd

Authored by Yarik
1 parent 4fb5e6c3

Import browser beta v0.1

common/modules/language/behaviors/LanguageBehavior.php
@@ -237,7 +237,7 @@ @@ -237,7 +237,7 @@
237 $success = true; 237 $success = true;
238 $model_langs = $this->model_langs; 238 $model_langs = $this->model_langs;
239 foreach($model_langs as $model_lang) { 239 foreach($model_langs as $model_lang) {
240 - if($model_lang->save(true) === false) { 240 + if($model_lang->save() === false) {
241 $success = false; 241 $success = false;
242 } 242 }
243 } 243 }
@@ -251,11 +251,7 @@ @@ -251,11 +251,7 @@
251 */ 251 */
252 $owner = $this->owner; 252 $owner = $this->owner;
253 $db = $owner::getDb(); 253 $db = $owner::getDb();
254 - if($owner instanceof Product) {  
255 - var_dump('HERE'); die();  
256 - }  
257 $this->_transaction = $db->beginTransaction(); 254 $this->_transaction = $db->beginTransaction();
258 -  
259 } 255 }
260 256
261 public function afterSave($event) 257 public function afterSave($event)
@@ -264,10 +260,6 @@ @@ -264,10 +260,6 @@
264 * @var ActiveRecord $owner 260 * @var ActiveRecord $owner
265 */ 261 */
266 $owner = $this->owner; 262 $owner = $this->owner;
267 - $this->_transaction->commit();  
268 - if($owner instanceof Product) {  
269 - var_dump($owner->product_id); die();  
270 - }  
271 if(!empty( $this->model_langs )) { 263 if(!empty( $this->model_langs )) {
272 if($this->linkLangs() && $this->saveLangs()) { 264 if($this->linkLangs() && $this->saveLangs()) {
273 $this->_transaction->commit(); 265 $this->_transaction->commit();
common/modules/product/models/Import.php
@@ -439,7 +439,6 @@ @@ -439,7 +439,6 @@
439 $result_items = []; 439 $result_items = [];
440 440
441 while(( empty( $limit ) || $j++ < $limit ) && ( $data = fgetcsv($handle, 10000, ";") ) !== false) { 441 while(( empty( $limit ) || $j++ < $limit ) && ( $data = fgetcsv($handle, 10000, ";") ) !== false) {
442 -  
443 try { 442 try {
444 foreach($data as &$value) { 443 foreach($data as &$value) {
445 if(!$is_utf) { 444 if(!$is_utf) {
@@ -519,14 +518,13 @@ @@ -519,14 +518,13 @@
519 // ->where([ 'language_id' => $lang ]) 518 // ->where([ 'language_id' => $lang ])
520 // ->one(); 519 // ->one();
521 // Language::setCurrent($language->url); 520 // Language::setCurrent($language->url);
522 -  
523 $categories = $this->saveCatalog($catalog_names); 521 $categories = $this->saveCatalog($catalog_names);
524 - 522 +
525 $brand_id = $this->saveBrand($brand_name); 523 $brand_id = $this->saveBrand($brand_name);
526 524
527 $options = []; 525 $options = [];
528 if(!empty ( $filters )) { 526 if(!empty ( $filters )) {
529 - 527 +
530 $options = $this->saveFilters($filters, 0, $categories); 528 $options = $this->saveFilters($filters, 0, $categories);
531 } 529 }
532 $parsed_name = $this->parseName($product_name); 530 $parsed_name = $this->parseName($product_name);
@@ -568,18 +566,14 @@ @@ -568,18 +566,14 @@
568 if(!empty( $options )) { 566 if(!empty( $options )) {
569 $_product->options = $options; 567 $_product->options = $options;
570 } 568 }
571 - 569 +
572 if(!empty( $_product->lang )) { 570 if(!empty( $_product->lang )) {
573 $product_name_inserted = $_product->lang->name; 571 $product_name_inserted = $_product->lang->name;
574 } else { 572 } else {
575 $product_name_inserted = $_product->model_langs[ Language::$current->language_id ]->name; 573 $product_name_inserted = $_product->model_langs[ Language::$current->language_id ]->name;
576 } 574 }
577 -  
578 - $_product->validate();  
579 - die(var_dump($_product->getErrors()));  
580 575
581 - var_dump($_product->save()); die();  
582 - if(!$_product->transactionStatus) { 576 + if(($_product->save() === false) || !$_product->transactionStatus) {
583 $result_items[] = 'Product #' . $product_name_inserted . ' not saved' . " (line $j)"; 577 $result_items[] = 'Product #' . $product_name_inserted . ' not saved' . " (line $j)";
584 continue; 578 continue;
585 } 579 }
@@ -639,15 +633,15 @@ @@ -639,15 +633,15 @@
639 { 633 {
640 $options = []; 634 $options = [];
641 foreach($filters as $filter) { 635 foreach($filters as $filter) {
642 - 636 +
643 preg_match_all('/\[(.*):(.*)\]/', $filter, $filter); 637 preg_match_all('/\[(.*):(.*)\]/', $filter, $filter);
644 - 638 +
645 if(empty( $filter[ 1 ][ 0 ] )) { 639 if(empty( $filter[ 1 ][ 0 ] )) {
646 continue; 640 continue;
647 } 641 }
648 $filter_name = trim($filter[ 1 ][ 0 ]); 642 $filter_name = trim($filter[ 1 ][ 0 ]);
649 $parsed_group_name = $this->parseName($filter_name); 643 $parsed_group_name = $this->parseName($filter_name);
650 - 644 +
651 /** 645 /**
652 * @var TaxGroup $taxGroup 646 * @var TaxGroup $taxGroup
653 */ 647 */
@@ -674,38 +668,38 @@ @@ -674,38 +668,38 @@
674 $taxGroup->is_filter = false; 668 $taxGroup->is_filter = false;
675 $taxGroup->save(); 669 $taxGroup->save();
676 } 670 }
677 - $filters_options = explode(',', $filter[ 2 ][ 0 ]);  
678 - foreach($filters_options as $filter_options) {  
679 - $parsed_option_name = $this->parseName($filter_options);  
680 - /**  
681 - * @var TaxOption $option  
682 - */  
683 -  
684 - if(!empty( $parsed_option_name[ 'remote_id' ] ) && ( $option = TaxOption::find()  
685 - ->joinWith('lang')  
686 - ->andFilterWhere([ 'remote_id' => $parsed_option_name[ 'remote_id' ] ])  
687 - ->andFilterWhere([ 'tax_group_id' => $taxGroup->tax_group_id ])  
688 - ->one() ) !== NULL  
689 - ) {  
690 - if(!empty( $option->lang )) {  
691 - $option->lang->value = $parsed_option_name[ 'name' ];  
692 - $option->lang->save();  
693 - } else {  
694 - throw new \Exception('Tax option with ID ' . $option->tax_option_id . ' and lang ' . Language::getCurrent()->language_id . ' doesn\'t exist');  
695 - }  
696 - } else {  
697 - // Create option  
698 - $option = new TaxOption();  
699 - $option->generateLangs();  
700 - $option_langs = $option->model_langs;  
701 - foreach($option_langs as $option_lang) {  
702 - $option_lang->value = $parsed_option_name[ 'name' ];  
703 - }  
704 - $option->tax_group_id = $taxGroup->tax_group_id;  
705 - $option->save();  
706 - }  
707 - $options[] = $option->tax_option_id;  
708 - } 671 +// $filters_options = explode(',', $filter[ 2 ][ 0 ]);
  672 +// foreach($filters_options as $filter_options) {
  673 +// $parsed_option_name = $this->parseName($filter_options);
  674 +// /**
  675 +// * @var TaxOption $option
  676 +// */
  677 +//
  678 +// if(!empty( $parsed_option_name[ 'remote_id' ] ) && ( $option = TaxOption::find()
  679 +// ->joinWith('lang')
  680 +// ->andFilterWhere([ 'remote_id' => $parsed_option_name[ 'remote_id' ] ])
  681 +// ->andFilterWhere([ 'tax_group_id' => $taxGroup->tax_group_id ])
  682 +// ->one() ) !== NULL
  683 +// ) {
  684 +// if(!empty( $option->lang )) {
  685 +// $option->lang->value = $parsed_option_name[ 'name' ];
  686 +// $option->lang->save();
  687 +// } else {
  688 +// throw new \Exception('Tax option with ID ' . $option->tax_option_id . ' and lang ' . Language::getCurrent()->language_id . ' doesn\'t exist');
  689 +// }
  690 +// } else {
  691 +// // Create option
  692 +// $option = new TaxOption();
  693 +// $option->generateLangs();
  694 +// $option_langs = $option->model_langs;
  695 +// foreach($option_langs as $option_lang) {
  696 +// $option_lang->value = $parsed_option_name[ 'name' ];
  697 +// }
  698 +// $option->tax_group_id = $taxGroup->tax_group_id;
  699 +// $option->save();
  700 +// }
  701 +// $options[] = $option->tax_option_id;
  702 +// }
709 } 703 }
710 return $options; 704 return $options;
711 } 705 }
common/modules/product/models/Product.php
@@ -156,15 +156,6 @@ @@ -156,15 +156,6 @@
156 { 156 {
157 return $this->hasOne(Brand::className(), [ 'brand_id' => 'brand_id' ]); 157 return $this->hasOne(Brand::className(), [ 'brand_id' => 'brand_id' ]);
158 } 158 }
159 -  
160 -  
161 -  
162 - public function beforeValidate()  
163 - {  
164 - if(parent::beforeValidate()){  
165 - die('here');  
166 - }  
167 - }  
168 159
169 /** 160 /**
170 * @return \yii\db\ActiveQuery 161 * @return \yii\db\ActiveQuery
@@ -354,53 +345,53 @@ @@ -354,53 +345,53 @@
354 ->sum('quantity'); 345 ->sum('quantity');
355 } 346 }
356 347
357 - public function afterSave($insert, $changedAttributes)  
358 - {  
359 - parent::afterSave($insert, $changedAttributes);  
360 -  
361 -  
362 - if(!empty($this->categories)){  
363 - $categories = Category::findAll($this->categories);  
364 - $this->unlinkAll('categories', true);  
365 - foreach($categories as $category){  
366 - $this->link('categories', $category);  
367 - }  
368 - }  
369 -  
370 - if(!empty($this->options)){  
371 - $options = TaxOption::findAll($this->options);  
372 - $this->unlinkAll('options',true);  
373 - foreach($options as $option){  
374 - $this->link('options', $option);  
375 - }  
376 - }  
377 -  
378 -  
379 - if (!empty($this->_variants)) {  
380 - $todel = [];  
381 - foreach ($this->variants ?: [] as $_variant) {  
382 - $todel[$_variant->product_variant_id] = $_variant->product_variant_id;  
383 - }  
384 - foreach ($this->_variants as $_variant) {  
385 - if (!is_array($_variant)) {  
386 - return;  
387 - }  
388 - if (!empty($_variant['product_variant_id'])) {  
389 - unset($todel[$_variant['product_variant_id']]);  
390 - $model = ProductVariant::findOne($_variant['product_variant_id']);  
391 - } else {  
392 - $model = new ProductVariant();  
393 - }  
394 - $_variant['product_id'] = $this->product_id;  
395 - $model->load(['ProductVariant' => $_variant]);  
396 - $model->product_id = $this->product_id;  
397 - $model->save();  
398 - }  
399 - if (!empty($todel)) {  
400 - ProductVariant::deleteAll(['product_variant_id' => $todel]);  
401 - }  
402 - }  
403 - } 348 +// public function afterSave($insert, $changedAttributes)
  349 +// {
  350 +// parent::afterSave($insert, $changedAttributes);
  351 +//
  352 +//
  353 +// if(!empty($this->categories)){
  354 +// $categories = Category::findAll($this->categories);
  355 +// $this->unlinkAll('categories', true);
  356 +// foreach($categories as $category){
  357 +// $this->link('categories', $category);
  358 +// }
  359 +// }
  360 +//
  361 +// if(!empty($this->options)){
  362 +// $options = TaxOption::findAll($this->options);
  363 +// $this->unlinkAll('options',true);
  364 +// foreach($options as $option){
  365 +// $this->link('options', $option);
  366 +// }
  367 +// }
  368 +//
  369 +//
  370 +// if (!empty($this->_variants)) {
  371 +// $todel = [];
  372 +// foreach ($this->variants ?: [] as $_variant) {
  373 +// $todel[$_variant->product_variant_id] = $_variant->product_variant_id;
  374 +// }
  375 +// foreach ($this->_variants as $_variant) {
  376 +// if (!is_array($_variant)) {
  377 +// return;
  378 +// }
  379 +// if (!empty($_variant['product_variant_id'])) {
  380 +// unset($todel[$_variant['product_variant_id']]);
  381 +// $model = ProductVariant::findOne($_variant['product_variant_id']);
  382 +// } else {
  383 +// $model = new ProductVariant();
  384 +// }
  385 +// $_variant['product_id'] = $this->product_id;
  386 +// $model->load(['ProductVariant' => $_variant]);
  387 +// $model->product_id = $this->product_id;
  388 +// $model->save();
  389 +// }
  390 +// if (!empty($todel)) {
  391 +// ProductVariant::deleteAll(['product_variant_id' => $todel]);
  392 +// }
  393 +// }
  394 +// }
404 395
405 public function imagesUpload() 396 public function imagesUpload()
406 { 397 {
common/modules/rubrication/models/TaxGroup.php
@@ -121,6 +121,7 @@ @@ -121,6 +121,7 @@
121 121
122 public function afterSave($insert, $changedAttributes) 122 public function afterSave($insert, $changedAttributes)
123 { 123 {
  124 + parent::afterSave($insert, $changedAttributes);
124 $this->unlinkAll('categories', true); 125 $this->unlinkAll('categories', true);
125 $categories = []; 126 $categories = [];
126 if(!empty( $this->categories )) { 127 if(!empty( $this->categories )) {
common/modules/rubrication/models/TaxOption.php
@@ -63,10 +63,10 @@ @@ -63,10 +63,10 @@
63 ], 63 ],
64 ], 64 ],
65 ], 65 ],
66 -// 'artboxtree' => [  
67 -// 'class' => ArtboxTreeBehavior::className(),  
68 -// 'keyNameGroup' => 'tax_group_id',  
69 -// ], 66 + 'artboxtree' => [
  67 + 'class' => ArtboxTreeBehavior::className(),
  68 + 'keyNameGroup' => 'tax_group_id',
  69 + ],
70 'language' => [ 70 'language' => [
71 'class' => LanguageBehavior::className(), 71 'class' => LanguageBehavior::className(),
72 ], 72 ],