Ecwid Ecommerce Shopping Cart - Version 6.8.9

Version Description

  • Dec 4, 2019 =
  • Several fixes and improvements for the "Import from WooCommerce" tool. If you import your products from WooCommerce to Ecwid, the import process now should work faster. We also added import of product sale prices from WooCommerce import "Sale Price". In the storefront, this price will be struck out to demonstrate the discount and the ON SALE label will appear on the product.
  • Avada, SimplyNews, Twenty Twenty themes improved compatibility. Even though Ecwid is compatible with every WordPress theme by design, some slight fixes and improvements are sometimes needed to make storefront look better. Thats why we are always monitoring how Ecwid pages look and behave in WordPress ecommerce themes.
  • Minor fixes and improvements.
Download this release

Release Info

Developer Ecwid
Plugin Icon 128x128 Ecwid Ecommerce Shopping Cart
Version 6.8.9
Comparing to
See all releases

Code changes from version 6.8.8 to 6.8.9

Files changed (33) hide show
  1. css/admin.css +1 -0
  2. css/frontend.css +3 -0
  3. css/themes/twentytwenty.css +1 -2
  4. ecwid-shopping-cart.php +24 -14
  5. includes/class-ecwid-admin.php +1 -1
  6. includes/class-ecwid-message-manager.php +41 -3
  7. includes/class-ecwid-oauth.php +7 -7
  8. includes/class-ecwid-products.php +1 -1
  9. includes/class-ecwid-seo-links.php +2 -1
  10. includes/class-ecwid-static-page.php +16 -0
  11. includes/class-ecwid-well-known.php +117 -0
  12. includes/importer/class-ecwid-import-page.php +3 -3
  13. includes/importer/class-ecwid-import.php +1 -1
  14. includes/importer/class-ecwid-importer-task.php +2 -1
  15. includes/importer/class-ecwid-importer.php +84 -45
  16. includes/importer/task/class-ecwid-importer-task-batch-status.php +122 -0
  17. includes/importer/task/class-ecwid-importer-task-create-product-variation.php +6 -13
  18. includes/importer/task/class-ecwid-importer-task-create-product.php +17 -45
  19. includes/importer/task/class-ecwid-importer-task-import-woo-categories.php +1 -1
  20. includes/importer/task/class-ecwid-importer-task-import-woo-product.php +2 -8
  21. includes/importer/task/class-ecwid-importer-task-import-woo-products-batch.php +49 -5
  22. includes/importer/task/class-ecwid-importer-task-import-woo-products.php +1 -1
  23. includes/importer/task/class-ecwid-importer-task-upload-category-image.php +24 -6
  24. includes/importer/task/class-ecwid-importer-task-upload-product-gallery-image.php +24 -6
  25. includes/importer/task/class-ecwid-importer-task-upload-product-image.php +24 -8
  26. includes/importer/task/class-ecwid-importer-task-upload-product-variation-image.php +24 -7
  27. includes/shortcodes/class-ecwid-shortcode-productbrowser.php +1 -1
  28. includes/themes/class-ecwid-theme-avada.php +4 -0
  29. lib/ecwid_api_v3.php +125 -9
  30. readme.txt +7 -2
  31. templates/admin-message.php +1 -0
  32. templates/admin/simple-connect.tpl.php +4 -1
  33. templates/debug.php +2 -2
css/admin.css CHANGED
@@ -69,6 +69,7 @@
69
  }
70
 
71
  div.ecwid-message {
 
72
  padding: 27px 29px 20px 30px;
73
  display: block;
74
  }
69
  }
70
 
71
  div.ecwid-message {
72
+ margin-bottom: 15px;
73
  padding: 27px 29px 20px 30px;
74
  display: block;
75
  }
css/frontend.css CHANGED
@@ -79,6 +79,9 @@ html#ecwid_html body#ecwid_body .ecwid.ecwid-SingleProduct-v2.ecwid-random-produ
79
  min-height: 42px;
80
  }
81
 
 
 
 
82
  .hide-ec-dynamic-placeholder .ecwid-shopping-cart-product-browser {
83
  display: none;
84
  }
79
  min-height: 42px;
80
  }
81
 
82
+ #dynamic-ec-store {
83
+ width: 100%;
84
+ }
85
  .hide-ec-dynamic-placeholder .ecwid-shopping-cart-product-browser {
86
  display: none;
87
  }
css/themes/twentytwenty.css CHANGED
@@ -1,4 +1,3 @@
1
- html#ecwid_html body#ecwid_body .section-inner.thin,
2
- html#ecwid_html body#ecwid_body .entry-content {
3
  max-width: 120rem;
4
  }
1
+ #dynamic-ec-store, #static-ec-store {
 
2
  max-width: 120rem;
3
  }
ecwid-shopping-cart.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://www.ecwid.com?source=wporg
5
  Description: Ecwid is a free full-featured shopping cart. It can be easily integrated with any Wordpress blog and takes less than 5 minutes to set up.
6
  Text Domain: ecwid-shopping-cart
7
  Author: Ecwid Ecommerce
8
- Version: 6.8.8
9
  Author URI: https://ecwid.to/ecwid-site
10
  */
11
 
@@ -147,6 +147,8 @@ require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-seo-links.php';
147
  require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-html-meta.php';
148
  require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-wp-dashboard-feed.php';
149
 
 
 
150
  if (version_compare( phpversion(), '5.6', '>=' ) ) {
151
  require_once ECWID_PLUGIN_DIR . 'includes/importer/importer.php';
152
  }
@@ -607,7 +609,7 @@ function ecwid_backward_compatibility() {
607
  elseif (isset($_GET['ecwid_category_id']))
608
  $redirect = ecwid_get_category_url(intval($_GET['ecwid_category_id']));
609
 
610
- wp_redirect($redirect, 301);
611
  exit();
612
  }
613
  }
@@ -1026,6 +1028,8 @@ function ecwid_full_cache_reset()
1026
  EcwidPlatform::cache_reset( 'all_categories' );
1027
  EcwidPlatform::cache_reset( 'nav_categories_posts' );
1028
 
 
 
1029
  $p = new Ecwid_Products();
1030
  $p->reset_dates();
1031
 
@@ -1699,7 +1703,7 @@ function ecwid_plugin_activation_redirect( $plugin ) {
1699
  $is_newbie = ecwid_is_demo_store();
1700
 
1701
  if( $is_newbie && $plugin == plugin_basename( __FILE__ ) ) {
1702
- exit( wp_redirect( Ecwid_Admin::get_dashboard_url() ) );
1703
  }
1704
  }
1705
 
@@ -1793,6 +1797,8 @@ function ecwid_uninstall() {
1793
  delete_option("ecwid_plugin_version");
1794
  delete_option("ecwid_use_chameleon");
1795
  delete_option(Ecwid_Api_V3::TOKEN_OPTION_NAME);
 
 
1796
  }
1797
 
1798
  function ecwid_abs_intval($value) {
@@ -1942,7 +1948,8 @@ function ecwid_update_plugin_params()
1942
  update_option($name, $value);
1943
  }
1944
 
1945
- wp_redirect('admin.php?page=ec-params');
 
1946
  }
1947
 
1948
  function ecwid_get_clear_all_cache_action() {
@@ -1957,7 +1964,8 @@ function ecwid_clear_all_cache()
1957
  ecwid_full_cache_reset();
1958
 
1959
  if ( array_key_exists( 'redirect_back', $_GET ) ) {
1960
- wp_redirect ( 'admin.php?page=ec-params' );
 
1961
  }
1962
  }
1963
  }
@@ -2214,7 +2222,7 @@ function ecwid_create_store() {
2214
  ecwid_update_store_id($data->id);
2215
 
2216
  $api->save_token( $data->token );
2217
- update_option( 'ecwid_oauth_scope', 'read_profile ' . Ecwid_OAuth::SCOPE_READ_CATALOG . ' allow_sso create_customers public_storefront' );
2218
 
2219
  header( 'HTTP/1.1 200 OK' );
2220
 
@@ -2233,7 +2241,8 @@ function ecwid_do_sso_redirect() {
2233
 
2234
  $url = ecwid_get_admin_sso_url( time() );
2235
 
2236
- wp_redirect( $url );
 
2237
  }
2238
 
2239
  function ecwid_get_admin_sso_url( $time, $page = '' ) {
@@ -2434,8 +2443,8 @@ function ecwid_admin_post_connect()
2434
  update_option('ecwid_is_api_enabled', 'off');
2435
  update_option('ecwid_api_check_time', 0);
2436
  update_option('ecwid_last_oauth_fail_time', 1);
2437
- wp_redirect( Ecwid_Admin::get_dashboard_url() );
2438
- exit;
2439
  }
2440
  global $ecwid_oauth;
2441
 
@@ -2448,11 +2457,11 @@ function ecwid_admin_post_connect()
2448
  wp_redirect( $ecwid_oauth->get_auth_dialog_url() );
2449
  }
2450
  } else if (!isset($_GET['reconnect'])) {
2451
- wp_redirect(Ecwid_Admin::get_dashboard_url() . '&oauth=no');
2452
  } else {
2453
- wp_redirect(Ecwid_Admin::get_dashboard_url() . '&reconnect&connection_error');
2454
  }
2455
- exit;
2456
  }
2457
 
2458
  function ecwid_test_oauth($force = false)
@@ -2627,7 +2636,7 @@ function ecwid_sync_products() {
2627
  echo 'OK';
2628
  wp_die();
2629
  } else {
2630
- wp_redirect(Ecwid_Admin::get_dashboard_url() . '-advanced');
2631
  }
2632
  }
2633
 
@@ -2715,7 +2724,8 @@ function ecwid_sync_reset()
2715
  EcwidPlatform::set(Ecwid_Products_Sync_Status::OPTION_LAST_PRODUCT_UPDATE_TIME, 0);
2716
  EcwidPlatform::set(Ecwid_Products_Sync_Status::OPTION_LAST_PRODUCT_DELETE_TIME, 0);
2717
 
2718
- wp_redirect( Ecwid_Admin::get_dashboard_url() . '-advanced' );
 
2719
  }
2720
 
2721
  add_action('admin_post_ecwid_sync_no_sse', 'ecwid_sync_products_no_sse');
5
  Description: Ecwid is a free full-featured shopping cart. It can be easily integrated with any Wordpress blog and takes less than 5 minutes to set up.
6
  Text Domain: ecwid-shopping-cart
7
  Author: Ecwid Ecommerce
8
+ Version: 6.8.9
9
  Author URI: https://ecwid.to/ecwid-site
10
  */
11
 
147
  require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-html-meta.php';
148
  require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-wp-dashboard-feed.php';
149
 
150
+ require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-well-known.php';
151
+
152
  if (version_compare( phpversion(), '5.6', '>=' ) ) {
153
  require_once ECWID_PLUGIN_DIR . 'includes/importer/importer.php';
154
  }
609
  elseif (isset($_GET['ecwid_category_id']))
610
  $redirect = ecwid_get_category_url(intval($_GET['ecwid_category_id']));
611
 
612
+ wp_safe_redirect($redirect, 301);
613
  exit();
614
  }
615
  }
1028
  EcwidPlatform::cache_reset( 'all_categories' );
1029
  EcwidPlatform::cache_reset( 'nav_categories_posts' );
1030
 
1031
+ Ecwid_Static_Page::clear_all_cache();
1032
+
1033
  $p = new Ecwid_Products();
