Commit 105200f0573ba0db5f128c198f2cd834bd73b370
Merge remote-tracking branch 'origin/master'
Showing
2 changed files
with
60 additions
and
14 deletions
Show diff stats
common/modules/product/models/Export.php
@@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
3 | namespace common\modules\product\models; | 3 | namespace common\modules\product\models; |
4 | 4 | ||
5 | use common\modules\rubrication\models\TaxGroup; | 5 | use common\modules\rubrication\models\TaxGroup; |
6 | + use common\modules\rubrication\models\TaxOption; | ||
6 | use yii\base\Model; | 7 | use yii\base\Model; |
7 | 8 | ||
8 | class Export extends Model | 9 | class Export extends Model |
@@ -59,7 +60,7 @@ | @@ -59,7 +60,7 @@ | ||
59 | $list = [ | 60 | $list = [ |
60 | $categories, | 61 | $categories, |
61 | !empty($product->brand) ? $product->brand ->name :'', | 62 | !empty($product->brand) ? $product->brand ->name :'', |
62 | - $product->name, | 63 | + $product->name . '(#' . $product->product_id .'#)', |
63 | '', | 64 | '', |
64 | ( ( !empty( $product->description ) ) ? $product->description : '' ), | 65 | ( ( !empty( $product->description ) ) ? $product->description : '' ), |
65 | $filterString, | 66 | $filterString, |
@@ -101,14 +102,19 @@ | @@ -101,14 +102,19 @@ | ||
101 | return $result; | 102 | return $result; |
102 | 103 | ||
103 | } | 104 | } |
104 | - | 105 | + |
106 | + /** | ||
107 | + * @param TaxOption[] $filters | ||
108 | + * | ||
109 | + * @return string | ||
110 | + */ | ||
105 | public function convertFilterToString($filters) | 111 | public function convertFilterToString($filters) |
106 | { | 112 | { |
107 | if(!empty($filters)){ | 113 | if(!empty($filters)){ |
108 | $fittersArray = []; | 114 | $fittersArray = []; |
109 | foreach($filters as $filter) { | 115 | foreach($filters as $filter) { |
110 | if($filter->taxGroup instanceof TaxGroup){ | 116 | if($filter->taxGroup instanceof TaxGroup){ |
111 | - $fittersArray[ $filter->taxGroup->alias ][] = $filter->value; | 117 | + $fittersArray[ $filter->taxGroup->alias ][] = $filter->value . '(#' . $filter->alias . '#)'; |
112 | } | 118 | } |
113 | 119 | ||
114 | } | 120 | } |
common/modules/product/models/Import.php
@@ -243,7 +243,6 @@ | @@ -243,7 +243,6 @@ | ||
243 | 243 | ||
244 | public function goProducts($from = 0, $limit = null) | 244 | public function goProducts($from = 0, $limit = null) |
245 | { | 245 | { |
246 | - | ||
247 | set_time_limit(0); | 246 | set_time_limit(0); |
248 | $new_products = $linked_products = 0; | 247 | $new_products = $linked_products = 0; |
249 | 248 | ||
@@ -318,6 +317,12 @@ | @@ -318,6 +317,12 @@ | ||
318 | $result_items[] = "Не указано наименование товара (строка $j)"; | 317 | $result_items[] = "Не указано наименование товара (строка $j)"; |
319 | continue; | 318 | continue; |
320 | } | 319 | } |
320 | + if (preg_match('/^.+\(#(\d+)#\)$/', trim($product_name), $remote_id)) { | ||
321 | + if (!empty( $remote_id[ 1 ] )) { | ||
322 | + $remote_id = $remote_id[ 1 ]; | ||
323 | + $product_name = substr($product_name, 0, strpos($product_name, '(#' . $remote_id . '#)')); | ||
324 | + } | ||
325 | + } | ||
321 | 326 | ||
322 | // 4 Описание Укр | 327 | // 4 Описание Укр |
323 | $product_body_uk = $data[ 3 ]; | 328 | $product_body_uk = $data[ 3 ]; |
@@ -363,9 +368,16 @@ | @@ -363,9 +368,16 @@ | ||
363 | $product_image = explode('=', $data[ 14 ]); | 368 | $product_image = explode('=', $data[ 14 ]); |
364 | $product_image = @$product_image[ 3 ]; | 369 | $product_image = @$product_image[ 3 ]; |
365 | 370 | ||
366 | - if (( $_product = Product::find() | ||
367 | - ->filterWhere([ 'name' => trim($product_name) ]) | ||
368 | - ->one() ) === null | 371 | + if (!empty( $remote_id )) { |
372 | + if (( $_product = Product::find() | ||
373 | + ->filterWhere([ 'product_id' => $remote_id ]) | ||
374 | + ->one() ) === null | ||
375 | + ) { | ||
376 | + $_product = new Product(); | ||
377 | + } | ||
378 | + } elseif (( $_product = Product::find() | ||
379 | + ->filterWhere([ 'name' => trim($product_name) ]) | ||
380 | + ->one() ) === null | ||
369 | ) { | 381 | ) { |
370 | $_product = new Product(); | 382 | $_product = new Product(); |
371 | } | 383 | } |
@@ -621,26 +633,44 @@ | @@ -621,26 +633,44 @@ | ||
621 | $filters_options = explode(',', $filter[ 2 ][ 0 ]); | 633 | $filters_options = explode(',', $filter[ 2 ][ 0 ]); |
622 | 634 | ||
623 | foreach ($filters_options as $filter_options) { | 635 | foreach ($filters_options as $filter_options) { |
624 | - $value = TaxValueString::find() | ||
625 | - ->innerJoinWith('taxOption') | ||
626 | - ->andWhere([ 'value' => $filter_options ]) | ||
627 | - ->andWhere([ 'tax_option.tax_group_id' => $taxGroup->tax_group_id ]) | ||
628 | - ->one(); | 636 | + $parsed_filter = $this->parseFilter($filter_options); |
637 | + $value = null; | ||
638 | + if ($parsed_filter !== false) { | ||
639 | + $value = TaxValueString::find() | ||
640 | + ->innerJoinWith('taxOption') | ||
641 | + ->andWhere([ 'tax_option.alias' => $parsed_filter[ 2 ] ]) | ||
642 | + ->andWhere([ 'tax_option.tax_group_id' => $taxGroup->tax_group_id ]) | ||
643 | + ->one(); | ||
644 | + } | ||
629 | 645 | ||
630 | if (!$value instanceof TaxValueString) { | 646 | if (!$value instanceof TaxValueString) { |
631 | // Create option | 647 | // Create option |
632 | $option = new TaxOption(); | 648 | $option = new TaxOption(); |
633 | $option->tax_group_id = $taxGroup->tax_group_id; | 649 | $option->tax_group_id = $taxGroup->tax_group_id; |
634 | - $option->name = $filter_options; | 650 | + if($parsed_filter !== false) { |
651 | + $option->name = $parsed_filter[1]; | ||
652 | + $option->alias = $parsed_filter[2]; | ||
653 | + } else { | ||
654 | + $option->name = $filter_options; | ||
655 | + } | ||
635 | $option->save(); | 656 | $option->save(); |
636 | 657 | ||
637 | $value = new TaxValueString(); | 658 | $value = new TaxValueString(); |
638 | $value->tax_option_id = $option->tax_option_id; | 659 | $value->tax_option_id = $option->tax_option_id; |
639 | - $value->value = $filter_options; | 660 | + $value->value = $option->name; |
640 | $value->save(); | 661 | $value->save(); |
641 | 662 | ||
642 | $option->default_value = $value->tax_value_id; | 663 | $option->default_value = $value->tax_value_id; |
643 | $option->save(); | 664 | $option->save(); |
665 | + } else { | ||
666 | + if($parsed_filter !== false) { | ||
667 | + $value->value = $parsed_filter[1]; | ||
668 | + $value->taxOption->name = $parsed_filter[1]; | ||
669 | + } else { | ||
670 | + $value->value = $filter_options; | ||
671 | + $value->taxOption->name = $filter_options; | ||
672 | + } | ||
673 | + $value->save(); | ||
644 | } | 674 | } |
645 | $options[] = $value->tax_option_id; | 675 | $options[] = $value->tax_option_id; |
646 | 676 | ||
@@ -650,4 +680,14 @@ | @@ -650,4 +680,14 @@ | ||
650 | 680 | ||
651 | return $options; | 681 | return $options; |
652 | } | 682 | } |
683 | + | ||
684 | + private function parseFilter($filter) | ||
685 | + { | ||
686 | + $regex = '/^(.+)\(#(.+)#\)$/'; | ||
687 | + if (preg_match($regex, $filter, $result)) { | ||
688 | + return $result; | ||
689 | + } else { | ||
690 | + return false; | ||
691 | + } | ||
692 | + } | ||
653 | } | 693 | } |
654 | \ No newline at end of file | 694 | \ No newline at end of file |