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 | 213 | $name = trim($name); |
| 214 | 214 | $matches = []; |
| 215 | 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 | 219 | return $matches; |
| 220 | 220 | } |
| ... | ... | @@ -237,10 +237,10 @@ |
| 237 | 237 | foreach($catalog_names as $catalog_name) { |
| 238 | 238 | // ==== Set category ==== |
| 239 | 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 | 245 | if(!empty( $category->lang )) { |
| 246 | 246 | $category->lang->name = $parsed_name[ 'name' ]; |
| ... | ... | @@ -279,10 +279,10 @@ |
| 279 | 279 | /** |
| 280 | 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 | 287 | if(!empty( $brand->lang )) { |
| 288 | 288 | $brand->lang->name = $parsed_name[ 'name' ]; |
| ... | ... | @@ -399,7 +399,7 @@ |
| 399 | 399 | if(isset( $variants_options ) && !empty( $variants_options )) { |
| 400 | 400 | $_productVariant->options = $variants_options; |
| 401 | 401 | } |
| 402 | - | |
| 402 | + | |
| 403 | 403 | /** |
| 404 | 404 | * @todo set to false |
| 405 | 405 | */ |
| ... | ... | @@ -413,20 +413,19 @@ |
| 413 | 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 | 420 | public function goProducts($from = 0, $limit = NULL) |
| 421 | 421 | { |
| 422 | - $start_time = time(); | |
| 423 | 422 | set_time_limit(0); |
| 424 | 423 | |
| 425 | 424 | if(!( $handle = $this->getProductsFile('uploadFileProducts') )) { |
| 426 | 425 | $this->errors[] = 'File not found'; |
| 427 | 426 | return false; |
| 428 | 427 | } |
| 429 | - | |
| 428 | + | |
| 430 | 429 | $filesize = filesize(Yii::getAlias('@uploadDir') . '/' . Yii::getAlias('@uploadFileProducts')); |
| 431 | 430 | |
| 432 | 431 | if($from) { |
| ... | ... | @@ -512,36 +511,33 @@ |
| 512 | 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 | 523 | $categories = $this->saveCatalog($catalog_names); |
| 525 | - $this->debug($start_time, 'Categories'); | |
| 526 | - $start_time = time(); | |
| 524 | + | |
| 527 | 525 | $brand_id = $this->saveBrand($brand_name); |
| 528 | - $this->debug($start_time, 'Brands'); | |
| 529 | 526 | |
| 530 | 527 | $options = []; |
| 531 | 528 | if(!empty ( $filters )) { |
| 532 | - $start_time = time(); | |
| 529 | + | |
| 533 | 530 | $options = $this->saveFilters($filters, 0, $categories); |
| 534 | - $this->debug($start_time, 'saveFilters'); | |
| 535 | 531 | } |
| 536 | 532 | $parsed_name = $this->parseName($product_name); |
| 537 | 533 | /** |
| 538 | 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 | 542 | if(!empty( $_product->lang )) { |
| 547 | 543 | $_product->lang->name = $parsed_name[ 'name' ]; |
| ... | ... | @@ -559,7 +555,7 @@ |
| 559 | 555 | $product_lang->description = $product_body; |
| 560 | 556 | } |
| 561 | 557 | } |
| 562 | - | |
| 558 | + | |
| 563 | 559 | $is_new_product = empty( $_product->product_id ); |
| 564 | 560 | |
| 565 | 561 | $_product->categories = $categories; |
| ... | ... | @@ -570,7 +566,6 @@ |
| 570 | 566 | $_product->is_top = $product_top; |
| 571 | 567 | $_product->akciya = $product_akciya; |
| 572 | 568 | $_product->is_new = $product_new; |
| 573 | - $this->debug($start_time, 'Product'); | |
| 574 | 569 | if(!$_product->save()) { |
| 575 | 570 | if(!empty( $_product->lang )) { |
| 576 | 571 | $product_name_inserted = $_product->lang->name; |
| ... | ... | @@ -580,13 +575,11 @@ |
| 580 | 575 | $result_items[] = 'Product #' . $product_name_inserted . ' not saved' . " (line $j)"; |
| 581 | 576 | continue; |
| 582 | 577 | } |
| 583 | - $start_time = time(); | |
| 578 | + | |
| 584 | 579 | $this->saveFotos($fotos, $_product->product_id); |
| 585 | - $this->debug($start_time, 'saveFotos'); | |
| 586 | 580 | // ะฝัะถะฝะพ ะดะปั ะฟัะพััะฐะฒะปะตะฝะธั ั ะฐัะฐะบัะตัะธััะธะบ ะพัะฝะพัััะธั ัั ะบ ะผะพะดะธัะธะบะฐัะธัะผ |
| 587 | - $start_time = time(); | |
| 581 | + | |
| 588 | 582 | $this->saveVariants($data, $product_cost_old, $_product->product_id, $_product->categories, $product_cost); |
| 589 | - $this->debug($start_time, 'saveVariants'); | |
| 590 | 583 | if(!empty( $options )) { |
| 591 | 584 | $_product->options = $options; |
| 592 | 585 | } |
| ... | ... | @@ -596,7 +589,7 @@ |
| 596 | 589 | $result_items[] = "Product {$_product->lang->name} #{$_product->product_id} saved (" . ( $is_new_product ? 'new product' : 'exists product' ) . ")" . " (line $j)"; |
| 597 | 590 | |
| 598 | 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 | 600 | 'totalsize' => $filesize, |
| 608 | 601 | 'items' => $result_items, |
| 609 | 602 | ]; |
| 610 | - | |
| 603 | + | |
| 611 | 604 | fclose($handle); |
| 612 | - | |
| 605 | + | |
| 613 | 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 | 610 | return $result; |
| ... | ... | @@ -649,14 +642,15 @@ |
| 649 | 642 | } |
| 650 | 643 | $filter_name = trim($filter[ 1 ][ 0 ]); |
| 651 | 644 | $parsed_group_name = $this->parseName($filter_name); |
| 652 | - $start_time = time(); | |
| 645 | + | |
| 653 | 646 | /** |
| 654 | 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 | 654 | if(!empty( $taxGroup->lang )) { |
| 661 | 655 | $taxGroup->lang->name = $parsed_group_name[ 'name' ]; |
| 662 | 656 | $taxGroup->lang->save(); |
| ... | ... | @@ -675,19 +669,19 @@ |
| 675 | 669 | $taxGroup->is_filter = false; |
| 676 | 670 | $taxGroup->save(); |
| 677 | 671 | } |
| 678 | - print $this->debug($start_time, 'TaxGroup'); | |
| 679 | 672 | $filters_options = explode(',', $filter[ 2 ][ 0 ]); |
| 680 | 673 | foreach($filters_options as $filter_options) { |
| 681 | 674 | $parsed_option_name = $this->parseName($filter_options); |
| 682 | 675 | /** |
| 683 | 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 | 685 | if(!empty( $option->lang )) { |
| 692 | 686 | $option->lang->value = $parsed_option_name[ 'name' ]; |
| 693 | 687 | $option->lang->save(); |
| ... | ... | @@ -706,7 +700,6 @@ |
| 706 | 700 | $option->save(); |
| 707 | 701 | } |
| 708 | 702 | $options[] = $option->tax_option_id; |
| 709 | - print $this->debug($start_time, 'TaxOption'); | |
| 710 | 703 | } |
| 711 | 704 | } |
| 712 | 705 | return $options; | ... | ... |