1034
  $p->reset_dates();
1035
 
1703
  $is_newbie = ecwid_is_demo_store();
1704
 
1705
  if( $is_newbie && $plugin == plugin_basename( __FILE__ ) ) {
1706
+ exit( wp_safe_redirect( Ecwid_Admin::get_dashboard_url() ) );
1707
  }
1708
  }
1709
 
1797
  delete_option("ecwid_plugin_version");
1798
  delete_option("ecwid_use_chameleon");
1799
  delete_option(Ecwid_Api_V3::TOKEN_OPTION_NAME);
1800
+
1801
+ EcwidPlatform::cache_reset('need_add_rewrite');
1802
  }
1803
 
1804
  function ecwid_abs_intval($value) {
1948
  update_option($name, $value);
1949
  }
1950
 
1951
+ wp_safe_redirect('admin.php?page=ec-params');
1952
+ exit();
1953
  }
1954
 
1955
  function ecwid_get_clear_all_cache_action() {
1964
  ecwid_full_cache_reset();
1965
 
1966
  if ( array_key_exists( 'redirect_back', $_GET ) ) {
1967
+ wp_safe_redirect ( 'admin.php?page=ec-params' );
1968
+ exit();
1969
  }
1970
  }
1971
  }
2222
  ecwid_update_store_id($data->id);
2223
 
2224
  $api->save_token( $data->token );
2225
+ update_option( 'ecwid_oauth_scope', 'read_profile ' . Ecwid_OAuth::SCOPE_READ_CATALOG . ' create_catalog update_catalog allow_sso create_customers public_storefront' );
2226
 
2227
  header( 'HTTP/1.1 200 OK' );
2228
 
2241
 
2242
  $url = ecwid_get_admin_sso_url( time() );
2243
 
2244
+ wp_redirect( $url );
2245
+ exit();
2246
  }
2247
 
2248
  function ecwid_get_admin_sso_url( $time, $page = '' ) {
2443
  update_option('ecwid_is_api_enabled', 'off');
2444
  update_option('ecwid_api_check_time', 0);
2445
  update_option('ecwid_last_oauth_fail_time', 1);
2446
+ wp_safe_redirect( Ecwid_Admin::get_dashboard_url() );
2447
+ exit();
2448
  }
2449
  global $ecwid_oauth;
2450
 
2457
  wp_redirect( $ecwid_oauth->get_auth_dialog_url() );
2458
  }
2459
  } else if (!isset($_GET['reconnect'])) {
2460
+ wp_safe_redirect(Ecwid_Admin::get_dashboard_url() . '&oauth=no');
2461
  } else {
2462
+ wp_safe_redirect(Ecwid_Admin::get_dashboard_url() . '&reconnect&connection_error');
2463
  }
2464
+ exit();
2465
  }
2466
 
2467
  function ecwid_test_oauth($force = false)
2636
  echo 'OK';
2637
  wp_die();
2638
  } else {
2639
+ wp_safe_redirect(Ecwid_Admin::get_dashboard_url() . '-advanced');
2640
  }
2641
  }
2642
 
2724
  EcwidPlatform::set(Ecwid_Products_Sync_Status::OPTION_LAST_PRODUCT_UPDATE_TIME, 0);
2725
  EcwidPlatform::set(Ecwid_Products_Sync_Status::OPTION_LAST_PRODUCT_DELETE_TIME, 0);
2726
 
2727
+ wp_safe_redirect( Ecwid_Admin::get_dashboard_url() . '-advanced' );
2728
+ exit();
2729
  }
2730
 
2731
  add_action('admin_post_ecwid_sync_no_sse', 'ecwid_sync_products_no_sse');
includes/class-ecwid-admin.php CHANGED
@@ -363,7 +363,7 @@ class Ecwid_Admin {
363
 
364
  $page = str_replace('admin_page_ecwid', Ecwid_Admin::ADMIN_SLUG, $base );
365
 
366
- wp_redirect( admin_url('admin.php?page=' . $page ), 301 );
367
  exit();
368
  }
369
 
363
 
364
  $page = str_replace('admin_page_ecwid', Ecwid_Admin::ADMIN_SLUG, $base );
365
 
366
+ wp_safe_redirect( admin_url('admin.php?page=' . $page ), 301 );
367
  exit();
368
  }
369
 
includes/class-ecwid-message-manager.php CHANGED
@@ -92,12 +92,48 @@ TXT
92
 
93
  $do_not_show_again = true == $params['hideable'];
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  include ECWID_PLUGIN_DIR . 'templates/admin-message.php';
96
  }
97
 
98
  public static function disable_message($name)
99
  {
100
  $messages = get_option('ecwid_disabled_messages');
 
 
 
 
 
101
  $messages[$name] = true;
102
 
103
  update_option('ecwid_disabled_messages', $messages);
@@ -106,8 +142,9 @@ TXT
106
  public static function enable_message($name)
107
  {
108
  $messages = get_option('ecwid_disabled_messages');
109
- if (isset($messages['name']))
110
  unset($messages['name']);
 
111
 
112
  update_option('ecwid_disabled_messages', $messages);
113
  }
@@ -143,7 +180,7 @@ TXT
143
 
144
  $hidden_messages = get_option('ecwid_disabled_messages');
145
 
146
- if ( !empty( $hidden_messages ) ) {
147
  foreach ($hidden_messages as $name => $message) {
148
  unset ($this->messages[$name]);
149
  }
@@ -353,10 +390,11 @@ HTML
353
  if ( !class_exists( 'Ecwid_Importer' ) ) {
354
  require_once ECWID_PLUGIN_DIR . 'includes/importer/class-ecwid-importer.php';
355
  }
356
-
357
  return
358
  is_plugin_active( 'woocommerce/woocommerce.php' )
359
  && strpos( $admin_page, Ecwid_Import::PAGE_SLUG ) === false
 
360
  && !$this->need_to_show_message( 'on_activate' )
361
  && Ecwid_Api_V3::is_available()
362
  && !ecwid_is_demo_store()
92
 
93
  $do_not_show_again = true == $params['hideable'];
94
 
95
+
96
+ //TO-DO: delete this block
97
+ $debug = EcwidPlatform::cache_get( 'temporary_debug', null );
98
+ if( $name == 'api_failed_other' && is_null($debug) ) {
99
+
100
+ $api_url = 'https://' . Ecwid_Config::get_api_domain() . '/api/v3/';
101
+ $api_profile_url = $api_url . get_ecwid_store_id() . '/profile?token=' . Ecwid_Api_V3::get_token();
102
+
103
+ $api_v3_profile_results = wp_remote_get(
104
+ $api_profile_url,
105
+ array('timeout' => 5)
106
+ );
107
+
108
+ if( is_wp_error($api_v3_profile_results) ) {
109
+ $error = $api_v3_profile_results->get_error_message();
110
+
111
+ preg_match( '/cURL error ([0-9]+):/i', $error, $m );
112
+
113
+ $script_js = sprintf(
114
+ '<script src="https://%s/script.js?%s&data_platform=wporg&data_wp_error=%s"></script>',
115
+ Ecwid_Config::get_scriptjs_domain(),
116
+ get_ecwid_store_id(),
117
+ $m[1]
118
+ );
119
+
120
+ $message .= $script_js;
121
+
122
+ EcwidPlatform::cache_set( 'temporary_debug', 1, WEEK_IN_SECONDS );
123
+ }
124
+ }
125
+
126
  include ECWID_PLUGIN_DIR . 'templates/admin-message.php';
127
  }
128
 
129
  public static function disable_message($name)
130
  {
131
  $messages = get_option('ecwid_disabled_messages');
132
+
133
+ if( !is_array($messages) ) {
134
+ $messages = array();
135
+ }
136
+
137
  $messages[$name] = true;
138
 
139
  update_option('ecwid_disabled_messages', $messages);
142
  public static function enable_message($name)
143
  {
144
  $messages = get_option('ecwid_disabled_messages');
145
+ if (isset($messages['name'])) {
146
  unset($messages['name']);
147
+ }
148
 
149
  update_option('ecwid_disabled_messages', $messages);
150
  }
180
 
181
  $hidden_messages = get_option('ecwid_disabled_messages');
182
 
183
+ if ( !empty( $hidden_messages ) && is_array( $hidden_messages ) ) {
184
  foreach ($hidden_messages as $name => $message) {
185
  unset ($this->messages[$name]);
186
  }
390
  if ( !class_exists( 'Ecwid_Importer' ) ) {
391
  require_once ECWID_PLUGIN_DIR . 'includes/importer/class-ecwid-importer.php';
392
  }
393
+
394
  return
395
  is_plugin_active( 'woocommerce/woocommerce.php' )
396
  && strpos( $admin_page, Ecwid_Import::PAGE_SLUG ) === false
397
+ && $_GET['import'] != 'ec-store-import'
398
  && !$this->need_to_show_message( 'on_activate' )
399
  && Ecwid_Api_V3::is_available()
400
  && !ecwid_is_demo_store()
includes/class-ecwid-oauth.php CHANGED
@@ -88,7 +88,7 @@ class Ecwid_OAuth {
88
  $this->update_state(array('mode' => self::MODE_CONNECT, 'error' => 'cancelled'));
89
  }
90
 
91
- wp_redirect( Ecwid_Admin::get_dashboard_url() . '&connection_error' . ($reconnect ? '&reconnect' : ''));
92
  exit;
93
  }
94
 
@@ -133,9 +133,9 @@ class Ecwid_OAuth {
133
  Ecwid_Api_V3::reset_api_status();
134
 
135
  $this->api->save_token($result->access_token);
136
-
137
  if ( isset( $this->state->return_url ) && !empty( $this->state->return_url ) ) {
138
- wp_redirect( admin_url( $this->state->return_url ) );
139
  } else {
140
  $url = '';
141
  if ($reconnect) {
@@ -143,7 +143,7 @@ class Ecwid_OAuth {
143
  } else {
144
  $url = Ecwid_Admin::get_dashboard_url();
145
  }
146
- wp_redirect( $url );
147
  }
148
  exit;
149
  }
@@ -155,7 +155,7 @@ class Ecwid_OAuth {
155
  update_option( 'ecwid_is_api_enabled', 'off' );
156
  update_option( 'ecwid_api_check_time', 0 );
157
 
158
- wp_redirect( Ecwid_Admin::get_dashboard_url() );
159
  exit;
160
  }
161
 
@@ -245,8 +245,8 @@ class Ecwid_OAuth {
245
  EcwidPlatform::report_error($last_error);
246
  }
247
 
248
- wp_redirect( Ecwid_Admin::get_dashboard_url() . '&connection_error' . ( $mode == self::MODE_RECONNECT ? '&reconnect' : '' ) );
249
- exit;
250
  }
251
 
252
  protected function _get_scope() {
88
  $this->update_state(array('mode' => self::MODE_CONNECT, 'error' => 'cancelled'));
89
  }
90
 
91
+ wp_safe_redirect( Ecwid_Admin::get_dashboard_url() . '&connection_error' . ($reconnect ? '&reconnect' : ''));
92
  exit;
93
  }
94
 
133
  Ecwid_Api_V3::reset_api_status();
134
 
135
  $this->api->save_token($result->access_token);
136
+
137
  if ( isset( $this->state->return_url ) && !empty( $this->state->return_url ) ) {
138
+ wp_safe_redirect( admin_url( $this->state->return_url ) );
139
  } else {
140
  $url = '';
141
  if ($reconnect) {
143
  } else {
144
  $url = Ecwid_Admin::get_dashboard_url();
145
  }
146
+ wp_safe_redirect( $url );
147
  }
148
  exit;
149
  }
