diff --git a/common/modules/product/models/Import.php b/common/modules/product/models/Import.php index c1ecdf2..4c470d7 100755 --- a/common/modules/product/models/Import.php +++ b/common/modules/product/models/Import.php @@ -213,8 +213,8 @@ $name = trim($name); $matches = []; if(preg_match($pattern, $name, $matches)) { - if(!isset($matches['remote_id'])) { - $matches['remote_id'] = ''; + if(!isset( $matches[ 'remote_id' ] )) { + $matches[ 'remote_id' ] = ''; } return $matches; } @@ -237,10 +237,10 @@ foreach($catalog_names as $catalog_name) { // ==== Set category ==== $parsed_name = $this->parseName($catalog_name); - if(!empty($parsed_name['remote_id']) && ( $category = Category::find() - ->joinWith('lang') - ->andFilterWhere([ 'remote_id' => $parsed_name[ 'remote_id' ] ]) - ->one() ) !== NULL + if(!empty( $parsed_name[ 'remote_id' ] ) && ( $category = Category::find() + ->joinWith('lang') + ->andFilterWhere([ 'remote_id' => $parsed_name[ 'remote_id' ] ]) + ->one() ) !== NULL ) { if(!empty( $category->lang )) { $category->lang->name = $parsed_name[ 'name' ]; @@ -279,10 +279,10 @@ /** * @var Brand $brand */ - if(!empty($parsed_name['remote_id']) && ($brand = Brand::find() - ->joinWith('lang') - ->andFilterWhere([ 'remote_id' => $parsed_name[ 'remote_id' ] ]) - ->one() ) !== NULL + if(!empty( $parsed_name[ 'remote_id' ] ) && ( $brand = Brand::find() + ->joinWith('lang') + ->andFilterWhere([ 'remote_id' => $parsed_name[ 'remote_id' ] ]) + ->one() ) !== NULL ) { if(!empty( $brand->lang )) { $brand->lang->name = $parsed_name[ 'name' ]; @@ -399,7 +399,7 @@ if(isset( $variants_options ) && !empty( $variants_options )) { $_productVariant->options = $variants_options; } - + /** * @todo set to false */ @@ -413,20 +413,19 @@ return $MOD_ARRAY; } - private function debug($start_time, $message) { - echo $message.': '.(time()-$start_time).'s passed'; - } + // private function debug($start_time, $message) { + // echo $message.': '.(time()-$start_time).'s passed'; + // } public function goProducts($from = 0, $limit = NULL) { - $start_time = time(); set_time_limit(0); if(!( $handle = $this->getProductsFile('uploadFileProducts') )) { $this->errors[] = 'File not found'; return false; } - + $filesize = filesize(Yii::getAlias('@uploadDir') . '/' . Yii::getAlias('@uploadFileProducts')); if($from) { @@ -512,36 +511,33 @@ $fotos = explode(',', trim($data[ 12 ])); } -// $lang = \Yii::$app->session->get('export_lang', Language::getDefaultLanguage()->language_id); -// /** -// * @var Language $language -// */ -// $language = Language::find() -// ->where([ 'language_id' => $lang ]) -// ->one(); -// Language::setCurrent($language->url); - $start_time = time(); + // $lang = \Yii::$app->session->get('export_lang', Language::getDefaultLanguage()->language_id); + // /** + // * @var Language $language + // */ + // $language = Language::find() + // ->where([ 'language_id' => $lang ]) + // ->one(); + // Language::setCurrent($language->url); + $categories = $this->saveCatalog($catalog_names); - $this->debug($start_time, 'Categories'); - $start_time = time(); + $brand_id = $this->saveBrand($brand_name); - $this->debug($start_time, 'Brands'); $options = []; if(!empty ( $filters )) { - $start_time = time(); + $options = $this->saveFilters($filters, 0, $categories); - $this->debug($start_time, 'saveFilters'); } $parsed_name = $this->parseName($product_name); /** * @var Product $_product */ - $start_time = time(); - if(!empty($parsed_name['remote_id']) && ( $_product = Product::find() - ->joinWith('lang') - ->andFilterWhere([ 'remote_id' => $parsed_name[ 'remote_id' ] ]) - ->one() ) !== NULL + + if(!empty( $parsed_name[ 'remote_id' ] ) && ( $_product = Product::find() + ->joinWith('lang') + ->andFilterWhere([ 'remote_id' => $parsed_name[ 'remote_id' ] ]) + ->one() ) !== NULL ) { if(!empty( $_product->lang )) { $_product->lang->name = $parsed_name[ 'name' ]; @@ -559,7 +555,7 @@ $product_lang->description = $product_body; } } - + $is_new_product = empty( $_product->product_id ); $_product->categories = $categories; @@ -570,7 +566,6 @@ $_product->is_top = $product_top; $_product->akciya = $product_akciya; $_product->is_new = $product_new; - $this->debug($start_time, 'Product'); if(!$_product->save()) { if(!empty( $_product->lang )) { $product_name_inserted = $_product->lang->name; @@ -580,13 +575,11 @@ $result_items[] = 'Product #' . $product_name_inserted . ' not saved' . " (line $j)"; continue; } - $start_time = time(); + $this->saveFotos($fotos, $_product->product_id); - $this->debug($start_time, 'saveFotos'); // нужно для проставления характеристик относящихся к модификациям - $start_time = time(); + $this->saveVariants($data, $product_cost_old, $_product->product_id, $_product->categories, $product_cost); - $this->debug($start_time, 'saveVariants'); if(!empty( $options )) { $_product->options = $options; } @@ -596,7 +589,7 @@ $result_items[] = "Product {$_product->lang->name} #{$_product->product_id} saved (" . ( $is_new_product ? 'new product' : 'exists product' ) . ")" . " (line $j)"; } catch(\Exception $e) { - print $result_items[] = $e->getMessage() . '(line ' . $j . ')'; + $result_items[] = $e->getMessage() . '(line ' . $j . ')'; } } @@ -607,11 +600,11 @@ 'totalsize' => $filesize, 'items' => $result_items, ]; - + fclose($handle); - + if($result[ 'end' ]) { -// unlink(Yii::getAlias('@uploadDir') . '/' . Yii::getAlias('@uploadFileProducts')); + // unlink(Yii::getAlias('@uploadDir') . '/' . Yii::getAlias('@uploadFileProducts')); } return $result; @@ -649,14 +642,15 @@ } $filter_name = trim($filter[ 1 ][ 0 ]); $parsed_group_name = $this->parseName($filter_name); - $start_time = time(); + /** * @var TaxGroup $taxGroup */ - if(!empty($parsed_group_name['remote_id']) && ($taxGroup = TaxGroup::find() - ->joinWith('lang') - ->andFilterWhere([ 'remote_id' => $parsed_group_name[ 'remote_id' ] ]) - ->one()) !== NULL) { + if(!empty( $parsed_group_name[ 'remote_id' ] ) && ( $taxGroup = TaxGroup::find() + ->joinWith('lang') + ->andFilterWhere([ 'remote_id' => $parsed_group_name[ 'remote_id' ] ]) + ->one() ) !== NULL + ) { if(!empty( $taxGroup->lang )) { $taxGroup->lang->name = $parsed_group_name[ 'name' ]; $taxGroup->lang->save(); @@ -675,19 +669,19 @@ $taxGroup->is_filter = false; $taxGroup->save(); } - print $this->debug($start_time, 'TaxGroup'); $filters_options = explode(',', $filter[ 2 ][ 0 ]); foreach($filters_options as $filter_options) { $parsed_option_name = $this->parseName($filter_options); /** * @var TaxOption $option */ - $start_time = time(); - if(!empty($parsed_option_name['remote_id']) && ($option = TaxOption::find() - ->joinWith('lang') - ->andFilterWhere([ 'remote_id' => $parsed_option_name[ 'remote_id' ] ]) - ->andFilterWhere([ 'tax_group_id' => $taxGroup->tax_group_id ]) - ->one()) !== NULL) { + + if(!empty( $parsed_option_name[ 'remote_id' ] ) && ( $option = TaxOption::find() + ->joinWith('lang') + ->andFilterWhere([ 'remote_id' => $parsed_option_name[ 'remote_id' ] ]) + ->andFilterWhere([ 'tax_group_id' => $taxGroup->tax_group_id ]) + ->one() ) !== NULL + ) { if(!empty( $option->lang )) { $option->lang->value = $parsed_option_name[ 'name' ]; $option->lang->save(); @@ -706,7 +700,6 @@ $option->save(); } $options[] = $option->tax_option_id; - print $this->debug($start_time, 'TaxOption'); } } return $options; -- libgit2 0.21.4