Product Import Export for WooCommerce - Version 2.0.5

Version Description

  • Tested OK with WP 5.8.
  • Bug fix: Product attribute update issue.
Download this release

Release Info

Developer webtoffee
Plugin Icon 128x128 Product Import Export for WooCommerce
Version 2.0.5
Comparing to
See all releases

Code changes from version 2.0.4 to 2.0.5

admin/classes/class-csvreader.php CHANGED
@@ -74,8 +74,8 @@ class Wt_Import_Export_For_Woo_Basic_Csvreader
74
  $val=(isset($sample_data_val[$k]) ? $this->format_data_from_csv($sample_data_val[$k], $enc) : '');
75
 
76
  /* removing BOM like non characters */
77
- // $key=preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $key);
78
- $key= wt_removeBomUtf8_basic($key);
79
  if($grouping)
80
  {
81
  if(strrpos($key, ':')!==false)
@@ -158,8 +158,8 @@ class Wt_Import_Export_For_Woo_Basic_Csvreader
158
  }else
159
  {
160
  /* removing BOM like non characters */
161
- // $head_arr[$head_key]=preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $head_val);
162
- $head_arr[$head_key]= wt_removeBomUtf8_basic($head_val);
163
  }
164
  }
165
 
74
  $val=(isset($sample_data_val[$k]) ? $this->format_data_from_csv($sample_data_val[$k], $enc) : '');
75
 
76
  /* removing BOM like non characters */
77
+ $key=preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $key);
78
+ //$key= wt_removeBomUtf8_basic($key);
79
  if($grouping)
80
  {
81
  if(strrpos($key, ':')!==false)
158
  }else
159
  {
160
  /* removing BOM like non characters */
161
+ $head_arr[$head_key]=preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $head_val);
162
+ //$head_arr[$head_key]= wt_removeBomUtf8_basic($head_val);
163
  }
164
  }
165
 
admin/modules/import/import.php CHANGED
@@ -136,6 +136,17 @@ class Wt_Import_Export_For_Woo_Basic_Import
136
  'help_text'=>__('Provide the default count for the records to be imported in a batch.'),
137
  'validation_rule'=>array('type'=>'absint'),
138
  );
 
 
 
 
 
 
 
 
 
 
 
139
  return $fields;
140
  }
141
 
136
  'help_text'=>__('Provide the default count for the records to be imported in a batch.'),
137
  'validation_rule'=>array('type'=>'absint'),
138
  );
139
+
140
+ $fields['maximum_execution_time'] = array(
141
+ 'label' => __("Maximum execution time"),
142
+ 'type' => 'number',
143
+ 'value' => ini_get('max_execution_time'), /* Default max_execution_time settings value */
144
+ 'field_name' => 'maximum_execution_time',
145
+ 'field_group' => 'advanced_field',
146
+ 'help_text' => __('The maximum execution time, in seconds(eg:- 300, 600, 1800, 3600). If set to zero, no time limit is imposed. Increasing this will reduce the chance of export/import timeouts.'),
147
+ 'validation_rule' => array('type' => 'int'),
148
+ );
149
+
150
  return $fields;
151
  }
152
 