155
  update_option( 'ecwid_is_api_enabled', 'off' );
156
  update_option( 'ecwid_api_check_time', 0 );
157
 
158
+ wp_safe_redirect( Ecwid_Admin::get_dashboard_url() );
159
  exit;
160
  }
161
 
245
  EcwidPlatform::report_error($last_error);
246
  }
247
 
248
+ wp_safe_redirect( Ecwid_Admin::get_dashboard_url() . '&connection_error' . ( $mode == self::MODE_RECONNECT ? '&reconnect' : '' ) );
249
+ exit();
250
  }
251
 
252
  protected function _get_scope() {
includes/class-ecwid-products.php CHANGED
@@ -78,7 +78,7 @@ class Ecwid_Products {
78
  $url = $this->_get_post_link($post->ID);
79
 
80
  if ($url) {
81
- wp_redirect($url, 301);
82
  exit();
83
  }
84
  }
78
  $url = $this->_get_post_link($post->ID);
79
 
80
  if ($url) {
81
+ wp_safe_redirect($url, 301);
82
  exit();
83
  }
84
  }
includes/class-ecwid-seo-links.php CHANGED
@@ -110,7 +110,8 @@ class Ecwid_Seo_Links {
110
  }
111
 
112
  if ($redirect) {
113
- wp_redirect( $redirect, 301 );
 
114
  }
115
  }
116
  }
110
  }
111
 
112
  if ($redirect) {
113
+ wp_safe_redirect( $redirect, 301 );
114
+ exit;
115
  }
116
  }
117
  }
includes/class-ecwid-static-page.php CHANGED
@@ -26,6 +26,10 @@ class Ecwid_Static_Page {
26
  if ( !self::is_enabled_static_home_page() ) {
27
  return null;
28
  }
 
 
 
 
29
 
30
  if( !self::is_data_available() ) {
31
  return null;
@@ -314,6 +318,18 @@ class Ecwid_Static_Page {
314
  return $api->is_store_feature_enabled( Ecwid_Api_V3::FEATURE_NEW_PRODUCT_LIST );
315
  }
316
 
 
 
 
 
 
 
 
 
 
 
 
 
317
  }
318
 
319
  $__ecwid_static_page = new Ecwid_Static_Page();
26
  if ( !self::is_enabled_static_home_page() ) {
27
  return null;
28
  }
29
+
30
+ if ( !Ecwid_Store_page::is_store_page() ) {
31
+ return null;
32
+ }
33
 
34
  if( !self::is_data_available() ) {
35
  return null;
318
  return $api->is_store_feature_enabled( Ecwid_Api_V3::FEATURE_NEW_PRODUCT_LIST );
319
  }
320
 
321
+ public static function clear_all_cache() {
322
+ global $wpdb;
323
+
324
+ $sql = "
325
+ DELETE
326
+ FROM {$wpdb->options}
327
+ WHERE option_name like '\_transient\_ecwid\_catalog\_%'
328
+ OR option_name like '\_transient\_timeout\_ecwid\_catalog\_%'
329
+ ";
330
+
331
+ $wpdb->query($sql);
332
+ }
333
  }
334
 
335
  $__ecwid_static_page = new Ecwid_Static_Page();
includes/class-ecwid-well-known.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ecwid_Well_Known {
4
+
5
+ public function __construct()
6
+ {
7
+ // rule for .well-known/* path
8
+ add_filter( 'query_vars', array( $this, 'query_vars' ) );
9
+ add_action( 'parse_request', array( $this, 'delegate_request' ), 1000 );
10
+ add_action( 'generate_rewrite_rules', array( $this, 'rewrite_rules' ), 1000 );
11
+
12
+ add_action( 'permalink_structure_changed', array( $this, 'save_mod_rewrite_rules' ) );
13
+
14
+ if( !Ecwid_Seo_Links::is_feature_available() ) {
15
+ add_action( 'init', array( $this, 'check_add_rewrite_rules' ) );
16
+ }
17
+
18
+ // Well-Known URIs
19
+ add_action( "ec_well_known_apple-developer-merchantid-domain-association", array($this, "apple_pay_verification" ) );
20
+ }
21
+
22
+ public function query_vars($vars) {
23
+ $vars[] = 'ec-well-known';
24
+ return $vars;
25
+ }
26
+
27
+ public function rewrite_rules($wp_rewrite) {
28
+ $well_known_rules = array(
29
+ '.well-known/(.+)' => 'index.php?ec-well-known='.$wp_rewrite->preg_index(1)
30
+ );
31
+ $wp_rewrite->rules = $well_known_rules + $wp_rewrite->rules;
32
+ }
33
+
34
+ public function delegate_request($wp) {
35
+ if( array_key_exists('ec-well-known', $wp->query_vars) ) {
36
+ $uri_suffix = str_replace( '/', '', $wp->query_vars['ec-well-known'] );
37
+
38
+ do_action( "ec_well_known", $wp->query_vars );
39
+ do_action( "ec_well_known_{$uri_suffix}", $wp->query_vars );
40
+ }
41
+ }
42
+
43
+ public function save_mod_rewrite_rules() {
44
+
45
+ if( !function_exists('get_home_path') ) {
46
+ require_once ( ABSPATH . 'wp-admin/includes/file.php' );
47
+ }
48
+
49
+ if( !function_exists('insert_with_markers') ) {
50
+ require_once ( ABSPATH . 'wp-admin/includes/misc.php' );
51
+ }
52
+
53
+ $brand = Ecwid_Config::get_brand();
54
+ $rules = array();
55
+ $home_path = get_home_path();
56
+ $htaccess_file = $home_path . '.htaccess';
57
+
58
+ if( !Ecwid_Seo_Links::is_feature_available() ) {
59
+ $rules[] = '<IfModule mod_rewrite.c>';
60
+ $rules[] = 'RewriteEngine On';
61
+ $rules[] = 'RewriteRule ^\.well-known/(.+)$ index.php?ec-well-known=$1 [L]';
62
+ $rules[] = '</IfModule>';
63
+ } else {
64
+ EcwidPlatform::cache_reset('need_add_rewrite');
65
+ }
66
+
67
+ insert_with_markers( $htaccess_file, $brand, $rules );
68
+ }
69
+
70
+ public function check_add_rewrite_rules(){
71
+ $need_add_rewrite = EcwidPlatform::cache_get( 'need_add_rewrite', null );
72
+
73
+ if ( is_null($need_add_rewrite) ) {
74
+ $this->save_mod_rewrite_rules();
75
+ EcwidPlatform::cache_set('need_add_rewrite', '1', WEEK_IN_SECONDS);
76
+ }
77
+ }
78
+
79
+ public function apple_pay_verification( $query_vars ) {
80
+ $api = new Ecwid_Api_V3();
81
+ $profile = $api->get_store_profile(true);
82
+
83
+ if( $profile && !empty($profile->payment->applePay->verificationFileUrl) ) {
84
+
85
+ $response = wp_remote_get(
86
+ $profile->payment->applePay->verificationFileUrl,
87
+ array(
88
+ 'timeout' => 60
89
+ )
90
+ );
91
+
92
+ $body = wp_remote_retrieve_body( $response );
93
+
94
+ if( !empty( $body ) ) {
95
+ echo $body;
96
+ } else {
97
+ $this->show_404();
98
+ }
99
+
100
+ exit();
101
+ } else {
102
+ $this->show_404();
103
+ }
104
+ }
105
+
106
+ public function show_404() {
107
+ global $wp_query;
108
+
109
+ $wp_query->set_404();
110
+ status_header( 404 );
111
+
112
+ exit();
113
+ }
114
+
115
+ }
116
+ $ecwid_well_know = new Ecwid_Well_Known();
117
+
includes/importer/class-ecwid-import-page.php CHANGED
@@ -140,10 +140,10 @@ class Ecwid_Import_Page
140
  $url .= '&' . $param . '=true';
141
  }
142
  }
143
-
144
- wp_redirect(
145
  'admin.php?page=' . Ecwid_Admin::ADMIN_SLUG
146
- . '&reconnect&return-url=' . urlencode( $url )
147
  . '&scope=create_catalog+update_catalog&do_reconnect=1'
148
  );
149
  }
140
  $url .= '&' . $param . '=true';
141
  }
142
  }
143
+
144
+ wp_safe_redirect(
145
  'admin.php?page=' . Ecwid_Admin::ADMIN_SLUG
146
+ . '&reconnect&return-url=' . urlencode( $url )
147
  . '&scope=create_catalog+update_catalog&do_reconnect=1'
148
  );
149
  }
includes/importer/class-ecwid-import.php CHANGED
@@ -49,7 +49,7 @@ class Ecwid_Import
49
 
50
  $api = new Ecwid_Api_V3();
51
 
52
- $ecwid_products = $api->get_products( array( 'limit' => '1' ) );
53
  $result['ecwid_total_products'] = $ecwid_products->total;
54
 
55
  $ecwid_categories = $api->get_categories(array('limit' => 1));
49
 
50
  $api = new Ecwid_Api_V3();
51
 
52
+ $ecwid_products = $api->get_products( array( 'limit' => 1 ) );
53
  $result['ecwid_total_products'] = $ecwid_products->total;
54
 
55
  $ecwid_categories = $api->get_categories(array('limit' => 1));
includes/importer/class-ecwid-importer-task.php CHANGED
@@ -50,7 +50,8 @@ abstract class Ecwid_Importer_Task
50
  'Import_Woo_Products',
51
  'Import_Woo_Products_Batch',
52
  'Import_Woo_Categories',
53
- 'Import_Woo_Product'
 
54
  );
55
 
56
  foreach ( $names as $name ) {
50
  'Import_Woo_Products',
51
  'Import_Woo_Products_Batch',
52
  'Import_Woo_Categories',
53
+ 'Import_Woo_Product',
54
+ 'Batch_Status'
55
  );
56
 
