Commit 105200f0573ba0db5f128c198f2cd834bd73b370

Authored by Alexey Boroda
2 parents 2be06650 2e23f037

Merge remote-tracking branch 'origin/master'

common/modules/product/models/Export.php
... ... @@ -3,6 +3,7 @@
3 3 namespace common\modules\product\models;
4 4  
5 5 use common\modules\rubrication\models\TaxGroup;
  6 + use common\modules\rubrication\models\TaxOption;
6 7 use yii\base\Model;
7 8  
8 9 class Export extends Model
... ... @@ -59,7 +60,7 @@
59 60 $list = [
60 61 $categories,
61 62 !empty($product->brand) ? $product->brand ->name :'',
62   - $product->name,
  63 + $product->name . '(#' . $product->product_id .'#)',
63 64 '',
64 65 ( ( !empty( $product->description ) ) ? $product->description : '' ),
65 66 $filterString,
... ... @@ -101,14 +102,19 @@
101 102 return $result;
102 103  
103 104 }
104   -
  105 +
  106 + /**
  107 + * @param TaxOption[] $filters
  108 + *
  109 + * @return string
  110 + */
105 111 public function convertFilterToString($filters)
106 112 {
107 113 if(!empty($filters)){
108 114 $fittersArray = [];
109 115 foreach($filters as $filter) {
110 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 243  
244 244 public function goProducts($from = 0, $limit = null)
245 245 {
246   -
247 246 set_time_limit(0);
248 247 $new_products = $linked_products = 0;
249 248  
... ... @@ -318,6 +317,12 @@
318 317 $result_items[] = "Не указано наименование товара (строка $j)";
319 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 327 // 4 Описание Укр
323 328 $product_body_uk = $data[ 3 ];
... ... @@ -363,9 +368,16 @@
363 368 $product_image = explode('=', $data[ 14 ]);
364 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 382 $_product = new Product();
371 383 }
... ... @@ -621,26 +633,44 @@
621 633 $filters_options = explode(',', $filter[ 2 ][ 0 ]);
622 634  
623 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 646 if (!$value instanceof TaxValueString) {
631 647 // Create option
632 648 $option = new TaxOption();
633 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 656 $option->save();
636 657  
637 658 $value = new TaxValueString();
638 659 $value->tax_option_id = $option->tax_option_id;
639   - $value->value = $filter_options;
  660 + $value->value = $option->name;
640 661 $value->save();
641 662  
642 663 $option->default_value = $value->tax_value_id;
643 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 675 $options[] = $value->tax_option_id;
646 676  
... ... @@ -650,4 +680,14 @@
650 680  
651 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 694 \ No newline at end of file
... ...