admin/modules/product/import/import.php CHANGED
@@ -180,7 +180,7 @@ class Wt_Import_Export_For_Woo_Basic_Product_Import {
180
  if((isset($mapped_data['ID']) && !empty($mapped_data['ID']))||(isset($mapped_data['_sku']) && !empty($mapped_data['_sku'])) || (isset($mapped_data['sku']) && !empty($mapped_data['sku']))){
181
  $this->item_data['id'] = $this->wt_product_existance_check($mapped_data); // to determine wether merge or import
182
  }
183
-
184
  if(!$this->merge){
185
  $default_data = $this->get_default_data();
186
  $this->item_data = wp_parse_args( $this->item_data, $default_data );
@@ -405,10 +405,12 @@ class Wt_Import_Export_For_Woo_Basic_Product_Import {
405
  continue;
406
  }
407
  if ('download_limit' == $column || '_download_limit' == $column) {
 
408
  $this->item_data['download_limit'] = $this->wt_parse_int_field($value);
409
  continue;
410
  }
411
  if ('download_expiry' == $column || '_download_expiry' == $column) {
 
412
  $this->item_data['download_expiry'] = $this->wt_parse_int_field($value);
413
  continue;
414
  }
@@ -461,7 +463,14 @@ class Wt_Import_Export_For_Woo_Basic_Product_Import {
461
  continue;
462
  }
463
 
464
- }
 
 
 
 
 
 
 
465
 
466
  if(empty($this->item_data['id'])){
467
  $this->item_data['id'] = $this->wt_parse_id_field($mapped_data);
@@ -885,8 +894,37 @@ class Wt_Import_Export_For_Woo_Basic_Product_Import {
885
  }
886
  }
887
 
888
-
889
- if($this->is_product_exist){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
890
  if('skip' == $this->found_action){
891
  if($id && $id_found_with_id ){
892
  throw new Exception(sprintf('Product with same ID already exists. ID: %d',$id ));
@@ -1352,7 +1390,7 @@ class Wt_Import_Export_For_Woo_Basic_Product_Import {
1352
  try {
1353
  do_action('wt_woocommerce_product_import_before_process_item', $data);
1354
  $data = apply_filters('wt_woocommerce_product_import_process_item_data', $data);
1355
-
1356
  // Get product ID from SKU if created during the importation.
1357
  if (empty($data['id']) && !empty($data['sku'])) {
1358
  $product_id = wc_get_product_id_by_sku($data['sku']);
@@ -1414,12 +1452,29 @@ class Wt_Import_Export_For_Woo_Basic_Product_Import {
1414
 
1415
  $this->set_meta_data($object, $data);
1416
  $this->set_other_taxonomy_data($object, $data);
1417
-
1418
  $object = apply_filters('wt_woocommerce_product_import_pre_insert_product_object', $object, $data);
1419
 
1420
  $object->save();
1421
 
1422
- if($this->delete_existing){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1423
  update_post_meta($object->get_id(), '_wt_delete_existing', 1);
1424
  }
1425
 
@@ -1579,6 +1634,12 @@ class Wt_Import_Export_For_Woo_Basic_Product_Import {
1579
  $default_attributes = array();
1580
  $existing_attributes = $product->get_attributes();
1581
 
 
 
 
 
 
 
1582
  foreach ($data['raw_attributes'] as $position => $attribute) {
1583
  $attribute_id = 0;
1584
 
@@ -1649,13 +1710,7 @@ class Wt_Import_Export_For_Woo_Basic_Product_Import {
1649
  $attributes[] = $attribute_object;
1650
  }
1651
  }
1652
-
1653
- if(isset($existing_attributes)){
1654
- foreach ($existing_attributes as $key => $existing_attribute) {
1655
- $attributes[] = $existing_attribute;
1656
- }
1657
- }
1658
-
1659
  $product->set_attributes($attributes);
1660
 
1661
  }
@@ -1831,5 +1886,52 @@ class Wt_Import_Export_For_Woo_Basic_Product_Import {
1831
  }
1832
  }
1833
 
1834
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1835
  }
180
  if((isset($mapped_data['ID']) && !empty($mapped_data['ID']))||(isset($mapped_data['_sku']) && !empty($mapped_data['_sku'])) || (isset($mapped_data['sku']) && !empty($mapped_data['sku']))){
181
  $this->item_data['id'] = $this->wt_product_existance_check($mapped_data); // to determine wether merge or import
182
  }
183
+
184
  if(!$this->merge){
185
  $default_data = $this->get_default_data();
186
  $this->item_data = wp_parse_args( $this->item_data, $default_data );
405
  continue;
406
  }
407
  if ('download_limit' == $column || '_download_limit' == $column) {
408
+ $value = trim($value,'\'');
409
  $this->item_data['download_limit'] = $this->wt_parse_int_field($value);
410
  continue;
411
  }
412
  if ('download_expiry' == $column || '_download_expiry' == $column) {
413
+ $value = trim($value,'\'');
414
  $this->item_data['download_expiry'] = $this->wt_parse_int_field($value);
415
  continue;
416
  }
463
  continue;
464
  }
465
 
466
+ /**
467
+ * WPML
468
+ */
469
+ if ($column == 'wpml:original_product_id' || $column == 'wpml:original_product_sku' || $column == 'wpml:language_code') {
470
+ $column = trim(str_replace('wpml:', '', $column));
471
+ $this->item_data['wpml'][] = array('key' => esc_attr($column), 'value' => $value);
472
+ }
473
+ }
474
 
475
  if(empty($this->item_data['id'])){
476
  $this->item_data['id'] = $this->wt_parse_id_field($mapped_data);
894
  }
895
  }
896
 
897
+ /*
898
+ * WPML
899
+ */
900
+
901
+ if (apply_filters('wpml_setting', false, 'setup_complete') && (!empty($sku)) && ((!empty($data['wpml:original_product_id']) || !empty($data['wpml:original_product_sku'])) && !empty($data['wpml:language_code']))) {
902
+
903
+ $db_query = $wpdb->prepare("
904
+ SELECT $wpdb->posts.ID
905
+ FROM $wpdb->posts
906
+ LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
907
+ WHERE $wpdb->posts.post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )
908
+ AND $wpdb->postmeta.meta_key = '_sku' AND $wpdb->postmeta.meta_value = '%s'
909
+ ", $sku);
910
+ $found_product_ids = $wpdb->get_results($db_query);
911
+
912
+ /*
913
+ * Finding product ID by sku (each translation may have the same sku if the translation created by duplicating original product)
914
+ */
915
+ $found_product_id = '';
916
+ foreach ($found_product_ids as $value) {
917
+ $original_post_language_info = self::wt_get_wpml_original_post_language_info($value->ID);
918
+ if ($original_post_language_info->language_code == $data['wpml:language_code']) {
919
+ $found_product_id = $value->ID;
920
+ }
921
+ }
922
+ if ($found_product_id != '') {
923
+ $product_id = $found_product_id;
924
+ }
925
+ }
926
+
927
+ if($this->is_product_exist){
928
  if('skip' == $this->found_action){
929
  if($id && $id_found_with_id ){
930
  throw new Exception(sprintf('Product with same ID already exists. ID: %d',$id ));
1390
  try {
1391
  do_action('wt_woocommerce_product_import_before_process_item', $data);
1392
  $data = apply_filters('wt_woocommerce_product_import_process_item_data', $data);
1393
+
1394
  // Get product ID from SKU if created during the importation.
1395
  if (empty($data['id']) && !empty($data['sku'])) {
1396
  $product_id = wc_get_product_id_by_sku($data['sku']);
1452
 
1453
  $this->set_meta_data($object, $data);
1454
  $this->set_other_taxonomy_data($object, $data);
1455
+
1456
  $object = apply_filters('wt_woocommerce_product_import_pre_insert_product_object', $object, $data);
1457
 
1458
  $object->save();
1459
 
1460
+ /*
1461
+ * WPML
1462
+ */
1463
+ $translation_post_details = array();
1464
+ if (isset($data['wpml']) && !empty($data['wpml'])) {
1465
+ foreach ($data['wpml'] as $meta) {
1466
+ $key = apply_filters('wt_wpml_import_post_meta_key', $meta['key']);
1467
+ if ($key == 'original_product_id' || $key == 'original_product_sku' || $key == 'language_code') {
1468
+ $translation_post_details[$key] = $meta['value'];
1469
+ }
1470
+ }
1471
+ $translation_post_details['current_post_id'] = $object->get_id();
1472
+ }
1473
+ if ((!empty($translation_post_details['original_product_id']) || !empty($translation_post_details['original_product_sku'])) && !empty($translation_post_details['language_code'])) {
1474
+ $this->wt_wpml_element_connect_on_insert($translation_post_details);
1475
+ }
1476
+
1477
+ if($this->delete_existing){
1478
  update_post_meta($object->get_id(), '_wt_delete_existing', 1);
1479
  }
1480
 
1634
  $default_attributes = array();
1635
  $existing_attributes = $product->get_attributes();
1636
 
1637
+ if(isset($existing_attributes)){
1638
+ foreach ($existing_attributes as $key => $existing_attribute) {
1639
+ $attributes[] = $existing_attribute;
1640
+ }
1641
+ }
1642
+
1643
  foreach ($data['raw_attributes'] as $position => $attribute) {
1644
  $attribute_id = 0;
1645
 
1710
  $attributes[] = $attribute_object;
1711
  }
1712
  }
1713
+
 
 
 
 
 
 
1714
  $product->set_attributes($attributes);
1715
 
1716
  }
1886
  }
1887
  }
1888
 
1889
+ /**
1890
+ * WPML compatibility
1891
+ */
1892
+ public function wt_wpml_element_connect_on_insert($translation_post_details) {
1893
+ if ($translation_post_details) {
1894
+ // https://wpml.org/wpml-hook/wpml_element_type/
1895
+ $wpml_element_type = apply_filters('wpml_element_type', 'post_product');
1896
+
1897
+ // get the language info of the original post
1898
+ // https://wpml.org/wpml-hook/wpml_element_language_details/
1899
+
1900
+ if (isset($translation_post_details['original_product_id']) && !empty($translation_post_details['original_product_id']))
1901
+ $original_product = wc_get_product($translation_post_details['original_product_id']);
1902
+ $original_product_id = '';
1903
+ if (!empty($original_product) && is_object($original_product)) {
1904
+ $original_product_id = $translation_post_details['original_product_id'];
1905
+ }
1906
+ if (!$original_product_id && isset($translation_post_details['original_product_sku']) && !empty($translation_post_details['original_product_sku'])) {
1907
+ $original_product_id = wc_get_product_id_by_sku($translation_post_details['original_product_sku']);
1908
+ }
1909
+ if ($original_product_id) {
1910
+
1911
+ $original_post_language_info = self::wt_get_wpml_original_post_language_info($original_product_id);
1912
+
1913
+ $set_language_args = array(
1914
+ 'element_id' => $translation_post_details['current_post_id'],
1915
+ 'element_type' => $wpml_element_type,
1916
+ 'trid' => $original_post_language_info->trid,
1917
+ 'language_code' => $translation_post_details['language_code'],
1918
+ 'source_language_code' => $original_post_language_info->language_code
1919
+ );
1920
+
1921
+ do_action('wpml_set_element_language_details', $set_language_args);
1922
+ }
1923
+ }
1924
+ }
1925
+ /**
1926
+ * Get info like language code, parent product ID etc by product id.
1927
+ * @param int Product ID.
1928
+ * @return array/false.
1929
+ */
1930
+ public static function wt_get_wpml_original_post_language_info($element_id) {
1931
+ $get_language_args = array('element_id' => $element_id, 'element_type' => 'post_product');
1932
+ $original_post_language_info = apply_filters('wpml_element_language_details', null, $get_language_args);
1933
+ return $original_post_language_info;
1934
+ }
1935
+
1936
+ }
1937
  }
includes/class-wt-import-export-for-woo.php CHANGED
@@ -80,7 +80,7 @@ class Wt_Import_Export_For_Woo_Basic {
80
  if ( defined( 'WT_P_IEW_VERSION' ) ) {
81
  $this->version = WT_P_IEW_VERSION;
82
  } else {
83
- $this->version = '2.0.4';
84
  }
85
  $this->plugin_name = 'wt-import-export-for-woo-basic';
86
 
80
  if ( defined( 'WT_P_IEW_VERSION' ) ) {
81
  $this->version = WT_P_IEW_VERSION;
82
  } else {
83
+ $this->version = '2.0.5';
84
  }
85
  $this->plugin_name = 'wt-import-export-for-woo-basic';
86
 
product-import-export-for-woo.php CHANGED
@@ -5,7 +5,7 @@
5
  Description: Import and Export Products From and To your WooCommerce Store.
6
  Author: WebToffee
7
  Author URI: https://www.webtoffee.com/product/product-import-export-woocommerce/
8
- Version: 2.0.4
9
  WC tested up to: 5.5
10
  License: GPLv3
11
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
@@ -43,7 +43,7 @@ if ( !defined( 'WT_IEW_DEBUG_BASIC_TROUBLESHOOT' ) ) {
43
  * Start at version 1.0.0 and use SemVer - https://semver.org
44
  * Rename this for your plugin and update it as you release new versions.
45
  */
46
- define( 'WT_P_IEW_VERSION', '2.0.4' );
47
 
48
  /**
49
  * The code that runs during plugin activation.
@@ -117,6 +117,10 @@ register_deactivation_hook( __FILE__, 'deactivate_wt_import_export_for_woo_basic
117
  */
118
  require plugin_dir_path( __FILE__ ) . 'includes/class-wt-import-export-for-woo.php';
119
 
 
 
 
 
120
  /**
121
  * Begins execution of the plugin.
122
  *
5
  Description: Import and Export Products From and To your WooCommerce Store.
6
  Author: WebToffee
7
  Author URI: https://www.webtoffee.com/product/product-import-export-woocommerce/
8
+ Version: 2.0.5
9
  WC tested up to: 5.5
10
  License: GPLv3
11
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
43
  * Start at version 1.0.0 and use SemVer - https://semver.org
44
  * Rename this for your plugin and update it as you release new versions.
45
  */
46
+ define( 'WT_P_IEW_VERSION', '2.0.5' );
47
 
48
  /**
49
  * The code that runs during plugin activation.
117
  */
118
  require plugin_dir_path( __FILE__ ) . 'includes/class-wt-import-export-for-woo.php';
119
 
120
+ $advanced_settings = get_option('wt_iew_advanced_settings', array());
121
+ $ier_get_max_execution_time = (isset($advanced_settings['wt_iew_maximum_execution_time']) && $advanced_settings['wt_iew_maximum_execution_time'] != '') ? $advanced_settings['wt_iew_maximum_execution_time'] : ini_get('max_execution_time');
122
+ set_time_limit($ier_get_max_execution_time);
123
+
124
  /**
125
  * Begins execution of the plugin.
126
  *
readme.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: webtoffee
3
  Donate link: https://www.webtoffee.com/plugins/
4
  Tags: product export, product import, CSV import export, woocommerce, CSV, product, export, import, woocommerce product import, woocommerce import products, export woocommerce products, import products into woocommerce
5
  Requires at least: 3.0.1
6
- Tested up to: 5.7
7
  Requires PHP: 5.6
8
- Stable tag: 2.0.4
9
  License: GPLv3 or later
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
@@ -174,6 +174,10 @@ Yes. You can import grouped, affiliate/external products in addition to simple p
174
 
175
  == Changelog ==
176
 
 
 
 
 
177
  = 2.0.4 =
178
  * Tested OK with WC 5.5.
179
  * Added external/affiliate and grouped product support.
@@ -474,6 +478,6 @@ Yes. You can import grouped, affiliate/external products in addition to simple p
474
 
475
  == Upgrade Notice ==
476
 
477
- = 2.0.4 =
478
- * Tested OK with WC 5.5.
479
- * Added external/affiliate and grouped product support.
3
  Donate link: https://www.webtoffee.com/plugins/
4
  Tags: product export, product import, CSV import export, woocommerce, CSV, product, export, import, woocommerce product import, woocommerce import products, export woocommerce products, import products into woocommerce
5
  Requires at least: 3.0.1
6
+ Tested up to: 5.8
7
  Requires PHP: 5.6
8
+ Stable tag: 2.0.5
9
  License: GPLv3 or later
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
174
 
175
  == Changelog ==
176
 
177
+ = 2.0.5 =
178
+ * Tested OK with WP 5.8.
179
+ * Bug fix: Product attribute update issue.
180
+
181
  = 2.0.4 =
182
  * Tested OK with WC 5.5.
183
  * Added external/affiliate and grouped product support.
478
 
479
  == Upgrade Notice ==
480
 
481
+ = 2.0.5 =
482
+ * Tested OK with WP 5.8.
483
+ * Bug fix: Product attribute update issue.