57
  foreach ( $names as $name ) {
includes/importer/class-ecwid-importer.php CHANGED
@@ -1,7 +1,5 @@
1
  <?php
2
-
3
  require_once dirname(__FILE__) . '/class-ecwid-importer-task.php';
4
-
5
  class Ecwid_Importer
6
  {
7
  const OPTION_TASKS = 'ecwid_importer_tasks';
@@ -17,12 +15,14 @@ class Ecwid_Importer
17
 
18
  const SETTING_UPDATE_BY_SKU = 'update-by-sku';
19
  const SETTING_DELETE_DEMO = 'delete-demo';
20
-
21
  const DEMO_CREATE_FROM = 1469707991;
22
  const DEMO_CREATE_TO = 1469710442;
23
 
24
  protected $_tasks;
25
  protected $_start_time;
 
 
 
26
 
27
  public function initiate( $settings = array() )
28
  {
@@ -30,11 +30,9 @@ class Ecwid_Importer
30
  update_option( self::OPTION_PRODUCTS, array() );
31
  update_option( self::OPTION_TASKS, array() );
32
  update_option( self::OPTION_STATUS, array() );
33
-
34
  $this->_start();
35
 
36
  $api = new Ecwid_Api_V3();
37
-
38
  $this->_set_settings( $settings );
39
  $this->_maybe_set_forced_settings();
40
  $this->_set_tasks(array());
@@ -51,21 +49,16 @@ class Ecwid_Importer
51
  $start = time();
52
 
53
  $status = get_option( self::OPTION_STATUS, array( 'plan_limit' => array() ) );
54
- $count = 0;
55
  $progress = array( 'success' => array(), 'error' => array(), 'total' => count($this->_tasks) );
56
-
57
  do {
58
  $current_task = $this->_get_current_task();
59
-
60
  $task_data = $this->_tasks[$current_task];
61
-
62
  if ( !isset( $status['plan_limit'] )
63
  || !is_array( $status['plan_limit'] )
64
  || !array_key_exists( $task_data['type'], $status['plan_limit'] )
65
  ) {
66
 
67
  $task = Ecwid_Importer_Task::load_task($task_data['type']);
68
-
69
  $result = $task->execute($this, $task_data);
70
 
71
  if ( $result['status'] == 'error' ) {
@@ -81,17 +74,13 @@ class Ecwid_Importer
81
  if ( is_wp_error( $error_data ) ) {
82
  $message = var_export( $result['data']->get_error_message(), true );
83
  } elseif ( is_array( $error_data ) ) {
84
-
85
  $message = @$error_data['response']['code'];
86
-
87
  if ( $error_data['response']['message'] ) {
88
  $message .= ' ' . $error_data['response']['message'];
89
  }
90
-
91
  if ( @$error_data['http_message'] ) {
92
  $message .= ' ' . $error_data['http_message'];
93
  }
94
-
95
  if ( @$error_data['api_message'] ) {
96
  $message .= ':' . $error_data['api_message'];
97
  }
@@ -99,17 +88,14 @@ class Ecwid_Importer
99
  if ( @$error_data['api_code'] ) {
100
  $message .= '(' . $error_data['api_code'] . ')';
101
  }
102
-
103
  } elseif ( @$error_data == 'skipped' ) {
104
  $message = $result['message'];
105
  }
106
 
107
  $this->_tasks[$current_task]['error'] = $message;
108
-
109
  if ( !isset( $progress['error_messages'][$task_data['type']] ) ) {
110
  $progress['error_messages'][$task_data['type']] = array();
111
  }
112
-
113
  if ( !isset( $progress['error_messages'][$task_data['type']][$message] ) ) {
114
  $progress['error_messages'][$task_data['type']][$message] = [];
115
  }
@@ -127,7 +113,7 @@ class Ecwid_Importer
127
 
128
  if ( $task instanceof Ecwid_Importer_Task_Create_Product_Variation || $task instanceof Ecwid_Importer_Task_Upload_Product_Variation_Image ) {
129
  $error_data['variation_id'] = $task_data['variation_id'];
130
- }
131
  } else {
132
  $error_data = $task_data;
133
  }
@@ -136,7 +122,6 @@ class Ecwid_Importer
136
  } else {
137
  $progress['success'][] = $task_data['type'];
138
  }
139
-
140
  update_option( self::OPTION_STATUS, $status );
141
  } else {
142
  $progress['error'][] = $task_data['type'];
@@ -150,7 +135,6 @@ class Ecwid_Importer
150
  }
151
 
152
  $this->_set_current_task( $current_task );
153
- $count++;
154
 
155
  $progress['current'] = $current_task;
156
  $progress['total'] = count( $this->_tasks );
@@ -158,13 +142,40 @@ class Ecwid_Importer
158
  $this->_set_tasks( $this->_tasks );
159
 
160
  if ( $start + self::TICK_LENGTH <= time() ) {
 
161
  $progress['status'] = 'in_progress';
162
- $progress['tasks'] = $this->_tasks;
163
-
164
- return $progress;
165
  }
166
  } while ( 1 );
167
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  $this->_set_tasks( null );
169
 
170
  $progress['status'] = 'complete';
@@ -174,20 +185,63 @@ class Ecwid_Importer
174
  return $progress;
175
  }
176
 
177
- public function append_task( $task ) {
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  $this->_tasks[] = $task;
180
 
181
  return count( $this->_tasks ) - 1;
182
  //array_splice( $this->_tasks, (int)$this->_get_current_task() + 1, 0, array( $task ) );
183
  }
184
 
185
- /**
186
- * Appends $task as a child of current task. It skips current task, skips all task with the same type
187
- * and appends $task after all its siblings
188
- *
189
- * @param $task
190
- */
191
  /**
192
  * Appends $task as a child of current task. It skips current task, skips all task with the same type
193
  * and appends $task after all its siblings
@@ -196,20 +250,15 @@ class Ecwid_Importer
196
  */
197
  public function append_child( $task ) {
198
  $ind = $this->_get_current_task();
199
-
200
  $this_task = $this->_tasks[$ind];
201
-
202
  $ind++;
203
  while ( isset( $this->_tasks[$ind] ) && ( $this->_tasks[$ind]['type'] == $task['type'] || $this->_tasks[$ind]['type'] == $this_task['type'] ) ) {
204
  $ind++;
205
  }
206
-
207
  return $this->append_after( $task, $ind - 1 );
208
  }
209
-
210
  public function append_after( $task, $index ) {
211
  array_splice( $this->_tasks, $index + 1, 0, array( $task ) );
212
-
213
  return $index + 1;
214
  }
215
 
@@ -251,7 +300,6 @@ class Ecwid_Importer
251
  public function save_ecwid_category( $woo_category_id, $ecwid_category_id )
252
  {
253
  $categories = get_option( self::OPTION_CATEGORIES, array() );
254
-
255
  $categories[$woo_category_id] = $ecwid_category_id;
256
 
257
  update_option(self::OPTION_CATEGORIES, $categories );
@@ -259,16 +307,12 @@ class Ecwid_Importer
259
 
260
  public function get_ecwid_product_id( $woo_product_id ) {
261
  $products = get_option( self::OPTION_PRODUCTS, array() );
262
-
263
  return @$products[$woo_product_id];
264
  }
265
-
266
  public function save_ecwid_product_id( $woo_product_id, $ecwid_product_id )
267
  {
268
  $products = get_option( self::OPTION_PRODUCTS, array() );
269
-
270
  $products[$woo_product_id] = $ecwid_product_id;
271
-
272
  update_option(self::OPTION_PRODUCTS, $products );
273
  }
274
 
@@ -309,7 +353,6 @@ class Ecwid_Importer
309
 
310
  public function get_setting( $name ) {
311
  $settings = get_option( self::OPTION_SETTINGS, array() );
312
-
313
  return @$settings[$name];
314
  }
315
 
@@ -380,14 +423,12 @@ class Ecwid_Importer
380
  public static function count_woo_products()
381
  {
382
  $count = wp_count_posts( 'product' );
383
-
384
  return $count->publish;
385
  }
386
 
387
  public static function count_ecwid_products()
388
  {
389
  $api = new Ecwid_Api_V3();
390
-
391
  $max = 100;
392
  $ecwid_products = $api->get_products( array( 'limit' => $max ) );
393
 
@@ -408,7 +449,6 @@ class Ecwid_Importer
408
  public static function count_ecwid_categories()
409
  {
410
  $api = new Ecwid_Api_V3();
411
-
412
  $ecwid_categories = $api->get_categories( array( 'limit' => 1 ) );
413
  return $ecwid_categories->total;
414
  }
@@ -460,7 +500,6 @@ class Ecwid_Importer
460
  );
461
  }
462
  }
463
-
464
  return $result;
465
  }
466
 
1
  <?php
 
2
  require_once dirname(__FILE__) . '/class-ecwid-importer-task.php';
 
3
  class Ecwid_Importer
4
  {
5
  const OPTION_TASKS = 'ecwid_importer_tasks';
15
 
16
  const SETTING_UPDATE_BY_SKU = 'update-by-sku';
17
  const SETTING_DELETE_DEMO = 'delete-demo';
 
18
  const DEMO_CREATE_FROM = 1469707991;
19
  const DEMO_CREATE_TO = 1469710442;
20
 
21
  protected $_tasks;
22
  protected $_start_time;
23
+
24
+ public $_batch;
25
+ public $_batch_progress;
26
 
27
  public function initiate( $settings = array() )
28
  {
30
  update_option( self::OPTION_PRODUCTS, array() );
31
  update_option( self::OPTION_TASKS, array() );
32
  update_option( self::OPTION_STATUS, array() );
 
33
  $this->_start();
34
 
35
  $api = new Ecwid_Api_V3();
 
36
  $this->_set_settings( $settings );
37
  $this->_maybe_set_forced_settings();
38
  $this->_set_tasks(array());
49
  $start = time();
50
 
51
  $status = get_option( self::OPTION_STATUS, array( 'plan_limit' => array() ) );
 
52
  $progress = array( 'success' => array(), 'error' => array(), 'total' => count($this->_tasks) );
 
53
  do {
54
  $current_task = $this->_get_current_task();
 
55
  $task_data = $this->_tasks[$current_task];
 
56
  if ( !isset( $status['plan_limit'] )
57
  || !is_array( $status['plan_limit'] )
58
  || !array_key_exists( $task_data['type'], $status['plan_limit'] )
59
  ) {
60
 
61
  $task = Ecwid_Importer_Task::load_task($task_data['type']);
 
62
  $result = $task->execute($this, $task_data);
63
 
64
  if ( $result['status'] == 'error' ) {
74
  if ( is_wp_error( $error_data ) ) {
75
  $message = var_export( $result['data']->get_error_message(), true );
76
  } elseif ( is_array( $error_data ) ) {
 
77
  $message = @$error_data['response']['code'];
 
78
  if ( $error_data['response']['message'] ) {
79
  $message .= ' ' . $error_data['response']['message'];
80
  }
 
81
  if ( @$error_data['http_message'] ) {
82
  $message .= ' ' . $error_data['http_message'];
83
  }
 
84
  if ( @$error_data['api_message'] ) {
85
  $message .= ':' . $error_data['api_message'];
86
  }
88
  if ( @$error_data['api_code'] ) {
89
  $message .= '(' . $error_data['api_code'] . ')';
90
  }
 
91
  } elseif ( @$error_data == 'skipped' ) {
92
  $message = $result['message'];
93
  }
94
 
95
  $this->_tasks[$current_task]['error'] = $message;
 
96
  if ( !isset( $progress['error_messages'][$task_data['type']] ) ) {
97
  $progress['error_messages'][$task_data['type']] = array();
98
  }
 
99
  if ( !isset( $progress['error_messages'][$task_data['type']][$message] ) ) {
100
  $progress['error_messages'][$task_data['type']][$message] = [];
101
  }
113
 
114
  if ( $task instanceof Ecwid_Importer_Task_Create_Product_Variation || $task instanceof Ecwid_Importer_Task_Upload_Product_Variation_Image ) {
115
  $error_data['variation_id'] = $task_data['variation_id'];
116
+ }
117
  } else {
118
  $error_data = $task_data;
119
  }
122
  } else {
123
  $progress['success'][] = $task_data['type'];
124
  }
 
125
  update_option( self::OPTION_STATUS, $status );
126
  } else {
127
  $progress['error'][] = $task_data['type'];
135
  }
136
 
137
  $this->_set_current_task( $current_task );
 
138
 
139
  $progress['current'] = $current_task;
140
  $progress['total'] = count( $this->_tasks );
142
  $this->_set_tasks( $this->_tasks );
143
 
144
  if ( $start + self::TICK_LENGTH <= time() ) {
145
+
146
  $progress['status'] = 'in_progress';
147
+ break;
 
 
148
  }
149
  } while ( 1 );
150
 
151
+ if( count($this->get_batch()) ) {
152
+ if( $this->execute_batch() ) {
153
+ $this->_set_tasks( $this->_tasks );
154
+ $progress['status'] = 'in_progress';
155
+ }
156
+ }
157
+
158
+ if( is_array( $this->_batch_progress ) ) {
159
+ if( isset($this->_batch_progress['success']) ) {
160
+ $progress['success'] = array_merge( $progress['success'], $this->_batch_progress['success'] );
161
+ }
162
+ if( isset($this->_batch_progress['error']) ) {
163
+ $progress['error'] = array_merge( $progress['error'], $this->_batch_progress['error'] );
164
+ }
165
+ if( isset($this->_batch_progress['error_messages']) ) {
166
+ if( !isset($progress['error_messages']) ) {
167
+ $progress['error_messages'] = $this->_batch_progress['error_messages'];
168
+ } else {
169
+ $progress['error_messages'] = array_merge( $progress['error_messages'], $this->_batch_progress['error_messages'] );
170
+ }
171
+ }
172
+ }
173
+
174
+ if( $progress['status'] == 'in_progress' ) {
175
+ $progress['tasks'] = $this->_tasks;
176
+ return $progress;
177
+ }
178
+
179
  $this->_set_tasks( null );
180
 
181
  $progress['status'] = 'complete';
185
  return $progress;
186
  }
