Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.32 KB | None | 0 0
  1. public function index()
  2. {
  3. $this->load->model('import/error');
  4. $this->load->model('import/product');
  5. $this->load->model('import/currency');
  6. $this->load->model('import/language');
  7. $this->load->model('import/category');
  8. $this->load->model('import/manufacturer');
  9. $this->load->model('import/option');
  10. $this->load->model('import/attribute');
  11.  
  12. $products = array();
  13. $languages = array();
  14. $currencies = array();
  15. $groups = array();
  16. $brands = array();
  17. $options = array();
  18. $attributes = array();
  19.  
  20. if($this->getFromFile('db.products', false)===false ) {
  21. $db_products = $this->model_import_product->mappingProducts($this->supplier['supplier_id']);
  22.  
  23. $this->saveToFile('db.products', $db_products);
  24. }
  25.  
  26. $get_products = $this->get_content($this->supplier['url_product']);
  27.  
  28. if( $get_products && !$this->getFromFile('products'.$_GET['shop'], false) )
  29. {
  30. if( $get_products->languages )
  31. foreach ($get_products->languages->language as $language)
  32.  
  33. $languages[ (string)$language->id ] = (string)$language->code;
  34.  
  35. $currencies[ (string)$get_products->products['currency'] ] = (string)$get_products->products['currency'];
  36.  
  37. if( $get_products->categories )
  38.  
  39. foreach ($get_products->categories->category as $category)
  40.  
  41. $groups[ (string)$category->id ] = (string)$category->name;
  42.  
  43. if( $get_products->manufactures )
  44.  
  45. foreach ($get_products->manufactures->manufacturer as $manufacturer)
  46.  
  47. $brands[ (string)$manufacturer->id ] = (string)$manufacturer->name;
  48.  
  49. $db_products = $this->getFromFile('db.products');
  50.  
  51. foreach ($get_products->products->product as $product)
  52. {
  53.  
  54. $item = (array)$product;
  55. unset( $db_products[ $item['id'] ] );
  56. $item['code'] = (string)$product->code;
  57. $item['manufacturer_id'] = (string)$product->manufacturer_id;
  58. $item['options'] = array();
  59. $item['attributes'] = array();
  60. $item['images'] = array();
  61. $item['price'] = (float)$product->price;
  62. $item['price_old'] = (float)$product->price_old;
  63. $item['currency'] = (string)$get_products->products['currency'];
  64.  
  65. if( $product->description )
  66. foreach ($product->description as $description)
  67. $item['product_description'][ (string)$description['language_id'] ] = array(
  68. 'name' => (string)$description->title,
  69. 'short_description' => (string)$description->short_description,
  70. 'description' => (string)$description->description,
  71. );
  72.  
  73. if( $product->variants )
  74. foreach ($product->variants->variant as $variant) {
  75. $option_code = (string)$variant->title . (string)$variant->value_title;
  76.  
  77. $options[ $option_code ] = (string)$variant->title . ' ' . (string)$variant->value_title;
  78.  
  79. $item['options'][ $option_code ] = array(
  80. 'required' => 1,
  81. 'product_option_value' => array(
  82. 'quantity' => (int)$variant->quantity,
  83. 'subtract' => $this->supplier['subtract'],
  84. 'price' => (float)$variant->price,
  85. 'price_prefix' => (string)$variant->price_prefix,
  86. )
  87. );
  88. }
  89.  
  90. if ($product->amount_prices)
  91. foreach ($product->amount_prices->price as $price) {
  92. if ((int)$price->attributes()->amount > 0) {
  93. $item['product_discount'][] = array(
  94. 'quantity' => (int)$price->attributes()->amount,
  95. 'price' => (float)$price
  96. );
  97. }
  98. }
  99.  
  100. if( $product->attributes )
  101. foreach ($product->attributes->attribute as $attribute) {
  102. $attributes[ (string)$attribute['title'] ] = (string)$attribute['title'];
  103.  
  104. $item['attributes'][ (string)$attribute['title'] ] = (string)$attribute;
  105. }
  106.  
  107. $s = 0;
  108. if( $product->images )
  109. foreach ($product->images->image as $image) {
  110. if( (string)$image )
  111. $item['images'][] = array( 'name' => (string)$product->id . '_' . $s, 'url' => (string)$image );
  112.  
  113. $s++;
  114. }
  115.  
  116. $products[ (string)$product->id ] = $item;
  117. }
  118.  
  119. $this->saveToFile('db.products', $db_products);
  120. }
  121.  
  122. $this->languages = $this->model_import_language->mappingLanguages($this->supplier['supplier_id'], $languages);
  123. $this->currencies = $this->model_import_currency->mappingCurrencies($this->supplier['supplier_id'], $currencies);
  124. $this->categories = $this->model_import_category->mappingCategories($this->supplier['supplier_id'], $groups);
  125. $this->manufacturers = $this->model_import_manufacturer->mappingManufacturers($this->supplier['supplier_id'], $brands);
  126. $this->options = $this->model_import_option->mappingOptions($this->supplier['supplier_id'], $options);
  127. $this->attributes = $this->model_import_attribute->mappingAttributes($this->supplier['supplier_id'], $attributes);
  128.  
  129. if( $products ) {
  130. $products = array_chunk($products, $this->chunk_size);
  131.  
  132. $this->saveToFile('products'.$_GET['shop'], $products);
  133.  
  134. $this->redirect($this->url->link('import/' . $this->supplier_code, 'shop=' . $_GET['shop'], 'SSL'));
  135. }
  136.  
  137. if( $products = $this->getFromFile('products'.$_GET['shop']) ) {
  138. reset($products);
  139. $import = key($products);
  140.  
  141. $this->import( $products[ $import ] );
  142.  
  143. unset($products[ $import ]);
  144.  
  145. if( $products ) {
  146. $this->saveToFile('products'.$_GET['shop'], $products);
  147.  
  148. $this->redirect($this->url->link('import/' . $this->supplier_code, 'shop=' . $_GET['shop'], 'SSL'));
  149. } else {
  150. $db_products = $this->getFromFile('db.products');
  151.  
  152. foreach ($db_products as $sku => $db_product)
  153.  
  154. //$this->model_import_product->deleteProduct($db_product);
  155. $this->model_import_product->import(array('sku' => $sku), $this->supplier);
  156.  
  157. echo 'Import Success';
  158. }
  159. }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement