Commit b30494bfda61ce8bade1727ea3f94281043ef859
1 parent
e8ccb1b4
Import browser beta
Showing
1 changed file
with
51 additions
and
58 deletions
Show diff stats
common/modules/product/models/Import.php
| @@ -213,8 +213,8 @@ | @@ -213,8 +213,8 @@ | ||
| 213 | $name = trim($name); | 213 | $name = trim($name); |
| 214 | $matches = []; | 214 | $matches = []; |
| 215 | if(preg_match($pattern, $name, $matches)) { | 215 | if(preg_match($pattern, $name, $matches)) { |
| 216 | - if(!isset($matches['remote_id'])) { | ||
| 217 | - $matches['remote_id'] = ''; | 216 | + if(!isset( $matches[ 'remote_id' ] )) { |
| 217 | + $matches[ 'remote_id' ] = ''; | ||
| 218 | } | 218 | } |
| 219 | return $matches; | 219 | return $matches; |
| 220 | } | 220 | } |
| @@ -237,10 +237,10 @@ | @@ -237,10 +237,10 @@ | ||
| 237 | foreach($catalog_names as $catalog_name) { | 237 | foreach($catalog_names as $catalog_name) { |
| 238 | // ==== Set category ==== | 238 | // ==== Set category ==== |
| 239 | $parsed_name = $this->parseName($catalog_name); | 239 | $parsed_name = $this->parseName($catalog_name); |
| 240 | - if(!empty($parsed_name['remote_id']) && ( $category = Category::find() | ||
| 241 | - ->joinWith('lang') | ||
| 242 | - ->andFilterWhere([ 'remote_id' => $parsed_name[ 'remote_id' ] ]) | ||
| 243 | - ->one() ) !== NULL | 240 | + if(!empty( $parsed_name[ 'remote_id' ] ) && ( $category = Category::find() |
| 241 | + ->joinWith('lang') | ||
| 242 | + ->andFilterWhere([ 'remote_id' => $parsed_name[ 'remote_id' ] ]) | ||
| 243 | + ->one() ) !== NULL | ||
| 244 | ) { | 244 | ) { |
| 245 | if(!empty( $category->lang )) { | 245 | if(!empty( $category->lang )) { |
| 246 | $category->lang->name = $parsed_name[ 'name' ]; | 246 | $category->lang->name = $parsed_name[ 'name' ]; |
| @@ -279,10 +279,10 @@ | @@ -279,10 +279,10 @@ | ||
| 279 | /** | 279 | /** |
| 280 | * @var Brand $brand | 280 | * @var Brand $brand |
| 281 | */ | 281 | */ |
| 282 | - if(!empty($parsed_name['remote_id']) && ($brand = Brand::find() | ||
| 283 | - ->joinWith('lang') | ||
| 284 | - ->andFilterWhere([ 'remote_id' => $parsed_name[ 'remote_id' ] ]) | ||
| 285 | - ->one() ) !== NULL | 282 | + if(!empty( $parsed_name[ 'remote_id' ] ) && ( $brand = Brand::find() |
| 283 | + ->joinWith('lang') | ||
| 284 | + ->andFilterWhere([ 'remote_id' => $parsed_name[ 'remote_id' ] ]) | ||
| 285 | + ->one() ) !== NULL | ||
| 286 | ) { | 286 | ) { |
| 287 | if(!empty( $brand->lang )) { | 287 | if(!empty( $brand->lang )) { |
| 288 | $brand->lang->name = $parsed_name[ 'name' ]; | 288 | $brand->lang->name = $parsed_name[ 'name' ]; |
| @@ -399,7 +399,7 @@ | @@ -399,7 +399,7 @@ | ||
| 399 | if(isset( $variants_options ) && !empty( $variants_options )) { | 399 | if(isset( $variants_options ) && !empty( $variants_options )) { |
| 400 | $_productVariant->options = $variants_options; | 400 | $_productVariant->options = $variants_options; |
| 401 | } | 401 | } |
| 402 | - | 402 | + |
| 403 | /** | 403 | /** |
| 404 | * @todo set to false | 404 | * @todo set to false |
| 405 | */ | 405 | */ |
| @@ -413,20 +413,19 @@ | @@ -413,20 +413,19 @@ | ||
| 413 | return $MOD_ARRAY; | 413 | return $MOD_ARRAY; |
| 414 | } | 414 | } |
| 415 | 415 | ||
| 416 | - private function debug($start_time, $message) { | ||
| 417 | - echo $message.': '.(time()-$start_time).'s passed'; | ||
| 418 | - } | 416 | + // private function debug($start_time, $message) { |
| 417 | + // echo $message.': '.(time()-$start_time).'s passed'; | ||
| 418 | + // } | ||
| 419 | 419 | ||
| 420 | public function goProducts($from = 0, $limit = NULL) | 420 | public function goProducts($from = 0, $limit = NULL) |
| 421 | { | 421 | { |
| 422 | - $start_time = time(); | ||
| 423 | set_time_limit(0); | 422 | set_time_limit(0); |
| 424 | 423 | ||
| 425 | if(!( $handle = $this->getProductsFile('uploadFileProducts') )) { | 424 | if(!( $handle = $this->getProductsFile('uploadFileProducts') )) { |
| 426 | $this->errors[] = 'File not found'; | 425 | $this->errors[] = 'File not found'; |
| 427 | return false; | 426 | return false; |
| 428 | } | 427 | } |
| 429 | - | 428 | + |
| 430 | $filesize = filesize(Yii::getAlias('@uploadDir') . '/' . Yii::getAlias('@uploadFileProducts')); | 429 | $filesize = filesize(Yii::getAlias('@uploadDir') . '/' . Yii::getAlias('@uploadFileProducts')); |
| 431 | 430 | ||
| 432 | if($from) { | 431 | if($from) { |
| @@ -512,36 +511,33 @@ | @@ -512,36 +511,33 @@ | ||
| 512 | $fotos = explode(',', trim($data[ 12 ])); | 511 | $fotos = explode(',', trim($data[ 12 ])); |
| 513 | } | 512 | } |
| 514 | 513 | ||
| 515 | -// $lang = \Yii::$app->session->get('export_lang', Language::getDefaultLanguage()->language_id); | ||
| 516 | -// /** | ||
| 517 | -// * @var Language $language | ||
| 518 | -// */ | ||
| 519 | -// $language = Language::find() | ||
| 520 | -// ->where([ 'language_id' => $lang ]) | ||
| 521 | -// ->one(); | ||
| 522 | -// Language::setCurrent($language->url); | ||
| 523 | - $start_time = time(); | 514 | + // $lang = \Yii::$app->session->get('export_lang', Language::getDefaultLanguage()->language_id); |
| 515 | + // /** | ||
| 516 | + // * @var Language $language | ||
| 517 | + // */ | ||
| 518 | + // $language = Language::find() | ||
| 519 | + // ->where([ 'language_id' => $lang ]) | ||
| 520 | + // ->one(); | ||
| 521 | + // Language::setCurrent($language->url); | ||
| 522 | + | ||
| 524 | $categories = $this->saveCatalog($catalog_names); | 523 | $categories = $this->saveCatalog($catalog_names); |
| 525 | - $this->debug($start_time, 'Categories'); | ||
| 526 | - $start_time = time(); | 524 | + |
| 527 | $brand_id = $this->saveBrand($brand_name); | 525 | $brand_id = $this->saveBrand($brand_name); |
| 528 | - $this->debug($start_time, 'Brands'); | ||
| 529 | 526 | ||
| 530 | $options = []; | 527 | $options = []; |
| 531 | if(!empty ( $filters )) { | 528 | if(!empty ( $filters )) { |
| 532 | - $start_time = time(); | 529 | + |
| 533 | $options = $this->saveFilters($filters, 0, $categories); | 530 | $options = $this->saveFilters($filters, 0, $categories); |
| 534 | - $this->debug($start_time, 'saveFilters'); | ||
| 535 | } | 531 | } |
| 536 | $parsed_name = $this->parseName($product_name); | 532 | $parsed_name = $this->parseName($product_name); |
| 537 | /** | 533 | /** |
| 538 | * @var Product $_product | 534 | * @var Product $_product |
| 539 | */ | 535 | */ |
| 540 | - $start_time = time(); | ||
| 541 | - if(!empty($parsed_name['remote_id']) && ( $_product = Product::find() | ||
| 542 | - ->joinWith('lang') | ||
| 543 | - ->andFilterWhere([ 'remote_id' => $parsed_name[ 'remote_id' ] ]) | ||
| 544 | - ->one() ) !== NULL | 536 | + |
| 537 | + if(!empty( $parsed_name[ 'remote_id' ] ) && ( $_product = Product::find() | ||
| 538 | + ->joinWith('lang') | ||
| 539 | + ->andFilterWhere([ 'remote_id' => $parsed_name[ 'remote_id' ] ]) | ||
| 540 | + ->one() ) !== NULL | ||
| 545 | ) { | 541 | ) { |
| 546 | if(!empty( $_product->lang )) { | 542 | if(!empty( $_product->lang )) { |
| 547 | $_product->lang->name = $parsed_name[ 'name' ]; | 543 | $_product->lang->name = $parsed_name[ 'name' ]; |
| @@ -559,7 +555,7 @@ | @@ -559,7 +555,7 @@ | ||
| 559 | $product_lang->description = $product_body; | 555 | $product_lang->description = $product_body; |
| 560 | } | 556 | } |
| 561 | } | 557 | } |
| 562 | - | 558 | + |
| 563 | $is_new_product = empty( $_product->product_id ); | 559 | $is_new_product = empty( $_product->product_id ); |
| 564 | 560 | ||
| 565 | $_product->categories = $categories; | 561 | $_product->categories = $categories; |
| @@ -570,7 +566,6 @@ | @@ -570,7 +566,6 @@ | ||
| 570 | $_product->is_top = $product_top; | 566 | $_product->is_top = $product_top; |
| 571 | $_product->akciya = $product_akciya; | 567 | $_product->akciya = $product_akciya; |
| 572 | $_product->is_new = $product_new; | 568 | $_product->is_new = $product_new; |
| 573 | - $this->debug($start_time, 'Product'); | ||
| 574 | if(!$_product->save()) { | 569 | if(!$_product->save()) { |
| 575 | if(!empty( $_product->lang )) { | 570 | if(!empty( $_product->lang )) { |
| 576 | $product_name_inserted = $_product->lang->name; | 571 | $product_name_inserted = $_product->lang->name; |
| @@ -580,13 +575,11 @@ | @@ -580,13 +575,11 @@ | ||
| 580 | $result_items[] = 'Product #' . $product_name_inserted . ' not saved' . " (line $j)"; | 575 | $result_items[] = 'Product #' . $product_name_inserted . ' not saved' . " (line $j)"; |
| 581 | continue; | 576 | continue; |
| 582 | } | 577 | } |
| 583 | - $start_time = time(); | 578 | + |
| 584 | $this->saveFotos($fotos, $_product->product_id); | 579 | $this->saveFotos($fotos, $_product->product_id); |
| 585 | - $this->debug($start_time, 'saveFotos'); | ||
| 586 | // ะฝัะถะฝะพ ะดะปั ะฟัะพััะฐะฒะปะตะฝะธั ั ะฐัะฐะบัะตัะธััะธะบ ะพัะฝะพัััะธั ัั ะบ ะผะพะดะธัะธะบะฐัะธัะผ | 580 | // ะฝัะถะฝะพ ะดะปั ะฟัะพััะฐะฒะปะตะฝะธั ั ะฐัะฐะบัะตัะธััะธะบ ะพัะฝะพัััะธั ัั ะบ ะผะพะดะธัะธะบะฐัะธัะผ |
| 587 | - $start_time = time(); | 581 | + |
| 588 | $this->saveVariants($data, $product_cost_old, $_product->product_id, $_product->categories, $product_cost); | 582 | $this->saveVariants($data, $product_cost_old, $_product->product_id, $_product->categories, $product_cost); |
| 589 | - $this->debug($start_time, 'saveVariants'); | ||
| 590 | if(!empty( $options )) { | 583 | if(!empty( $options )) { |
| 591 | $_product->options = $options; | 584 | $_product->options = $options; |
| 592 | } | 585 | } |
| @@ -596,7 +589,7 @@ | @@ -596,7 +589,7 @@ | ||
| 596 | $result_items[] = "Product {$_product->lang->name} #{$_product->product_id} saved (" . ( $is_new_product ? 'new product' : 'exists product' ) . ")" . " (line $j)"; | 589 | $result_items[] = "Product {$_product->lang->name} #{$_product->product_id} saved (" . ( $is_new_product ? 'new product' : 'exists product' ) . ")" . " (line $j)"; |
| 597 | 590 | ||
| 598 | } catch(\Exception $e) { | 591 | } catch(\Exception $e) { |
| 599 | - print $result_items[] = $e->getMessage() . '(line ' . $j . ')'; | 592 | + $result_items[] = $e->getMessage() . '(line ' . $j . ')'; |
| 600 | } | 593 | } |
| 601 | 594 | ||
| 602 | } | 595 | } |
| @@ -607,11 +600,11 @@ | @@ -607,11 +600,11 @@ | ||
| 607 | 'totalsize' => $filesize, | 600 | 'totalsize' => $filesize, |
| 608 | 'items' => $result_items, | 601 | 'items' => $result_items, |
| 609 | ]; | 602 | ]; |
| 610 | - | 603 | + |
| 611 | fclose($handle); | 604 | fclose($handle); |
| 612 | - | 605 | + |
| 613 | if($result[ 'end' ]) { | 606 | if($result[ 'end' ]) { |
| 614 | -// unlink(Yii::getAlias('@uploadDir') . '/' . Yii::getAlias('@uploadFileProducts')); | 607 | + // unlink(Yii::getAlias('@uploadDir') . '/' . Yii::getAlias('@uploadFileProducts')); |
| 615 | } | 608 | } |
| 616 | 609 | ||
| 617 | return $result; | 610 | return $result; |
| @@ -649,14 +642,15 @@ | @@ -649,14 +642,15 @@ | ||
| 649 | } | 642 | } |
| 650 | $filter_name = trim($filter[ 1 ][ 0 ]); | 643 | $filter_name = trim($filter[ 1 ][ 0 ]); |
| 651 | $parsed_group_name = $this->parseName($filter_name); | 644 | $parsed_group_name = $this->parseName($filter_name); |
| 652 | - $start_time = time(); | 645 | + |
| 653 | /** | 646 | /** |
| 654 | * @var TaxGroup $taxGroup | 647 | * @var TaxGroup $taxGroup |
| 655 | */ | 648 | */ |
| 656 | - if(!empty($parsed_group_name['remote_id']) && ($taxGroup = TaxGroup::find() | ||
| 657 | - ->joinWith('lang') | ||
| 658 | - ->andFilterWhere([ 'remote_id' => $parsed_group_name[ 'remote_id' ] ]) | ||
| 659 | - ->one()) !== NULL) { | 649 | + if(!empty( $parsed_group_name[ 'remote_id' ] ) && ( $taxGroup = TaxGroup::find() |
| 650 | + ->joinWith('lang') | ||
| 651 | + ->andFilterWhere([ 'remote_id' => $parsed_group_name[ 'remote_id' ] ]) | ||
| 652 | + ->one() ) !== NULL | ||
| 653 | + ) { | ||
| 660 | if(!empty( $taxGroup->lang )) { | 654 | if(!empty( $taxGroup->lang )) { |
| 661 | $taxGroup->lang->name = $parsed_group_name[ 'name' ]; | 655 | $taxGroup->lang->name = $parsed_group_name[ 'name' ]; |
| 662 | $taxGroup->lang->save(); | 656 | $taxGroup->lang->save(); |
| @@ -675,19 +669,19 @@ | @@ -675,19 +669,19 @@ | ||
| 675 | $taxGroup->is_filter = false; | 669 | $taxGroup->is_filter = false; |
| 676 | $taxGroup->save(); | 670 | $taxGroup->save(); |
| 677 | } | 671 | } |
| 678 | - print $this->debug($start_time, 'TaxGroup'); | ||
| 679 | $filters_options = explode(',', $filter[ 2 ][ 0 ]); | 672 | $filters_options = explode(',', $filter[ 2 ][ 0 ]); |
| 680 | foreach($filters_options as $filter_options) { | 673 | foreach($filters_options as $filter_options) { |
| 681 | $parsed_option_name = $this->parseName($filter_options); | 674 | $parsed_option_name = $this->parseName($filter_options); |
| 682 | /** | 675 | /** |
| 683 | * @var TaxOption $option | 676 | * @var TaxOption $option |
| 684 | */ | 677 | */ |
| 685 | - $start_time = time(); | ||
| 686 | - if(!empty($parsed_option_name['remote_id']) && ($option = TaxOption::find() | ||
| 687 | - ->joinWith('lang') | ||
| 688 | - ->andFilterWhere([ 'remote_id' => $parsed_option_name[ 'remote_id' ] ]) | ||
| 689 | - ->andFilterWhere([ 'tax_group_id' => $taxGroup->tax_group_id ]) | ||
| 690 | - ->one()) !== NULL) { | 678 | + |
| 679 | + if(!empty( $parsed_option_name[ 'remote_id' ] ) && ( $option = TaxOption::find() | ||
| 680 | + ->joinWith('lang') | ||
| 681 | + ->andFilterWhere([ 'remote_id' => $parsed_option_name[ 'remote_id' ] ]) | ||
| 682 | + ->andFilterWhere([ 'tax_group_id' => $taxGroup->tax_group_id ]) | ||
| 683 | + ->one() ) !== NULL | ||
| 684 | + ) { | ||
| 691 | if(!empty( $option->lang )) { | 685 | if(!empty( $option->lang )) { |
| 692 | $option->lang->value = $parsed_option_name[ 'name' ]; | 686 | $option->lang->value = $parsed_option_name[ 'name' ]; |
| 693 | $option->lang->save(); | 687 | $option->lang->save(); |
| @@ -706,7 +700,6 @@ | @@ -706,7 +700,6 @@ | ||
| 706 | $option->save(); | 700 | $option->save(); |
| 707 | } | 701 | } |
| 708 | $options[] = $option->tax_option_id; | 702 | $options[] = $option->tax_option_id; |
| 709 | - print $this->debug($start_time, 'TaxOption'); | ||
| 710 | } | 703 | } |
| 711 | } | 704 | } |
| 712 | return $options; | 705 | return $options; |