187
 
 
188
 
189
+ public function append_batch( $batch_item ) {
190
+ $this->_batch[] = $batch_item;
191
+
192
+ return count( $this->_batch ) - 1;
193
+ }
194
+
195
+ public function get_batch() {
196
+
197
+ if( !is_array($this->_batch) ) {
198
+ $this->clear_batch();
199
+ }
200
+
201
+ return $this->_batch;
202
+ }
203
+
204
+ public function clear_batch() {
205
+ $this->_batch = array();
206
+ }
207
+
208
+ public function execute_batch() {
209
+
210
+ $batch = $this->get_batch();
211
+
212
+ $api = new Ecwid_Api_V3();
213
+ $result = $api->create_batch( $batch );
214
+
215
+ if( $result['response']['code'] == '200' ) {
216
+
217
+ $data = json_decode( $result['body'] );
218
+ $ticket = $data->ticket;
219
+
220
+ $this->append_task(
221
+ Ecwid_Importer_Task_Batch_Status::build(
222
+ array( 'ticket' => $ticket )
223
+ )
224
+ );
225
+
226
+ $this->clear_batch();
227
+
228
+ return true;
229
+ }
230
+
231
+ return false;
232
+ }
233
+
234
+ public static function is_localhost() {
235
+ return in_array( $_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1') );
236
+ }
237
+
238
+ public function append_task( $task ) {
239
  $this->_tasks[] = $task;
240
 
241
  return count( $this->_tasks ) - 1;
242
  //array_splice( $this->_tasks, (int)$this->_get_current_task() + 1, 0, array( $task ) );
243
  }
244
 
 
 
 
 
 
 
245
  /**
246
  * Appends $task as a child of current task. It skips current task, skips all task with the same type
247
  * and appends $task after all its siblings
250
  */
251
  public function append_child( $task ) {
252
  $ind = $this->_get_current_task();
 
253
  $this_task = $this->_tasks[$ind];
 
254
  $ind++;
255
  while ( isset( $this->_tasks[$ind] ) && ( $this->_tasks[$ind]['type'] == $task['type'] || $this->_tasks[$ind]['type'] == $this_task['type'] ) ) {
256
  $ind++;
257
  }
 
258
  return $this->append_after( $task, $ind - 1 );
259
  }
 
260
  public function append_after( $task, $index ) {
261
  array_splice( $this->_tasks, $index + 1, 0, array( $task ) );
 
262
  return $index + 1;
263
  }
264
 
300
  public function save_ecwid_category( $woo_category_id, $ecwid_category_id )
301
  {
302
  $categories = get_option( self::OPTION_CATEGORIES, array() );
 
303
  $categories[$woo_category_id] = $ecwid_category_id;
304
 
305
  update_option(self::OPTION_CATEGORIES, $categories );
307
 
308
  public function get_ecwid_product_id( $woo_product_id ) {
309
  $products = get_option( self::OPTION_PRODUCTS, array() );
 
310
  return @$products[$woo_product_id];
311
  }
 
312
  public function save_ecwid_product_id( $woo_product_id, $ecwid_product_id )
313
  {
314
  $products = get_option( self::OPTION_PRODUCTS, array() );
 
315
  $products[$woo_product_id] = $ecwid_product_id;
 
316
  update_option(self::OPTION_PRODUCTS, $products );
317
  }
318
 
353
 
354
  public function get_setting( $name ) {
355
  $settings = get_option( self::OPTION_SETTINGS, array() );
 
356
  return @$settings[$name];
357
  }
358
 
423
  public static function count_woo_products()
424
  {
425
  $count = wp_count_posts( 'product' );
 
426
  return $count->publish;
427
  }
428
 
429
  public static function count_ecwid_products()
430
  {
431
  $api = new Ecwid_Api_V3();
 
432
  $max = 100;
433
  $ecwid_products = $api->get_products( array( 'limit' => $max ) );
434
 
449
  public static function count_ecwid_categories()
450
  {
451
  $api = new Ecwid_Api_V3();
 
452
  $ecwid_categories = $api->get_categories( array( 'limit' => 1 ) );
453
  return $ecwid_categories->total;
454
  }
500
  );
501
  }
502
  }
 
503
  return $result;
504
  }
505
 
includes/importer/task/class-ecwid-importer-task-batch-status.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ecwid_Importer_Task_Batch_Status extends Ecwid_Importer_Task_Product_Base
4
+ {
5
+ public static $type = 'batch_status';
6
+
7
+ const STATUS_QUEUED = 'QUEUED';
8
+ const STATUS_IN_PROGRESS = 'IN_PROGRESS';
9
+ const STATUS_COMPLETED = 'COMPLETED';
10
+ const STATUS_FAILED = 'FAILED';
11
+
12
+ public function execute( Ecwid_Importer $exporter, array $task_data ) {
13
+
14
+ $ticket = $task_data['ticket'];
15
+
16
+ $api = new Ecwid_Api_V3();
17
+
18
+ $result = $api->get_batch_status( $ticket );
19
+
20
+ $batch = json_decode( $result['data'] );
21
+
22
+ if ( $batch->status != self::STATUS_COMPLETED ) {
23
+ $exporter->append_task(
24
+ $this->build(
25
+ array(
26
+ 'ticket' => $ticket,
27
+ 'timeout' => '1'
28
+ )
29
+ )
30
+ );
31
+ }
32
+
33
+ if ( $batch->status == self::STATUS_COMPLETED ) {
34
+
35
+ $status = get_option( Ecwid_Importer::OPTION_STATUS, array( 'plan_limit' => array() ) );
36
+
37
+ foreach($batch->responses as $response) {
38
+
39
+ $params = explode( '|', $response->id );
40
+ $type = $params[0];
41
+ $woo_id = $params[1];
42
+
43
+ if( $response->status == self::STATUS_FAILED ) {
44
+
45
+ $exporter->_batch_progress['error'][] = $type;
46
+
47
+ $message = '';
48
+ if( isset( $response->httpStatusCode ) ) {
49
+ $message .= $response->httpStatusCode;
50
+ }
51
+ if( isset( $response->httpStatusLine ) ) {
52
+ $message .= ' ' . $response->httpStatusLine . '.';
53
+ }
54
+ if( isset( $response->httpBody->errorMessage ) ) {
55
+ $message .= ' ' . $response->httpBody->errorMessage;
56
+ }
57
+ if( isset( $response->httpBody->errorCode ) ) {
58
+ $message .= ' (' . $response->httpBody->errorCode . ')';
59
+ }
60
+
61
+ if ( !isset( $exporter->_batch_progress['error_messages'][$type][$message] ) ) {
62
+ $exporter->_batch_progress['error_messages'][$type][$message] = [];
63
+ }
64
+
65
+ $error_data = array(
66
+ 'woo_id' => $woo_id,
67
+ 'woo_link' => wp_specialchars_decode(get_edit_post_link( $woo_id)),
68
+ 'name' => get_the_title( $woo_id )
69
+ );
70
+
71
+ $exporter->_batch_progress['error_messages'][$type][$message][] = $error_data;
72
+
73
+ if ( $response->httpStatusCode == 402 ) {
74
+ $status['plan_limit'][$type] = true;
75
+ }
76
+
77
+ continue;
78
+ }
79
+
80
+ if( $response->status != self::STATUS_COMPLETED ) {
81
+ continue;
82
+ }
83
+
84
+ $ecwid_id = $response->httpBody->id;
85
+
86
+ if ($type == 'create_product' ) {
87
+ update_post_meta( $woo_id, '_ecwid_product_id', $ecwid_id );
88
+ $exporter->save_ecwid_product_id( $woo_id, $ecwid_id );
89
+
90
+ $exporter->_batch_progress['success'][] = $type;
91
+
92
+ $exporter->append_task(
93
+ Ecwid_Importer_Task_Import_Woo_Product::build(
94
+ array('id' => $woo_id)
95
+ )
96
+ );
97
+ }
98
+
99
+ if ($type == 'create_variation' ) {
100
+ update_post_meta( $woo_id, '_ecwid_variation_id', $ecwid_id );
101
+ }
102
+
103
+ }
104
+
105
+ update_option( Ecwid_Importer::OPTION_STATUS, $status );
106
+ }
107
+
108
+ if( isset( $task_data['timeout'] ) && $task_data['timeout'] > 0 ) {
109
+ sleep( intval($task_data['timeout']) );
110
+ }
111
+
112
+ return $this->_result_success();
113
+ }
114
+
115
+ public static function build( array $data ) {
116
+ return array(
117
+ 'type' => self::$type,
118
+ 'ticket' => $data['ticket'],
119
+ 'timeout' => isset($data['timeout']) ? $data['timeout'] : 0
120
+ );
121
+ }
122
+ }
includes/importer/task/class-ecwid-importer-task-create-product-variation.php CHANGED
@@ -58,24 +58,17 @@ class Ecwid_Importer_Task_Create_Product_Variation extends Ecwid_Importer_Task_P
58
 
59
  if ( !isset( $variation_data['sku']) ) {
60
  unset( $variation_data['quantity'] );
61
- }
62
 
63
  break;
64
  }
65
 
66
- $result = $api->create_product_variation(
67
- $variation_data
68
- );
69
-
70
- $return = self::_process_api_result( $result, $data );
71
-
72
- if ( $return['status'] == self::STATUS_SUCCESS ) {
73
- $result_object = json_decode( $result['body'] );
74
 
75
- update_post_meta( $data['variation_id'], '_ecwid_variation_id', $result_object->id );
76
- }
77
-
78
- return $return;
79
  }
80
 
81
  public static function build( array $data ) {
58
 
59
  if ( !isset( $variation_data['sku']) ) {
60
  unset( $variation_data['quantity'] );
61
+ }
62
 
63
  break;
64
  }
65
 
66
+ $batch_item_id = self::$type . '|' . $this->_woo_product_id;
 
 
 
 
 
 
 
67
 
68
+ $batch_item = $api->batch_create_product_variation( $variation_data, $this->_ecwid_product_id, $batch_item_id );
69
+ $exporter->append_batch( $batch_item );
70
+
71
+ return $this->_result_success();
72
  }
73
 
74
  public static function build( array $data ) {
includes/importer/task/class-ecwid-importer-task-create-product.php CHANGED
@@ -6,9 +6,9 @@ class Ecwid_Importer_Task_Create_Product extends Ecwid_Importer_Task_Product_Bas
6
 
7
  const WC_PRODUCT_TYPE_VARIABLE = 'variable';
8
 
9
- public function execute( Ecwid_Importer $exporter, array $product_data ) {
10
 
11
- $this->_woo_product_id = $product_data['woo_id'];
12
 
13
  $product = wc_get_product( $this->_woo_product_id );
14
 
@@ -38,6 +38,13 @@ class Ecwid_Importer_Task_Create_Product extends Ecwid_Importer_Task_Product_Bas
38
  }
39
 
40
  $data['price'] = floatval( $data['price'] );
 
 
 
 
 
 
 
41
 
42
  $categories = get_the_terms( $this->_woo_product_id, 'product_cat' );
43
 
@@ -51,55 +58,20 @@ class Ecwid_Importer_Task_Create_Product extends Ecwid_Importer_Task_Product_Bas
51
  if ( empty( $data['categoryIds'] ) ) {
52
  unset( $data['categoryIds'] );
53
  }
54
-
55
- $ecwid_product_id = null;
56
- $result = null;
57
- $ecwid_id = null;
58
-
59
- $api = new Ecwid_Api_V3();
60
-
61
- if ( $exporter->get_setting( Ecwid_Importer::SETTING_UPDATE_BY_SKU ) ) {
62
-
63
- if( isset( $data['sku'] ) ) {
64
- $filter = array( 'sku' => $data['sku'] );
65
- } else {
66
- $filter = array( 'id' => $this->_woo_product_id );
67
- }
68
- $products = $api->get_products( $filter );
69
-
70
- if ( $products->total > 0 ) {
71
- $ecwid_id = $products->items[0]->id;
72
- $result = $api->update_product( $data, $ecwid_id );
73
- $exporter->save_ecwid_product_id( $this->get_woo_id(), $ecwid_id );
74
- }
75
- }
76
 
77
- if ( !$result ) {
78
- $result = $api->create_product( $data );
79
-
80
- if ( !$this->_is_api_result_error($result) ) {
81
- $result_object = json_decode( $result['body'] );
82
- $ecwid_id = $result_object->id;
83
- }
84
- }
85
-
86
- $return = $this->_process_api_result( $result, $data );
87
-
88
- if ( $return['status'] == self::STATUS_SUCCESS ) {
89
- $result_object = json_decode( $result['body'] );
90
-
91
- $this->_ecwid_product_id = $ecwid_id;
92
 
93
- update_post_meta( $this->get_woo_id(), '_ecwid_product_id', $ecwid_id );
94
- $exporter->save_ecwid_product_id( $this->get_woo_id(), $ecwid_id ? $ecwid_id : $result_object->id );
95
- }
96
 
97
- return $return;
98
  }
99
 
100
- public function _get_variable_product_data( )
101
  {
102
- $id = $this->get_woo_id();
 
 
103
  $result = array();
104
 
105
  $product = new WC_Product_Variable( $id );
6
 
7
  const WC_PRODUCT_TYPE_VARIABLE = 'variable';
8
 
9
+ public function get_batch_data( Ecwid_Importer $exporter, $woo_product_id ) {
10
 
11
+ $this->_woo_product_id = $woo_product_id;
12
 
13
  $product = wc_get_product( $this->_woo_product_id );
14
 
38
  }
39
 
40
  $data['price'] = floatval( $data['price'] );
41
+
42
+
43
+ $sale_price = $product->get_sale_price();
44
+ if( !empty( $sale_price ) ) {
45
+ $data['compareToPrice'] = $data['price'];
46
+ $data['price'] = floatval( $sale_price );
47
+ }
48
 
49
  $categories = get_the_terms( $this->_woo_product_id, 'product_cat' );
50
 
58
  if ( empty( $data['categoryIds'] ) ) {
59
  unset( $data['categoryIds'] );
60
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
+ return $data;
63
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
+ public function execute( Ecwid_Importer $exporter, array $product_data ) {
 
 
66
 
67
+ return $this->_result_success();
68
  }
69
 
70
+ public function _get_variable_product_data( $id = false )
71
  {
72
+ if( !$id ) {
73
+ $id = $this->get_woo_id();
74
+ }
75
  $result = array();
76
 
77
  $product = new WC_Product_Variable( $id );
includes/importer/task/class-ecwid-importer-task-import-woo-categories.php CHANGED
@@ -19,7 +19,7 @@ class Ecwid_Importer_Task_Import_Woo_Categories extends Ecwid_Importer_Task {
19
 
20
  foreach ( @$categories as $category ) {
21
  if ( $category['has_image'] ) {
22
- $importer->append_after(
23
  Ecwid_Importer_Task_Upload_Category_Image::build( $category ),
24
  $index++
25
  );
19
 
20
  foreach ( @$categories as $category ) {
21
  if ( $category['has_image'] ) {
22
+ $importer->append_task(
23
  Ecwid_Importer_Task_Upload_Category_Image::build( $category ),
24
  $index++
25
  );
includes/importer/task/class-ecwid-importer-task-import-woo-product.php CHANGED
@@ -15,14 +15,6 @@ class Ecwid_Importer_Task_Import_Woo_Product extends Ecwid_Importer_Task_Product
15
 
16
  $this->_woo_product_id = $product['woo_id'];
17
 
18
- $importer->append_task(
19
- Ecwid_Importer_Task_Create_Product::build(
20
- array(
21
- 'woo_id' => $product['woo_id']
22
- )
23
- )
24
- );
25
-
26
  if ( get_post_thumbnail_id( $product['woo_id'] ) ) {
27
  $importer->append_task(
28
  Ecwid_Importer_Task_Upload_Product_Image::build(
@@ -33,6 +25,7 @@ class Ecwid_Importer_Task_Import_Woo_Product extends Ecwid_Importer_Task_Product
33
  );
34
  }
35
 
 
36
  $p = wc_get_product( $product['woo_id'] );
37
 
38
  if ( $p instanceof WC_Product_Variable ) {
@@ -63,6 +56,7 @@ class Ecwid_Importer_Task_Import_Woo_Product extends Ecwid_Importer_Task_Product
63
  }
64
  }
65
 
 
66
  if ( $p->get_gallery_image_ids() ) {
67
  foreach ( $p->get_gallery_image_ids() as $image ) {
68
  $importer->append_task(
15
 
16
  $this->_woo_product_id = $product['woo_id'];
17
 
 
 
 
 
 
 
 
 
18
  if ( get_post_thumbnail_id( $product['woo_id'] ) ) {
19
  $importer->append_task(
20
  Ecwid_Importer_Task_Upload_Product_Image::build(
25
  );
26
  }
27
 
28
+
29
  $p = wc_get_product( $product['woo_id'] );
30
 
31
  if ( $p instanceof WC_Product_Variable ) {
56
  }
57
  }
58
 
59
+
60
  if ( $p->get_gallery_image_ids() ) {
61
  foreach ( $p->get_gallery_image_ids() as $image ) {
62
  $importer->append_task(
includes/importer/task/class-ecwid-importer-task-import-woo-products-batch.php CHANGED
@@ -15,13 +15,57 @@ class Ecwid_Importer_Task_Import_Woo_Products_Batch extends Ecwid_Importer_Task
15
  )
16
  );
17
 
 
 
18
  if ( $products ) {
 
19
  foreach ( $products as $id ) {
20
- $importer->append_child(
21
- Ecwid_Importer_Task_Import_Woo_Product::build(
22
- array( 'id' => $id )
23
- )
24
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  }
26
  }
27
 
15
  )
16
  );
17
 
18
+ $importer->clear_batch();
19
+
20
  if ( $products ) {
21
+
22
  foreach ( $products as $id ) {
23
+
24
+ $api = new Ecwid_Api_V3();
25
+ $batch_item = null;
26
+
27
+ $task_create_product = new Ecwid_Importer_Task_Create_Product();
28
+ $data = $task_create_product->get_batch_data( $importer, $id );
29
+
30
+ $batch_item_id = Ecwid_Importer_Task_Create_Product::$type . '|' . $id;
31
+
32
+ if ( $importer->get_setting( Ecwid_Importer::SETTING_UPDATE_BY_SKU ) && isset( $data['sku'] ) ) {
33
+
34
+ $filter = array( 'sku' => $data['sku'] );
35
+ $ecwid_products = $api->get_products( $filter );
36
+
37
+ if ( $ecwid_products->total > 0 ) {
38
+ $ecwid_id = $ecwid_products->items[0]->id;
39
+ $batch_item = $api->batch_update_product( $data, $ecwid_id, $batch_item_id );
40
+ }
41
+ }
42
+
43
+ if ( !$batch_item ) {
44
+ $batch_item = $api->batch_create_product( $data, $batch_item_id );
45
+ }
46
+
47
+ $importer->append_batch( $batch_item );
48
+ }
49
+
50
+ $batch = $importer->get_batch();
51
+ if( count( $batch ) ) {
52
+
53
+ $api = new Ecwid_Api_V3();
54
+ $result = $api->create_batch( $batch );
55
+
56
+ if( $result['response']['code'] == '200' ) {
57
+
58
+ $data = json_decode( $result['body'] );
59
+ $ticket = $data->ticket;
60
+
61
+ $importer->append_child(
62
+ Ecwid_Importer_Task_Batch_Status::build(
63
+ array( 'ticket' => $ticket )
64
+ )
65
+ );
66
+
67
+ $importer->clear_batch();
68
+ }
69
  }
70
  }
71
 
includes/importer/task/class-ecwid-importer-task-import-woo-products.php CHANGED
@@ -4,7 +4,7 @@ class Ecwid_Importer_Task_Import_Woo_Products extends Ecwid_Importer_Task {
4
 
5
  public static $type = 'import-woo-products';
6
 
7
- const BATCH_SIZE = 50;
8
 
9
  public function execute( Ecwid_Importer $importer, array $data ) {
10
 
4
 
5
  public static $type = 'import-woo-products';
6
 
7
+ const BATCH_SIZE = 100;
8
 
9
  public function execute( Ecwid_Importer $importer, array $data ) {
10
 
includes/importer/task/class-ecwid-importer-task-upload-category-image.php CHANGED
@@ -11,7 +11,6 @@ class Ecwid_Importer_Task_Upload_Category_Image extends Ecwid_Importer_Task
11
 
12
  // get the thumbnail id using the queried category term_id
13
  $thumbnail_id = get_term_meta( $woo_id, 'thumbnail_id', true );
14
- $file = get_attached_file ( $thumbnail_id );
15
 
16
  $category_id = $exporter->get_ecwid_category_id( $woo_id );
17
  if ( !$category_id ) {
@@ -22,12 +21,31 @@ class Ecwid_Importer_Task_Upload_Category_Image extends Ecwid_Importer_Task
22
  );
23
  }
24
 
25
- $data = array(
26
- 'categoryId' => $category_id,
27
- 'data' => file_get_contents( $file )
28
- );
 
 
 
 
 
 
 
 
 
29
 
30
- $result = $api->upload_category_image( $data );
 
 
 
 
 
 
 
 
 
 
31
 
32
  return self::_process_api_result( $result, $data );
33
  }
11
 
12
  // get the thumbnail id using the queried category term_id
13
  $thumbnail_id = get_term_meta( $woo_id, 'thumbnail_id', true );
 
14
 
15
  $category_id = $exporter->get_ecwid_category_id( $woo_id );
16
  if ( !$category_id ) {
21
  );
22
  }
23
 
24
+ if ( Ecwid_Importer::is_localhost() ) {
25
+
26
+ $file = get_attached_file ( $thumbnail_id );
27
+
28
+ $data = array(
29
+ 'categoryId' => $category_id,
30
+ 'data' => file_get_contents( $file )
31
+ );
32
+
33
+ $result = $api->upload_category_image( $data );
34
+ } else {
35
+
36
+ $batch_item_id = self::$type . '|' . $category_id;
37
 
38
+ $file_url = wp_get_attachment_url( $thumbnail_id );
39
+ $data = array(
40
+ 'externalUrl' => $file_url
41
+ );
42
+
43
+ $batch_item = $api->batch_upload_category_image( $data, $category_id, $batch_item_id );
44
+ $exporter->append_batch( $batch_item );
45
+
46
+ return $this->_result_success();
47
+
48
+ }
49
 
50
  return self::_process_api_result( $result, $data );
51
  }
includes/importer/task/class-ecwid-importer-task-upload-product-gallery-image.php CHANGED
@@ -28,14 +28,32 @@ class Ecwid_Importer_Task_Upload_Product_Gallery_Image extends Ecwid_Importer_Ta
28
  );
29
  }
30
 
31
- $data = array(
32
- 'productId' => $this->_ecwid_product_id,
33
- 'data' => file_get_contents( $file )
34
- );
35
 
36
- $result = $api->upload_product_gallery_image( $data );
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
- return self::_process_api_result( $result, $data );
 
 
 
 
 
 
 
 
 
 
39
  }
40
 
41
  public static function build( array $data ) {
28
  );
29
  }
30
 
 
 
 
 
31
 
32
+ if ( Ecwid_Importer::is_localhost() ) {
33
+
34
+ $data = array(
35
+ 'productId' => $this->_ecwid_product_id,
36
+ 'data' => file_get_contents( $file )
37
+ );
38
+
39
+ $result = $api->upload_product_gallery_image( $data );
40
+
41
+ return self::_process_api_result( $result, $data );
42
+ } else {
43
+
44
+ $batch_item_id = self::$type . '|' . $this->_ecwid_product_id;
45
 
46
+ $file_url = wp_get_attachment_url( $product_data['image_id'] );
47
+ $data = array(
48
+ 'externalUrl' => $file_url
49
+ );
50
+
51
+ $batch_item = $api->batch_upload_product_gallery_image( $data, $this->_ecwid_product_id, $batch_item_id );
52
+ $exporter->append_batch( $batch_item );
53
+
54
+ return $this->_result_success();
55
+
56
+ }
57
  }
58
 
59
  public static function build( array $data ) {
includes/importer/task/class-ecwid-importer-task-upload-product-image.php CHANGED
@@ -16,19 +16,35 @@ class Ecwid_Importer_Task_Upload_Product_Image extends Ecwid_Importer_Task_Produ
16
  'message' => 'Parent product was not imported for product #' . $product_data['woo_id']
17
  );
18
  }
19
-
20
  $api = new Ecwid_Api_V3();
21
 
22
- $file = get_attached_file ( get_post_thumbnail_id( $product_data['woo_id'] ) );
23
 
24
- $data = array(
25
- 'productId' => $this->_ecwid_product_id,
26
- 'data' => file_get_contents( $file )
27
- );
 
 
 
 
 
28
 
29
- $result = $api->upload_product_image( $data );
30
 
31
- return self::_process_api_result( $result, $data );
 
 
 
 
 
 
 
 
 
 
 
32
  }
33
 
34
  public static function build( array $data ) {
16
  'message' => 'Parent product was not imported for product #' . $product_data['woo_id']
17
  );
18
  }
19
+
20
  $api = new Ecwid_Api_V3();
21
 
22
+ if ( Ecwid_Importer::is_localhost() ) {
23
 
24
+ $file = get_attached_file ( get_post_thumbnail_id( $product_data['woo_id'] ) );
25
+
26
+ $data = array(
27
+ 'productId' => $this->_ecwid_product_id,
28
+ 'data' => file_get_contents( $file )
29
+ );
30
+
31
+ $result = $api->upload_product_image( $data );
32
+ return self::_process_api_result( $result, $data );
33
 
34
+ } else {
35
 
36
+ $batch_item_id = self::$type . '|' . $this->_ecwid_product_id;
37
+
38
+ $file_url = wp_get_attachment_url( get_post_thumbnail_id( $product_data['woo_id'] ) );
39
+ $data = array(
40
+ 'externalUrl' => $file_url
41
+ );
42
+
43
+ $batch_item = $api->batch_upload_product_image( $data, $this->_ecwid_product_id, $batch_item_id );
44
+ $exporter->append_batch( $batch_item );
45
+
46
+ return $this->_result_success();
47
+ }
48
  }
49
 
50
  public static function build( array $data ) {
includes/importer/task/class-ecwid-importer-task-upload-product-variation-image.php CHANGED
@@ -31,15 +31,32 @@ class Ecwid_Importer_Task_Upload_Product_Variation_Image extends Ecwid_Importer_
31
  );
32
  }
33
 
34
- $data = array(
35
- 'productId' => $this->_ecwid_product_id,
36
- 'variationId' => $variation_id,
37
- 'data' => file_get_contents( $file )
38
- );
 
 
 
 
 
 
 
39
 
40
- $result = $api->upload_product_variation_image( $data );
41
 
42
- return self::_process_api_result( $result, $data );
 
 
 
 
 
 
 
 
 
 
43
  }
44
 
45
  public static function build( array $data ) {
31
  );
32
  }
33
 
34
+ if ( Ecwid_Importer::is_localhost() ) {
35
+
36
+ $data = array(
37
+ 'productId' => $this->_ecwid_product_id,
38
+ 'variationId' => $variation_id,
39
+ 'data' => file_get_contents( $file )
40
+ );
41
+
42
+ $result = $api->upload_product_variation_image( $data );
43
+
44
+ return self::_process_api_result( $result, $data );
45
+ } else {
46
 
47
+ $batch_item_id = self::$type . '|' . $this->_ecwid_product_id;
48
 
49
+ $file_url = wp_get_attachment_url( get_post_thumbnail_id( $data['variation_id'] ) );
50
+ $data = array(
51
+ 'externalUrl' => $file_url
52
+ );
53
+
54
+ $batch_item = $api->batch_upload_product_variation_image( $data, $this->_ecwid_product_id, $data['variation_id'], $batch_item_id );
55
+ $exporter->append_batch( $batch_item );
56
+
57
+ return $this->_result_success();
58
+
59
+ }
60
  }
61
 
62
  public static function build( array $data ) {
includes/shortcodes/class-ecwid-shortcode-productbrowser.php CHANGED
@@ -34,7 +34,7 @@ class Ecwid_Shortcode_ProductBrowser extends Ecwid_Shortcode_Base {
34
  $option_print_html_catalog = get_option('ecwid_print_html_catalog', 'Y');
35
 
36
  if ( !Ecwid_Static_Page::is_data_available() || @$this->_params['noHTMLCatalog'] || empty( $option_print_html_catalog ) ) {
37
- return $default_render;
38
  }
39
 
40
 
34
  $option_print_html_catalog = get_option('ecwid_print_html_catalog', 'Y');
35
 
36
  if ( !Ecwid_Static_Page::is_data_available() || @$this->_params['noHTMLCatalog'] || empty( $option_print_html_catalog ) ) {
37
+ return '<div id="dynamic-ec-store">' . $default_render . '</div>';
38
  }
39
 
40
 
includes/themes/class-ecwid-theme-avada.php CHANGED
@@ -24,6 +24,10 @@ Ecwid.OnPageLoaded.add( function() {
24
  if (typeof niceScrollReInit == 'function') {
25
  niceScrollReInit();
26
  }
 
 
 
 
27
  }
28
  );</script>
29
  HTML;
24
  if (typeof niceScrollReInit == 'function') {
25
  niceScrollReInit();
26
  }
27
+
28
+ if (typeof jQuery("html").getNiceScroll == 'object') {
29
+ jQuery("html").getNiceScroll().resize();
30
+ }
31
  }
32
  );</script>
33
  HTML;
lib/ecwid_api_v3.php CHANGED
@@ -57,6 +57,7 @@ class Ecwid_Api_V3
57
  $this->_products_api_url = $this->_api_url . $this->store_id . '/products';
58
  $this->_profile_api_url = $this->_api_url . $this->store_id . '/profile';
59
  $this->_starter_site_api_url = $this->_api_url . $this->store_id . '/startersite';
 
60
 
61
  add_option( self::OPTION_API_STATUS, self::API_STATUS_UNDEFINED );
62
  }
@@ -64,12 +65,8 @@ class Ecwid_Api_V3
64
  public static function is_available()
65
  {
66
  $status = self::get_api_status();
67
-
68
- // if ( $status == self::API_STATUS_UNDEFINED ) {
69
- return self::check_api_status();
70
- // }
71
-
72
- return $status == self::API_STATUS_OK;
73
  }
74
 
75
  public static function connection_fails()
@@ -525,7 +522,7 @@ class Ecwid_Api_V3
525
  return $stats;
526
  }
527
 
528
- public function get_store_profile() {
529
 
530
  if( ecwid_is_demo_store() ) {
531
  return false;
@@ -533,7 +530,7 @@ class Ecwid_Api_V3
533
 
534
  $profile = EcwidPlatform::cache_get( self::PROFILE_CACHE_NAME );
535
 
536
- if ( $profile ) {
537
  return $profile;
538
  }
539
 
@@ -763,7 +760,7 @@ class Ecwid_Api_V3
763
 
764
  return $result;
765
  }
766
-
767
  protected function _sanitize_product_data( $data ) {
768
 
769
  $int_fields = array( 'quantity', 'defaultCategoryId', 'showOnFrontPage' );
@@ -995,4 +992,123 @@ class Ecwid_Api_V3
995
  }
996
  }
997
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
998
  }
57
  $this->_products_api_url = $this->_api_url . $this->store_id . '/products';
58
  $this->_profile_api_url = $this->_api_url . $this->store_id . '/profile';
59
  $this->_starter_site_api_url = $this->_api_url . $this->store_id . '/startersite';
60
+ $this->_batch_requests_api_url = $this->_api_url . $this->store_id . '/batch';
61
 
62
  add_option( self::OPTION_API_STATUS, self::API_STATUS_UNDEFINED );
63
  }
65
  public static function is_available()
66
  {
67
  $status = self::get_api_status();
68
+
69
+ return self::check_api_status();
 
 
 
 
70
  }
71
 
72
  public static function connection_fails()
522
  return $stats;
523
  }
524
 
525
+ public function get_store_profile( $disable_cache = false ) {
526
 
527
  if( ecwid_is_demo_store() ) {
528
  return false;
530
 
531
  $profile = EcwidPlatform::cache_get( self::PROFILE_CACHE_NAME );
532
 
533
+ if ( $profile && !$disable_cache ) {
534
  return $profile;
535
  }
536
 
760
 
761
  return $result;
762
  }
763
+
764
  protected function _sanitize_product_data( $data ) {
765
 
766
  $int_fields = array( 'quantity', 'defaultCategoryId', 'showOnFrontPage' );
992
  }
993
  }
994
  }
995
+
996
+ public function create_batch( $params )
997
+ {
998
+ $request_params = array(
999
+ 'token',
1000
+ 'stopOnFirstFailure' => 'false'
1001
+ );
1002
+ $url = $this->build_request_url( $this->_batch_requests_api_url, $request_params );
1003
+
1004
+ $result = $this->_do_post( $url, $params );
1005
+
1006
+ return $result;
1007
+ }
1008
+
1009
+ public function get_batch_status( $ticket )
1010
+ {
1011
+ $params = array(
1012
+ 'token' => self::get_token(),
1013
+ 'ticket' => $ticket
1014
+ );
1015
+
1016
+ $url = $this->build_request_url($this->_batch_requests_api_url, $params);
1017
+ $result = EcwidPlatform::fetch_url($url);
1018
+
1019
+ if ( @$result['code'] != '200' ) {
1020
+ return false;
1021
+ }
1022
+
1023
+ return $result;
1024
+ }
1025
+
1026
+ // TO-DO create class for batch methods
1027
+ public function compose_batch_item( $path, $method = 'GET', $body = false, $batch_id = false ) {
1028
+ $result = array(
1029
+ 'path' => $path,
1030
+ 'method' => $method
1031
+ );
1032
+
1033
+ if( !empty( $body ) ) {
1034
+ $result['body'] = $body;
1035
+ }
1036
+
1037
+ if( !empty( $batch_id ) ) {
1038
+ $result['id'] = $batch_id;
1039
+ }
1040
+
1041
+ return $result;
1042
+ }
1043
+
1044
+ public function batch_create_product( $params, $batch_id = false ) {
1045
+ return $this->compose_batch_item(
1046
+ '/products',
1047
+ 'POST',
1048
+ $this->_sanitize_product_data( $params ),
1049
+ $batch_id
1050
+ );
1051
+ }
1052
+
1053
+ public function batch_update_product( $params, $product_id, $batch_id = false ) {
1054
+ return $this->compose_batch_item(
1055
+ '/products/' . $product_id,
1056
+ 'PUT',
1057
+ $this->_sanitize_product_data( $params ),
1058
+ $batch_id
1059
+ );
1060
+ }
1061
+
1062
+ public function batch_upload_category_image( $params, $category_id, $batch_id = false ) {
1063
+ $url = $this->build_request_url('/categories/' . $product_id . '/image', $params);
1064
+
1065
+ return $this->compose_batch_item(
1066
+ $url,
1067
+ 'POST',
1068
+ false,
1069
+ $batch_id
1070
+ );
1071
+ }
1072
+
1073
+ public function batch_upload_product_image( $params, $product_id, $batch_id = false ) {
1074
+ $url = $this->build_request_url('/products/' . $product_id . '/image', $params);
1075
+
1076
+ return $this->compose_batch_item(
1077
+ $url,
1078
+ 'POST',
1079
+ false,
1080
+ $batch_id
1081
+ );
1082
+ }
1083
+
1084
+ public function batch_upload_product_gallery_image( $params, $product_id, $batch_id = false ) {
1085
+ $url = $this->build_request_url('/products/' . $product_id . '/gallery', $params);
1086
+
1087
+ return $this->compose_batch_item(
1088
+ $url,
1089
+ 'POST',
1090
+ false,
1091
+ $batch_id
1092
+ );
1093
+ }
1094
+
1095
+ public function batch_upload_product_variation_image( $params, $product_id, $variation_id, $batch_id = false ) {
1096
+ $url = $this->build_request_url('/products/' . $product_id . '/combinations/' . $variation_id . '/image', $params);
1097
+
1098
+ return $this->compose_batch_item(
1099
+ $url,
1100
+ 'POST',
1101
+ false,
1102
+ $batch_id
1103
+ );
1104
+ }
1105
+
1106
+ public function batch_create_product_variation( $params, $product_id, $batch_id = false ) {
1107
+ return $this->compose_batch_item(
1108
+ '/products/' . $product_id . '/combinations',
1109
+ 'POST',
1110
+ $params,
1111
+ $batch_id
1112
+ );
1113
+ }
1114
  }
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
- === Ecwid Ecommerce Shopping Cart ===
2
  Contributors: Ecwid
3
  Tags: ecommerce, e-commerce, storefront, online store, sell
4
  Requires at least: 3.7
5
  Tested up to: 5.3
6
- Stable tag: 6.8.8
7
 
8
  Powerful, easy to use ecommerce shopping cart. Sell on Facebook and Instagram. iPhone & Android apps. Superb support. Free plan available.
9
 
@@ -157,6 +157,11 @@ You can use Ecwid’s built-in import tools to copy your store products from any
157
  * [Ecwid eCommerce Forums](https://www.ecwid.com/forums/forumdisplay.php?f=19)
158
 
159
  == Changelog ==
 
 
 
 
 
160
  = 6.8.8 - Oct 31, 2019 =
161
  - WordPress 5.3 and Twenty Twenty theme compatibility. The new WordPress version with the 2020 theme is coming soon. The Ecwid ecommerce shopping cart plugin is ready for the upcoming changes — everything will work well in your WordPress admin and storefront pages. Feel free to upgrade your site to WordPress 5.3 as soon as it's released and try a new theme.
162
  - Minor fixes and improvements.
1
+ === Ecwid Ecommerce Shopping Cart ===
2
  Contributors: Ecwid
3
  Tags: ecommerce, e-commerce, storefront, online store, sell
4
  Requires at least: 3.7
5
  Tested up to: 5.3
6
+ Stable tag: 6.8.9
7
 
8
  Powerful, easy to use ecommerce shopping cart. Sell on Facebook and Instagram. iPhone & Android apps. Superb support. Free plan available.
9
 
157
  * [Ecwid eCommerce Forums](https://www.ecwid.com/forums/forumdisplay.php?f=19)
158
 
159
  == Changelog ==
160
+ = 6.8.9 - Dec 4, 2019 =
161
+ - **Several fixes and improvements for the "Import from WooCommerce" tool.** If you import your products from WooCommerce to Ecwid, the import process now should work faster. We also added import of product sale prices from WooCommerce import "Sale Price". In the storefront, this price will be struck out to demonstrate the discount and the ON SALE label will appear on the product.
162
+ - Avada, SimplyNews, Twenty Twenty themes improved compatibility. Even though Ecwid is compatible with every WordPress theme by design, some slight fixes and improvements are sometimes needed to make storefront look better. That’s why we are always monitoring how Ecwid pages look and behave in WordPress ecommerce themes.
163
+ - Minor fixes and improvements.
164
+
165
  = 6.8.8 - Oct 31, 2019 =
166
  - WordPress 5.3 and Twenty Twenty theme compatibility. The new WordPress version with the 2020 theme is coming soon. The Ecwid ecommerce shopping cart plugin is ready for the upcoming changes — everything will work well in your WordPress admin and storefront pages. Feel free to upgrade your site to WordPress 5.3 as soon as it's released and try a new theme.
167
  - Minor fixes and improvements.
templates/admin-message.php CHANGED
@@ -30,6 +30,7 @@
30
  <a
31
  class="button<?php if ( $secondary_hide ): ?> ecwid-message-hide<?php endif; ?>"
32
  href="<?php echo esc_attr( $secondary_url ); ?>"
 
33
  <?php if ( $secondary_blank ): ?>
34
  target="_blank"
35
  <?php endif; ?>
30
  <a
31
  class="button<?php if ( $secondary_hide ): ?> ecwid-message-hide<?php endif; ?>"
32
  href="<?php echo esc_attr( $secondary_url ); ?>"
33
+ name="<?php echo $name; ?>"
34
  <?php if ( $secondary_blank ): ?>
35
  target="_blank"
36
  <?php endif; ?>
templates/admin/simple-connect.tpl.php CHANGED
@@ -1,6 +1,8 @@
1
  <?php
2
  $no_oauth = @$_GET['oauth'] == 'no';
3
  $connection_error = isset( $_GET['connection_error'] );
 
 
4
  ?>
5
 
6
  <div class="wrap ecwid-admin ecwid-connect<?php if ($no_oauth): ?> no-oauth<?php else: ?> with-oauth<?php endif; ?>">
@@ -19,7 +21,8 @@
19
  <input type="text" id="ecwid-store-id" placeholder="<?php _e('Enter your Store ID', 'ecwid-shopping-cart'); ?>" />
20
  </div>
21
  <div class="connect-button">
22
- <a href="admin-post.php?action=ec_connect" class="with-oauth"><?php _e( 'Connect', 'ecwid-shopping-cart' ); ?></a>
 
23
  <a id="ecwid-connect-no-oauth" href="admin-post.php?action=ec_connect" class="no-oauth" style="white-space: nowrap; width:auto"><?php _e( 'Save and connect', 'ecwid-shopping-cart' ); ?></a>
24
  </div>
25
 
1
  <?php
2
  $no_oauth = @$_GET['oauth'] == 'no';
3
  $connection_error = isset( $_GET['connection_error'] );
4
+
5
+ $connect_url = 'admin-post.php?action=ec_connect';
6
  ?>
7
 
8
  <div class="wrap ecwid-admin ecwid-connect<?php if ($no_oauth): ?> no-oauth<?php else: ?> with-oauth<?php endif; ?>">
21
  <input type="text" id="ecwid-store-id" placeholder="<?php _e('Enter your Store ID', 'ecwid-shopping-cart'); ?>" />
22
  </div>
23
  <div class="connect-button">
24
+
25
+ <a href="<?php echo $connect_url; ?>" class="with-oauth"><?php _e( 'Connect', 'ecwid-shopping-cart' ); ?></a>
26
  <a id="ecwid-connect-no-oauth" href="admin-post.php?action=ec_connect" class="no-oauth" style="white-space: nowrap; width:auto"><?php _e( 'Save and connect', 'ecwid-shopping-cart' ); ?></a>
27
  </div>
28
 
templates/debug.php CHANGED
@@ -62,7 +62,7 @@
62
  <h2>Error log</h2>
63
  <div>
64
  <?php foreach (json_decode($all_options['ecwid_error_log'], true) as $key => $item): ?>
65
- <div class="section"><?php echo $item['message']; ?></div>
66
  <?php endforeach; ?>
67
  </div>
68
 
@@ -87,7 +87,7 @@
87
  <?php echo $key; ?>
88
  </div>
89
  <div>
90
- <?php echo $option; ?>
91
  </div>
92
  </div>
93
  <?php endif; ?>
62
  <h2>Error log</h2>
63
  <div>
64
  <?php foreach (json_decode($all_options['ecwid_error_log'], true) as $key => $item): ?>
65
+ <div class="section"><?php echo htmlspecialchars($item['message']); ?><br><br></div>
66
  <?php endforeach; ?>
67
  </div>
68
 
87
  <?php echo $key; ?>
88
  </div>
89
  <div>
90
+ <?php echo htmlspecialchars($option); ?>
91
  </div>
92
  </div>
93
  <?php endif; ?>