Ecwid Ecommerce Shopping Cart - Version 5.4

Version Description

  • Improvements in the SEO friendly versions of product pages, which are indexed by search engines. This includes optimized product price format, canonical tags and minor adjustments for SEO titles and descriptions. This is another improvement for search crawlers to better index store pages.
  • Adjustments for the All in one SEO plugin to make sure it works well with the Ecwids new clean URLs.
  • Fixed preg match PHP warning messages, which appeared on some sites with the Ecwid ecommerce plugin enabled.
  • Fixed an issue with site images in the Newsmag Wordpress theme some images were not displayed well with Ecwid. We fixed that so everything should work fine in the Newsmag theme now.
  • Several fixes and improvements for the floating minicart widget.
  • Loading speed improvements. We optimized the plugin code to render store pages and widgets faster.
Download this release

Release Info

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

Code changes from version 5.3.1 to 5.4

css/themes/newsmag.css ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ html#ecwid_html body#ecwid_body .ecwid img {
2
+ opacity: 1;
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 Team
8
- Version: 5.3.1
9
  Author URI: http://www.ecwid.com?source=wporg
10
  */
11
 
@@ -56,9 +56,12 @@ if ( is_admin() ) {
56
  }
57
 
58
  require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-nav-menus.php';
 
59
 
60
  require_once ECWID_PLUGIN_DIR . 'lib/ecwid_platform.php';
61
  require_once ECWID_PLUGIN_DIR . 'lib/ecwid_api_v3.php';
 
 
62
 
63
 
64
  // Older versions of Google XML Sitemaps plugin generate it in admin, newer in site area, so the hook should be assigned in both of them
@@ -430,24 +433,23 @@ function ecwid_load_textdomain() {
430
  }
431
 
432
  function ecwid_404_on_broken_escaped_fragment() {
433
- if (!ecwid_is_api_enabled()) {
434
  return;
435
  }
436
 
437
- if (!isset($_GET['_escaped_fragment_'])) {
438
  return;
439
  }
440
 
441
  $params = ecwid_parse_escaped_fragment($_GET['_escaped_fragment_']);
442
- $api = ecwid_new_product_api();
443
 
444
  if (isset($params['mode']) && !empty($params['mode']) && isset($params['id'])) {
445
  $result = array();
446
  $is_root_cat = $params['mode'] == 'category' && $params['id'] == 0;
447
  if ($params['mode'] == 'product') {
448
- $result = $api->get_product($params['id']);
449
  } elseif (!$is_root_cat && $params['mode'] == 'category') {
450
- $result = $api->get_category($params['id']);
451
  }
452
 
453
  if (!$is_root_cat && empty($result)) {
@@ -460,25 +462,37 @@ function ecwid_404_on_broken_escaped_fragment() {
460
  }
461
 
462
  function ecwid_503_on_store_closed() {
463
- if (!ecwid_is_api_enabled()) {
464
- return;
465
- }
466
 
467
- if (!isset($_GET['_escaped_fragment_'])) {
468
  return;
469
  }
470
 
471
- $api = ecwid_new_product_api();
472
- $profile = $api->get_profile();
 
 
 
473
 
474
- if ($profile['closed']) {
475
- header('HTTP/1.1 503 Service Temporarily Unavailable');
476
- header('Status: 503 Service Temporarily Unavailable');
 
 
 
 
 
 
 
 
 
 
477
  }
 
 
478
  }
479
 
480
- function ecwid_backward_compatibility() {
481
 
 
482
 
483
  // Backward compatibility with 1.1.2 and earlier
484
  if (isset($_GET['ecwid_product_id']) || isset($_GET['ecwid_category_id'])) {
@@ -502,7 +516,7 @@ function ecwid_build_sitemap($callback)
502
  if (get_post_status($page_id) == 'publish') {
503
  require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-sitemap-builder.php';
504
 
505
- $sitemap = new EcwidSitemapBuilder(Ecwid_Store_Page::get_store_url(), $callback, ecwid_new_product_api());
506
 
507
  $sitemap->generate();
508
  }
@@ -561,9 +575,7 @@ function ecwid_check_version()
561
  add_option('ecwid_plugin_version', $current_version);
562
 
563
  add_option('ecwid_use_chameleon', false);
564
-
565
- add_option('ecwid_use_new_horizontal_categories', 'Y');
566
-
567
  // Called in Ecwid_Seo_Links->on_fresh_install
568
  do_action( 'ecwid_on_fresh_install' );
569
 
@@ -571,9 +583,7 @@ function ecwid_check_version()
571
 
572
  do_action('ecwid_plugin_upgraded', array( 'old' => $stored_version, 'new' => $current_version ) );
573
  update_option('ecwid_plugin_version', $current_version);
574
-
575
- add_option('ecwid_use_new_horizontal_categories', '');
576
-
577
  do_action( 'ecwid_on_plugin_upgrade' );
578
  }
579
 
@@ -606,10 +616,12 @@ function ecwid_check_version()
606
 
607
  add_option(Ecwid_Widget_Floating_Shopping_Cart::OPTION_DISPLAY_POSITION, '');
608
 
609
- update_option('ecwid_use_new_search', 'Y');
610
-
 
 
 
611
  Ecwid_Config::load_from_ini();
612
- update_option('ecwid_use_new_categories', 'Y');
613
 
614
  add_option( 'force_scriptjs_render', false );
615
 
@@ -714,7 +726,10 @@ function ecwid_seo_ultimate_compatibility()
714
  {
715
  global $seo_ultimate;
716
 
717
- if ($seo_ultimate && Ecwid_Store_Page::is_store_page()) {
 
 
 
718
  remove_action('template_redirect', array($seo_ultimate->modules['titles'], 'before_header'), 0);
719
  remove_action('wp_head', array($seo_ultimate->modules['titles'], 'after_header'), 1000);
720
  remove_action('su_head', array($seo_ultimate->modules['meta-descriptions'], 'head_tag_output'));
@@ -790,11 +805,20 @@ function ecwid_admin_check_api_cache()
790
  update_option('ecwid_last_api_cache_check', time());
791
  }
792
 
793
- function ecwid_invalidate_cache()
794
  {
795
- $api = new Ecwid_Api_V3();
796
 
797
- if ($api->is_available()) {
 
 
 
 
 
 
 
 
 
 
798
  $stats = $api->get_store_update_stats();
799
 
800
  if ($stats) {
@@ -920,7 +944,7 @@ function ecwid_content_has_productbrowser( $content ) {
920
 
921
  function ecwid_ajax_crawling_fragment() {
922
 
923
- if ( !ecwid_is_api_enabled() ) return;
924
 
925
  if ( isset( $_GET['_escaped_fragment_'] ) ) return;
926
 
@@ -943,7 +967,7 @@ function ecwid_meta() {
943
  echo '<link rel="dns-prefetch" href="//app.ecwid.com/">' . PHP_EOL;
944
  echo '<link rel="dns-prefetch" href="//ecwid-static-ru.r.worldssl.net">' . PHP_EOL;
945
  echo '<link rel="dns-prefetch" href="//ecwid-images-ru.r.worldssl.net">' . PHP_EOL;
946
-
947
  if (!Ecwid_Store_Page::is_store_page() && ecwid_is_store_page_available()) {
948
  $page_url = Ecwid_Store_Page::get_store_url();
949
  echo '<link rel="prefetch" href="' . $page_url . '" />' . PHP_EOL;
@@ -963,29 +987,48 @@ function ecwid_product_browser_url_in_head() {
963
 
964
  function ecwid_canonical() {
965
 
966
- if (!ecwid_is_applicable_escaped_fragment()) {
967
- return;
968
- }
969
 
970
- $params = ecwid_parse_escaped_fragment($_GET['_escaped_fragment_']);
971
 
972
- $api = ecwid_new_product_api();
 
 
 
 
 
 
 
 
973
 
974
- if ($params['mode'] == 'product') {
975
- $product = $api->get_product($params['id']);
976
- $link = ecwid_get_product_url($product);
977
- } else if ($params['mode'] == 'category') {
978
- $category = $api->get_category($params['id']);
979
- $link = ecwid_get_category_url($category);
 
 
 
980
  }
981
 
982
- echo '<link rel="canonical" href="' . esc_attr($link) . '" />' . PHP_EOL;
 
 
 
 
 
 
983
  }
984
 
985
  function ecwid_is_applicable_escaped_fragment() {
986
 
987
- $allowed = ecwid_is_api_enabled() && isset($_GET['_escaped_fragment_']);
988
- if (!$allowed) return false;
 
 
 
989
 
990
  $params = ecwid_parse_escaped_fragment($_GET['_escaped_fragment_']);
991
  if (!$params) return false;
@@ -999,22 +1042,50 @@ function ecwid_meta_description() {
999
 
1000
  $params = array();
1001
 
 
1002
  if ( ecwid_is_applicable_escaped_fragment() ) {
1003
  $params = ecwid_parse_escaped_fragment( $_GET['_escaped_fragment_'] );
 
 
 
 
 
 
 
 
1004
  } else if ( Ecwid_Seo_Links::is_product_browser_url() ) {
1005
  $params = Ecwid_Seo_Links::maybe_extract_html_catalog_params();
1006
- }
 
 
 
1007
 
1008
- if ( empty( $params ) ) return;
 
 
 
 
 
 
 
 
1009
 
1010
- $api = ecwid_new_product_api();
1011
- if ($params['mode'] == 'product') {
1012
- $product = $api->get_product($params['id']);
1013
- $description = $product['description'];
1014
- } elseif ($params['mode'] == 'category') {
1015
- $category = $api->get_category($params['id']);
1016
- $description = $category['description'];
1017
- } else return;
 
 
 
 
 
 
 
 
1018
 
1019
  $description = ecwid_trim_description($description);
1020
 
@@ -1053,37 +1124,6 @@ function ecwid_hide_vote_message()
1053
  update_option('ecwid_show_vote_message', false);
1054
  }
1055
 
1056
- function ecwid_get_product_and_category($category_id, $product_id) {
1057
- $params = array
1058
- (
1059
- array("alias" => "c", "action" => "category", "params" => array("id" => $category_id)),
1060
- array("alias" => "p", "action" => "product", "params" => array("id" => $product_id)),
1061
- );
1062
-
1063
- $api = ecwid_new_product_api();
1064
- $batch_result = $api->get_batch_request($params);
1065
-
1066
- if (false == $batch_result) {
1067
- $product = $api->get_product($product_id);
1068
- $category = false;
1069
- } else {
1070
- $category = $batch_result["c"];
1071
- $product = $batch_result["p"];
1072
- }
1073
-
1074
- $return = "";
1075
-
1076
- if (is_array($product)) {
1077
- $return .=$product["name"];
1078
- }
1079
-
1080
- if(is_array($category)) {
1081
- $return.=" | ";
1082
- $return .=$category["name"];
1083
- }
1084
- return $return;
1085
- }
1086
-
1087
  function ecwid_get_title_separator()
1088
  {
1089
  $sep = apply_filters('document_title_separator', '|');
@@ -1124,41 +1164,75 @@ function _ecwid_get_seo_title()
1124
 
1125
  if ( ecwid_is_applicable_escaped_fragment() ) {
1126
  $params = ecwid_parse_escaped_fragment( $_GET['_escaped_fragment_'] );
1127
- } else if ( Ecwid_Seo_Links::is_product_browser_url() ) {
1128
- $params = Ecwid_Seo_Links::maybe_extract_html_catalog_params();
1129
- }
1130
-
1131
- if ( empty( $params ) ) return;
1132
 
1133
- $ecwid_seo_title = '';
1134
 
1135
- $separator = ecwid_get_title_separator();
1136
 
1137
- $api = ecwid_new_product_api();
 
 
 
 
1138
 
1139
- if ( isset( $params['mode'] ) && ! empty( $params['mode'] ) ) {
1140
- if ( $params['mode'] == 'product' ) {
1141
- if ( isset( $params['category'] ) && ! empty( $params['category'] ) ) {
1142
- $ecwid_seo_title = ecwid_get_product_and_category( $params['category'], $params['id'] );
1143
- } elseif ( empty( $params['category'] ) ) {
1144
- $ecwid_product = $api->get_product( $params['id'] );
1145
- $ecwid_seo_title = $ecwid_product['name'];
1146
- if ( isset( $ecwid_product['categories'] ) && is_array( $ecwid_product['categories'] ) ) {
1147
- foreach ( $ecwid_product['categories'] as $ecwid_category ) {
1148
- if ( $ecwid_category['defaultCategory'] == true ) {
 
 
 
 
1149
  $ecwid_seo_title .= ' ' . $separator . ' ';
1150
- $ecwid_seo_title .= $ecwid_category['name'];
1151
  }
1152
  }
1153
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1154
  }
1155
- } elseif ( $params['mode'] == 'category' ) {
1156
- $api = ecwid_new_product_api();
1157
- $ecwid_category = $api->get_category( $params['id'] );
1158
- $ecwid_seo_title = $ecwid_category['name'];
1159
  }
1160
  }
1161
 
 
1162
  if ( ! empty( $ecwid_seo_title ) ) {
1163
  return $ecwid_seo_title;
1164
  }
@@ -1166,6 +1240,33 @@ function _ecwid_get_seo_title()
1166
  return "";
1167
  }
1168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1169
  function ecwid_add_credits($powered_by)
1170
  {
1171
  if (!ecwid_is_paid_account()) {
@@ -1270,11 +1371,7 @@ function ecwid_minicart_shortcode($attributes) {
1270
  }
1271
 
1272
  function ecwid_get_search_js_code() {
1273
- if (get_option('ecwid_use_new_search', false)) {
1274
- return 'xSearch("style=");';
1275
- } else {
1276
- return 'xSearchPanel("style=")';
1277
- }
1278
  }
1279
 
1280
  function _ecwid_get_single_product_widget_parts_v1($attributes) {
@@ -1414,12 +1511,9 @@ function ecwid_parse_escaped_fragment($escaped_fragment) {
1414
  function ecwid_ajax_get_product_info() {
1415
  $id = $_GET['id'];
1416
 
1417
- if (ecwid_is_api_enabled()) {
1418
- $api = ecwid_new_product_api();
1419
- $product = $api->get_product_https($id);
1420
-
1421
- echo json_encode($product);
1422
- }
1423
 
1424
  exit();
1425
  }
@@ -1601,28 +1695,6 @@ function ecwid_uninstall() {
1601
  delete_option("ecwid_use_chameleon");
1602
  }
1603
 
1604
- function ecwid_get_store_shortcode_widgets()
1605
- {
1606
- if (get_option('ecwid_use_new_horizontal_categories')) return false;
1607
-
1608
-
1609
- $page_contents = get_post(Ecwid_Store_Page::get_current_store_page_id())->post_content;
1610
- $shortcodes = ecwid_find_shortcodes($page_contents, 'ecwid');
1611
-
1612
- if (!$shortcodes) {
1613
- return null;
1614
- }
1615
-
1616
- $shortcode = $shortcodes[0];
1617
- $attributes = shortcode_parse_atts($shortcode[3]);
1618
-
1619
- if (!isset($attributes['widgets'])) {
1620
- return null;
1621
- }
1622
-
1623
- return explode(' ', $attributes['widgets']);
1624
- }
1625
-
1626
  function ecwid_abs_intval($value) {
1627
  if (!is_null($value))
1628
  return abs(intval($value));
@@ -2170,11 +2242,16 @@ function ecwid_get_product_seo_url( $product_id ) {
2170
  global $ecwid_products;
2171
 
2172
  return $ecwid_products->get_product_link( $product_id );
2173
- } else {
2174
  $api = new Ecwid_Api_V3();
2175
  if ( $api->is_api_available() ) {
 
 
 
 
 
 
2176
  $product = $api->get_product( $product_id );
2177
-
2178
  return $product->url;
2179
  }
2180
  }
@@ -2232,7 +2309,11 @@ function ecwid_appearance_settings_do_page() {
2232
  }
2233
 
2234
  function ecwid_debug_do_page() {
2235
-
 
 
 
 
2236
  $remote_get_results = wp_remote_get( 'http://app.ecwid.com/api/v1/' . get_ecwid_store_id() . '/profile' );
2237
 
2238
  $api_v3_profile_results = wp_remote_get( 'https://app.ecwid.com/api/v3/' . get_ecwid_store_id() . '/profile?token=' . Ecwid_Api_V3::get_token() );
@@ -2627,16 +2708,15 @@ function ecwid_hmacsha1($data, $key) {
2627
  }
2628
  }
2629
 
2630
- function ecwid_can_display_html_catalog()
2631
  {
2632
  if (!isset($_GET['_escaped_fragment_'])) return;
2633
 
2634
- $api = ecwid_new_product_api();
2635
- if (!$api) return;
2636
-
2637
- $profile = $api->get_profile();
2638
- if (!$profile) return;
2639
- return $profile['closed'] != true;
2640
  }
2641
 
2642
  function ecwid_get_default_pb_size() {
@@ -2655,16 +2735,32 @@ function ecwid_update_store_id( $new_store_id ) {
2655
  update_option( 'ecwid_store_id', $new_store_id );
2656
  update_option( 'ecwid_is_api_enabled', 'off' );
2657
  update_option( 'ecwid_api_check_time', 0 );
 
 
2658
 
2659
  do_action('ecwid_update_store_id', $new_store_id);
2660
  }
2661
 
 
2662
  function ecwid_is_paid_account()
2663
  {
2664
- return ecwid_is_api_enabled() && get_ecwid_store_id() != ECWID_DEMO_STORE_ID;
 
 
 
 
 
 
 
 
 
 
 
 
 
2665
  }
2666
 
2667
- function ecwid_is_api_enabled()
2668
  {
2669
  $ecwid_is_api_enabled = get_option('ecwid_is_api_enabled');
2670
  $ecwid_api_check_time = get_option('ecwid_api_check_time');
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 Team
8
+ Version: 5.4
9
  Author URI: http://www.ecwid.com?source=wporg
10
  */
11
 
56
  }
57
 
58
  require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-nav-menus.php';
59
+ require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-ajax-defer-renderer.php';
60
 
61
  require_once ECWID_PLUGIN_DIR . 'lib/ecwid_platform.php';
62
  require_once ECWID_PLUGIN_DIR . 'lib/ecwid_api_v3.php';
63
+ require_once ECWID_PLUGIN_DIR . 'lib/ecwid_product.php';
64
+ require_once ECWID_PLUGIN_DIR . 'lib/ecwid_category.php';
65
 
66
 
67
  // Older versions of Google XML Sitemaps plugin generate it in admin, newer in site area, so the hook should be assigned in both of them
433
  }
434
 
435
  function ecwid_404_on_broken_escaped_fragment() {
436
+ if (!isset($_GET['_escaped_fragment_'])) {
437
  return;
438
  }
439
 
440
+ if ( !Ecwid_Api_V3::is_available() && !ecwid_is_apiv1_enabled() ) {
441
  return;
442
  }
443
 
444
  $params = ecwid_parse_escaped_fragment($_GET['_escaped_fragment_']);
 
445
 
446
  if (isset($params['mode']) && !empty($params['mode']) && isset($params['id'])) {
447
  $result = array();
448
  $is_root_cat = $params['mode'] == 'category' && $params['id'] == 0;
449
  if ($params['mode'] == 'product') {
450
+ $result = Ecwid_Product::get_by_id( $params['id'] );
451
  } elseif (!$is_root_cat && $params['mode'] == 'category') {
452
+ $result = Ecwid_Category::get_by_id( $params['id'] );
453
  }
454
 
455
  if (!$is_root_cat && empty($result)) {
462
  }
463
 
464
  function ecwid_503_on_store_closed() {
 
 
 
465
 
466
+ if ( !isset( $_GET['_escaped_fragment_'] ) ) {
467
  return;
468
  }
469
 
470
+ if ( ecwid_is_store_closed() ) {
471
+ header( 'HTTP/1.1 503 Service Temporarily Unavailable' );
472
+ header( 'Status: 503 Service Temporarily Unavailable' );
473
+ }
474
+ }
475
 
476
+ function ecwid_is_store_closed()
477
+ {
478
+ if ( Ecwid_Api_V3::is_available() ) {
479
+ $api = new Ecwid_Api_V3();
480
+ $profile = $api->get_store_profile();
481
+
482
+ return @$profile->settings->closed;
483
+ } else if ( ecwid_is_apiv1_enabled() ) {
484
+ $api = ecwid_new_product_api();
485
+
486
+ $profile = $api->get_profile();
487
+
488
+ return $profile->closed;
489
  }
490
+
491
+ return false;
492
  }
493
 
 
494
 
495
+ function ecwid_backward_compatibility() {
496
 
497
  // Backward compatibility with 1.1.2 and earlier
498
  if (isset($_GET['ecwid_product_id']) || isset($_GET['ecwid_category_id'])) {
516
  if (get_post_status($page_id) == 'publish') {
517
  require_once ECWID_PLUGIN_DIR . 'includes/class-ecwid-sitemap-builder.php';
518
 
519
+ $sitemap = new EcwidSitemapBuilder(Ecwid_Store_Page::get_store_url(), $callback);
520
 
521
  $sitemap->generate();
522
  }
575
  add_option('ecwid_plugin_version', $current_version);
576
 
577
  add_option('ecwid_use_chameleon', false);
578
+
 
 
579
  // Called in Ecwid_Seo_Links->on_fresh_install
580
  do_action( 'ecwid_on_fresh_install' );
581
 
583
 
584
  do_action('ecwid_plugin_upgraded', array( 'old' => $stored_version, 'new' => $current_version ) );
585
  update_option('ecwid_plugin_version', $current_version);
586
+
 
 
587
  do_action( 'ecwid_on_plugin_upgrade' );
588
  }
589
 
616
 
617
  add_option(Ecwid_Widget_Floating_Shopping_Cart::OPTION_DISPLAY_POSITION, '');
618
 
619
+ // Since 5.4
620
+ delete_option('ecwid_use_new_search');
621
+ delete_option('ecwid_use_new_categories');
622
+ // /Since 5.4
623
+
624
  Ecwid_Config::load_from_ini();
 
625
 
626
  add_option( 'force_scriptjs_render', false );
627
 
726
  {
727
  global $seo_ultimate;
728
 
729
+ if (!$seo_ultimate) return;
730
+ if (!Ecwid_Store_Page::is_store_page()) return;
731
+
732
+ if ( isset( $_GET['_escaped_fragment_'] ) || ( Ecwid_Seo_Links::is_enabled() && Ecwid_Seo_Links::is_product_browser_url() ) ) {
733
  remove_action('template_redirect', array($seo_ultimate->modules['titles'], 'before_header'), 0);
734
  remove_action('wp_head', array($seo_ultimate->modules['titles'], 'after_header'), 1000);
735
  remove_action('su_head', array($seo_ultimate->modules['meta-descriptions'], 'head_tag_output'));
805
  update_option('ecwid_last_api_cache_check', time());
806
  }
807
 
808
+ function ecwid_invalidate_cache( $full_reset = false)
809
  {
 
810
 
811
+ if ( $full_reset ) {
812
+ EcwidPlatform::invalidate_categories_cache_from(time());
813
+ EcwidPlatform::invalidate_products_cache_from(time());
814
+ EcwidPlatform::cache_reset( Ecwid_Api_V3::PROFILE_CACHE_NAME );
815
+
816
+ return;
817
+ }
818
+
819
+ if (Ecwid_Api_V3::is_available()) {
820
+ $api = new Ecwid_Api_V3();
821
+
822
  $stats = $api->get_store_update_stats();
823
 
824
  if ($stats) {
944
 
945
  function ecwid_ajax_crawling_fragment() {
946
 
947
+ if ( !Ecwid_Api_V3::is_available() && !ecwid_is_apiv1_enabled() ) return;
948
 
949
  if ( isset( $_GET['_escaped_fragment_'] ) ) return;
950
 
967
  echo '<link rel="dns-prefetch" href="//app.ecwid.com/">' . PHP_EOL;
968
  echo '<link rel="dns-prefetch" href="//ecwid-static-ru.r.worldssl.net">' . PHP_EOL;
969
  echo '<link rel="dns-prefetch" href="//ecwid-images-ru.r.worldssl.net">' . PHP_EOL;
970
+
971
  if (!Ecwid_Store_Page::is_store_page() && ecwid_is_store_page_available()) {
972
  $page_url = Ecwid_Store_Page::get_store_url();
973
  echo '<link rel="prefetch" href="' . $page_url . '" />' . PHP_EOL;
987
 
988
  function ecwid_canonical() {
989
 
990
+ $link = false;
991
+ if ( ecwid_is_applicable_escaped_fragment() ) {
 
992
 
993
+ $params = ecwid_parse_escaped_fragment($_GET['_escaped_fragment_']);
994
 
995
+ if ($params['mode'] == 'product') {
996
+ $product = Ecwid_Product::get_by_id( $params['id'] );
997
+ $link = ecwid_get_product_url($product);
998
+ } else if ($params['mode'] == 'category') {
999
+ $category = Ecwid_Category::get_by_id( $params['id'] );
1000
+ $link = ecwid_get_category_url($category);
1001
+ }
1002
+ } else if ( Ecwid_Seo_Links::is_product_browser_url() ) {
1003
+ $params = Ecwid_Seo_Links::maybe_extract_html_catalog_params();
1004
 
1005
+ if ($params) {
1006
+ if ( $params['mode'] == 'product' ) {
1007
+ $product = Ecwid_Product::get_by_id( $params['id'] );
1008
+ $link = $product->url;
1009
+ } elseif ( $params['mode'] == 'category' ) {
1010
+ $category = Ecwid_Category::get_by_id( $params['id'] );
1011
+ $link = $category->url;
1012
+ }
1013
+ }
1014
  }
1015
 
1016
+ if (!$link) {
1017
+ return;
1018
+ }
1019
+
1020
+ if ($link) {
1021
+ echo '<link rel="canonical" href="' . esc_attr($link) . '" />' . PHP_EOL;
1022
+ }
1023
  }
1024
 
1025
  function ecwid_is_applicable_escaped_fragment() {
1026
 
1027
+ if (!Ecwid_Api_V3::is_available() && !ecwid_is_apiv1_enabled()) {
1028
+ return false;
1029
+ }
1030
+
1031
+ if (!isset($_GET['_escaped_fragment_'])) return false;
1032
 
1033
  $params = ecwid_parse_escaped_fragment($_GET['_escaped_fragment_']);
1034
  if (!$params) return false;
1042
 
1043
  $params = array();
1044
 
1045
+ $description = false;
1046
  if ( ecwid_is_applicable_escaped_fragment() ) {
1047
  $params = ecwid_parse_escaped_fragment( $_GET['_escaped_fragment_'] );
1048
+
1049
+ if ($params['mode'] == 'product') {
1050
+ $product = Ecwid_Product::get_by_id( $params['id'] );
1051
+ $description = $product->description;
1052
+ } elseif ($params['mode'] == 'category') {
1053
+ $category = Ecwid_Category::get_by_id( $params['id'] );
1054
+ $description = $category->description;
1055
+ }
1056
  } else if ( Ecwid_Seo_Links::is_product_browser_url() ) {
1057
  $params = Ecwid_Seo_Links::maybe_extract_html_catalog_params();
1058
+ if ($params) {
1059
+
1060
+ if ( $params['mode'] == 'product' ) {
1061
+ $product = Ecwid_Product::get_by_id( $params['id'] );
1062
 
1063
+ if ( $product && isset( $product->seoDescription ) ) {
1064
+ $description = $product->seoDescription;
1065
+ }
1066
+
1067
+ if (!$description && $product && isset( $product->description ) ) {
1068
+ $description = $product->description;
1069
+ }
1070
+ } elseif ( $params['mode'] == 'category' ) {
1071
+ $category = Ecwid_Category::get_by_id( $params['id'] );
1072
 
1073
+ if ( $category ) {
1074
+ if ( isset( $category->seoDescription ) ) {
1075
+ $description = $category->seoDescription;
1076
+ }
1077
+
1078
+ if (!$description && isset( $category->description ) ) {
1079
+ $description = $category->description;
1080
+ }
1081
+ }
1082
+ }
1083
+ }
1084
+ }
1085
+
1086
+ if ( !$description ) {
1087
+ return;
1088
+ }
1089
 
1090
  $description = ecwid_trim_description($description);
1091
 
1124
  update_option('ecwid_show_vote_message', false);
1125
  }
1126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1127
  function ecwid_get_title_separator()
1128
  {
1129
  $sep = apply_filters('document_title_separator', '|');
1164
 
1165
  if ( ecwid_is_applicable_escaped_fragment() ) {
1166
  $params = ecwid_parse_escaped_fragment( $_GET['_escaped_fragment_'] );
1167
+ if ( empty( $params ) ) return;
 
 
 
 
1168
 
1169
+ $ecwid_seo_title = '';
1170
 
1171
+ $separator = ecwid_get_title_separator();
1172
 
1173
+ if ( isset( $params['mode'] ) && ! empty( $params['mode'] ) ) {
1174
+ if ( $params['mode'] == 'product' ) {
1175
+ if ( isset( $params['category'] ) && ! empty( $params['category'] ) ) {
1176
+ $product = Ecwid_Product::get_by_id( $params['id'] );
1177
+ $category = Ecwid_Category::get_by_id( $params['category'] );
1178
 
1179
+ if ( $product ) {
1180
+ $ecwid_seo_title = $product->name;
1181
+ if ( $category ) {
1182
+ $ecwid_seo_title .= ' ' . $separator . $category->name;
1183
+ }
1184
+ }
1185
+ } elseif ( empty( $params['category'] ) ) {
1186
+ $product = Ecwid_Product::get_by_id( $params['id'] );
1187
+
1188
+ if ( $product ) {
1189
+ $ecwid_seo_title = $product->name;
1190
+
1191
+ if ( $product->defaultCategoryId ) {
1192
+ $category = Ecwid_Category::get_by_id( $product->defaultCategoryId );
1193
  $ecwid_seo_title .= ' ' . $separator . ' ';
1194
+ $ecwid_seo_title .= $category->name;
1195
  }
1196
  }
1197
  }
1198
+ } elseif ( $params['mode'] == 'category' ) {
1199
+ $ecwid_category = Ecwid_Category::get_by_id( $params['id'] );
1200
+
1201
+ if ($ecwid_category) {
1202
+ $ecwid_seo_title = $ecwid_category->name;
1203
+ }
1204
+ }
1205
+ }
1206
+
1207
+ } else if ( Ecwid_Seo_Links::is_product_browser_url() && Ecwid_Api_V3::is_available() ) {
1208
+
1209
+ $params = Ecwid_Seo_Links::maybe_extract_html_catalog_params();
1210
+
1211
+ if ( $params ) {
1212
+ $api = new Ecwid_Api_V3();
1213
+
1214
+ if ( $params['mode'] == 'product' ) {
1215
+ $product = Ecwid_Product::get_by_id( $params['id'] );
1216
+ if ( isset( $product->seoTitle ) ) {
1217
+ $ecwid_seo_title = $product->seoTitle;
1218
+ } else {
1219
+ $ecwid_seo_title = $product->name;
1220
+ }
1221
+
1222
+ if ( $product->defaultCategoryId ) {
1223
+ $category = $api->get_category( $product->defaultCategoryId );
1224
+ if ( $category ) {
1225
+ $ecwid_seo_title .= ' ' . ecwid_get_title_separator() . ' ' . $category->name;
1226
+ }
1227
+ }
1228
+ } else if ( $params['mode'] == 'category' ) {
1229
+ $category = $api->get_category( $params['id'] );
1230
+ $ecwid_seo_title = $category->name;
1231
  }
 
 
 
 
1232
  }
1233
  }
1234
 
1235
+
1236
  if ( ! empty( $ecwid_seo_title ) ) {
1237
  return $ecwid_seo_title;
1238
  }
1240
  return "";
1241
  }
1242
 
1243
+ add_filter('oembed_endpoint_url', 'ecwid_oembed_url', 10, 3);
1244
+
1245
+ function ecwid_oembed_url( $url, $permalink, $format ) {
1246
+
1247
+ if (! Ecwid_Seo_Links::is_product_browser_url() ) {
1248
+ return $url;
1249
+ }
1250
+
1251
+ $params = Ecwid_Seo_Links::maybe_extract_html_catalog_params();
1252
+
1253
+ if ( $params['mode'] == 'product' ){
1254
+ $product = Ecwid_Product::get_by_id( $params['id'] );
1255
+ $permalink = $product->url;
1256
+ } else if ( $params['mode'] == 'category' ) {
1257
+ $category = Ecwid_Category::get_by_id( $params['id'] );
1258
+ $permalink = $category->url;
1259
+ }
1260
+
1261
+ $url = add_query_arg( array(
1262
+ 'url' => urlencode( $permalink ),
1263
+ 'format' => ( 'json' !== $format ) ? $format : false,
1264
+ ), $url );
1265
+
1266
+ return $url;
1267
+ }
1268
+
1269
+
1270
  function ecwid_add_credits($powered_by)
1271
  {
1272
  if (!ecwid_is_paid_account()) {
1371
  }
1372
 
1373
  function ecwid_get_search_js_code() {
1374
+ return 'xSearch("style=");';
 
 
 
 
1375
  }
1376
 
1377
  function _ecwid_get_single_product_widget_parts_v1($attributes) {
1511
  function ecwid_ajax_get_product_info() {
1512
  $id = $_GET['id'];
1513
 
1514
+ $product = Ecwid_Product::get_by_id($id);
1515
+
1516
+ echo json_encode($product);
 
 
 
1517
 
1518
  exit();
1519
  }
1695
  delete_option("ecwid_use_chameleon");
1696
  }
1697
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1698
  function ecwid_abs_intval($value) {
1699
  if (!is_null($value))
1700
  return abs(intval($value));
2242
  global $ecwid_products;
2243
 
2244
  return $ecwid_products->get_product_link( $product_id );
2245
+ } elseif (Ecwid_Api_V3::is_available()) {
2246
  $api = new Ecwid_Api_V3();
2247
  if ( $api->is_api_available() ) {
2248
+ $product = Ecwid_Product::get_by_id( $product_id );
2249
+
2250
+ if ($product->get_seo_link()) {
2251
+ return $product->get_seo_link();
2252
+ }
2253
+
2254
  $product = $api->get_product( $product_id );
 
2255
  return $product->url;
2256
  }
2257
  }
2309
  }
2310
 
2311
  function ecwid_debug_do_page() {
2312
+
2313
+ if ( array_key_exists( 'reset_cache', $_GET ) ) {
2314
+ ecwid_invalidate_cache(true );
2315
+ }
2316
+
2317
  $remote_get_results = wp_remote_get( 'http://app.ecwid.com/api/v1/' . get_ecwid_store_id() . '/profile' );
2318
 
2319
  $api_v3_profile_results = wp_remote_get( 'https://app.ecwid.com/api/v3/' . get_ecwid_store_id() . '/profile?token=' . Ecwid_Api_V3::get_token() );
2708
  }
2709
  }
2710
 
2711
+ function ecwid_should_display_escaped_fragment_catalog()
2712
  {
2713
  if (!isset($_GET['_escaped_fragment_'])) return;
2714
 
2715
+ if ( Ecwid_Api_V3::is_available() || ecwid_is_apiv1_enabled() ) {
2716
+ return !ecwid_is_store_closed();
2717
+ }
2718
+
2719
+ return false;
 
2720
  }
2721
 
2722
  function ecwid_get_default_pb_size() {
2735
  update_option( 'ecwid_store_id', $new_store_id );
2736
  update_option( 'ecwid_is_api_enabled', 'off' );
2737
  update_option( 'ecwid_api_check_time', 0 );
2738
+
2739
+ ecwid_invalidate_cache( true );
2740
 
2741
  do_action('ecwid_update_store_id', $new_store_id);
2742
  }
2743
 
2744
+
2745
  function ecwid_is_paid_account()
2746
  {
2747
+ if ( Ecwid_Api_V3::is_available() ) {
2748
+ $api = new Ecwid_Api_V3();
2749
+
2750
+ $profile = $api->get_store_profile();
2751
+
2752
+ return $profile
2753
+ && property_exists( $profile, 'account')
2754
+ && property_exists( $profile->account, 'availableFeatures' )
2755
+ && is_array( $profile->account->availableFeatures )
2756
+ && in_array(
2757
+ 'PREMIUM', $profile->account->availableFeatures
2758
+ );
2759
+ }
2760
+ return ecwid_is_apiv1_enabled() && get_ecwid_store_id() != ECWID_DEMO_STORE_ID;
2761
  }
2762
 
2763
+ function ecwid_is_apiv1_enabled()
2764
  {
2765
  $ecwid_is_api_enabled = get_option('ecwid_is_api_enabled');
2766
  $ecwid_api_check_time = get_option('ecwid_api_check_time');
includes/class-ecwid-admin.php CHANGED
@@ -107,7 +107,7 @@ class Ecwid_Admin {
107
  'ecwid-appearance',
108
  'ecwid-advanced',
109
  'ecwid-help',
110
- 'ecwid_debug',
111
  'ecwid-sync'
112
  );
113
 
107
  'ecwid-appearance',
108
  'ecwid-advanced',
109
  'ecwid-help',
110
+ 'ecwid-debug',
111
  'ecwid-sync'
112
  );
113
 
includes/class-ecwid-ajax-defer-renderer.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Ecwid_Ajax_Defer_Renderer {
4
+
5
+ const ALWAYS_ON = 'on';
6
+ const ALWAYS_OFF = 'off';
7
+ const AUTO = 'auto';
8
+ const OPTION_DEFER_RENDERING = 'ecwid_ajax_defer_rendering';
9
+ const FILTER_ENABLED = 'ecwid_enable_defer_rendering';
10
+
11
+ protected $_already_enabled = false;
12
+
13
+ protected static $instance = null;
14
+
15
+ public static function get_instance()
16
+ {
17
+ return self::$instance = new Ecwid_Ajax_Defer_Renderer();
18
+ }
19
+
20
+ protected function __construct()
21
+ {
22
+ add_option( self::OPTION_DEFER_RENDERING, self::AUTO );
23
+ $this->init();
24
+
25
+ add_action( 'ecwid_on_plugin_upgrade', array( $this, 'plugin_upgrade' ) );
26
+ }
27
+
28
+ public function init()
29
+ {
30
+ if ( $this->is_enabled() && !$this->_already_enabled ) {
31
+ add_filter( 'ecwid_disable_widgets', '__return_true' );
32
+ add_filter( 'ecwid_shortcode_custom_renderer', array( $this, 'get_custom_renderer' ) );
33
+ add_filter( 'the_content', array( $this, 'add_shortcodes' ) );
34
+ $this->_already_enabled = true;
35
+ }
36
+ }
37
+
38
+ public function plugin_upgrade()
39
+ {
40
+ $old_option = 'ecwid_defer_rendering';
41
+
42
+ $value = get_option( $old_option , null );
43
+
44
+ if ( !is_null( $value ) ) {
45
+ if ( !$value ) {
46
+ update_option( self::OPTION_DEFER_RENDERING, self::ALWAYS_OFF );
47
+ }
48
+
49
+ delete_option( $old_option );
50
+ }
51
+ }
52
+
53
+
54
+ public function is_enabled()
55
+ {
56
+ $option_value = get_option( self::OPTION_DEFER_RENDERING );
57
+
58
+ if ( $option_value == self::AUTO ) {
59
+ $filter_results = apply_filters( self::FILTER_ENABLED, false );
60
+
61
+ return $filter_results;
62
+ } else if ( $option_value == self::ALWAYS_ON ) {
63
+ return true;
64
+ } else {
65
+ return false;
66
+ }
67
+ }
68
+
69
+ public function get_custom_renderer() {
70
+ return array($this, 'render_shortcode');
71
+ }
72
+
73
+ public function render_shortcode($shortcode) {
74
+
75
+ if ( $shortcode instanceof Ecwid_Shortcode_Base ) {
76
+ return $shortcode->render_placeholder() . $this->_render_shortcode_script( $shortcode );
77
+ }
78
+
79
+ return '';
80
+ }
81
+
82
+ public function add_shortcodes($content) {
83
+ $ecwid_store_id = get_ecwid_store_id();
84
+ $before = <<<HTML
85
+ <script>
86
+ ecwid_shortcodes = [];
87
+ </script>
88
+ HTML;
89
+ $after = <<<HTML
90
+ <script>
91
+ window.ecwid_script_defer = true;
92
+ window.ecwid_dynamic_widgets = true;
93
+
94
+ if (typeof Ecwid != 'undefined' && Ecwid.destroy) Ecwid.destroy();
95
+
96
+ if (typeof ecwid_shortcodes != 'undefined') {
97
+ window._xnext_initialization_scripts = ecwid_shortcodes;
98
+
99
+ if (!document.getElementById('ecwid-script')) {
100
+ var script = document.createElement('script');
101
+ script.charset = 'utf-8';
102
+ script.type = 'text/javascript';
103
+ script.src = 'https://app.ecwid.com/script.js?$ecwid_store_id';
104
+ script.id = 'ecwid-script'
105
+
106
+ document.body.appendChild(script);
107
+
108
+ var catalog = document.getElementById('ecwid-html-catalog-$ecwid_store_id');
109
+ catalog.parentElement.removeChild(catalog);
110
+ } else {
111
+ ecwid_onBodyDone();
112
+ }
113
+
114
+ }
115
+ </script>
116
+ HTML;
117
+ return $before . $content . $after;
118
+ }
119
+
120
+ protected function _render_shortcode_script(Ecwid_Shortcode_Base $shortcode) {
121
+
122
+ $args = $shortcode->build_params_string();
123
+ $id = $shortcode->get_html_id();
124
+ $widgetType = substr($shortcode->get_ecwid_widget_function_name(), 1);
125
+ if ($widgetType == 'Search') {
126
+ $widgetType = 'SearchWidget';
127
+ }
128
+ $store_id = get_ecwid_store_id();
129
+
130
+ $code = <<<HTML
131
+ <script type="text/javascript">
132
+ ecwid_shortcodes[ecwid_shortcodes.length] = {
133
+ widgetType: '$widgetType',
134
+ id: '$id',
135
+ arg: [$args]
136
+ };
137
+ </script>
138
+ HTML;
139
+ return $code;
140
+ }
141
+ }
includes/class-ecwid-integration-aiosp.php CHANGED
@@ -7,16 +7,23 @@ class Ecwid_Integration_All_In_One_SEO_Pack
7
 
8
  public function __construct()
9
  {
10
- add_action( 'wp', array( $this, 'disable_seo_on_escaped_fragment' ) );
11
 
12
  add_filter( 'aiosp_sitemap_extra', array( $this, 'aiosp_hook_sitemap_extra' ) );
13
  add_filter( 'aiosp_sitemap_custom_ecwid', array( $this, 'aiosp_hook_sitemap_content') );
14
  }
15
 
16
  // Disable titles, descriptions and canonical link on ecwid _escaped_fragment_ pages
17
- public function disable_seo_on_escaped_fragment()
18
  {
19
- if (!array_key_exists('_escaped_fragment_', $_GET) || !Ecwid_Store_Page::is_store_page()) {
 
 
 
 
 
 
 
20
  return;
21
  }
22
 
7
 
8
  public function __construct()
9
  {
10
+ add_action( 'wp', array( $this, 'disable_seo_if_needed' ) );
11
 
12
  add_filter( 'aiosp_sitemap_extra', array( $this, 'aiosp_hook_sitemap_extra' ) );
13
  add_filter( 'aiosp_sitemap_custom_ecwid', array( $this, 'aiosp_hook_sitemap_content') );
14
  }
15
 
16
  // Disable titles, descriptions and canonical link on ecwid _escaped_fragment_ pages
17
+ public function disable_seo_if_needed()
18
  {
19
+ if (! Ecwid_Store_Page::is_store_page() ) {
20
+ return;
21
+ }
22
+
23
+ $is_escaped_fragment = array_key_exists('_escaped_fragment_', $_GET);
24
+ $is_seo_links_store_page = Ecwid_Seo_Links::is_enabled() && Ecwid_Seo_Links::is_product_browser_url();
25
+
26
+ if ( !$is_escaped_fragment && !$is_seo_links_store_page ) {
27
  return;
28
  }
29
 
includes/class-ecwid-seo-links.php CHANGED
@@ -48,7 +48,7 @@ class Ecwid_Seo_Links {
48
  }
49
 
50
  public function redirect_escaped_fragment() {
51
- if ( ecwid_can_display_html_catalog() ) {
52
  $params = ecwid_parse_escaped_fragment( $_GET[ '_escaped_fragment_' ] );
53
 
54
  if ( !isset( $params[ 'mode' ] ) ) {
48
  }
49
 
50
  public function redirect_escaped_fragment() {
51
+ if ( ecwid_should_display_escaped_fragment_catalog() ) {
52
  $params = ecwid_parse_escaped_fragment( $_GET[ '_escaped_fragment_' ] );
53
 
54
  if ( !isset( $params[ 'mode' ] ) ) {
includes/class-ecwid-sitemap-builder.php CHANGED
@@ -11,7 +11,6 @@ class EcwidSitemapBuilder {
11
  public function __construct($base_url, $callback, $api) {
12
  $this->callback = $callback;
13
  $this->base_url = $base_url;
14
- $this->api = $api;
15
  }
16
 
17
  public function generate() {
11
  public function __construct($base_url, $callback, $api) {
12
  $this->callback = $callback;
13
  $this->base_url = $base_url;
 
14
  }
15
 
16
  public function generate() {
includes/class-ecwid-store-page.php CHANGED
@@ -10,17 +10,10 @@ class Ecwid_Store_Page {
10
 
11
  public static function get_product_url( $id )
12
  {
13
- if ( Ecwid_Products::is_enabled() ) {
14
- global $ecwid_products;
15
-
16
- $url = $ecwid_products->get_product_link( $id );
17
-
18
- if ( $url ) {
19
- return $url;
20
- }
21
- }
22
-
23
- $url = self::get_product_url_from_api( $id );
24
  if ( $url ) {
25
  return $url;
26
  }
@@ -29,9 +22,10 @@ class Ecwid_Store_Page {
29
  }
30
 
31
  public static function get_product_url_from_api( $id ) {
32
- $api = new Ecwid_Api_V3();
 
33
 
34
- if ( $api->is_available() ) {
35
 
36
  $product = $api->get_product( $id );
37
 
@@ -50,12 +44,21 @@ class Ecwid_Store_Page {
50
 
51
  public static function get_category_url( $id )
52
  {
 
 
 
 
 
 
 
 
 
53
  if ( $id == 0 ) {
54
  return self::get_store_url();
55
  }
56
 
57
- $api = new Ecwid_Api_V3();
58
- if ( $api->is_available() ) {
59
 
60
  $category = $api->get_category( $id );
61
 
10
 
11
  public static function get_product_url( $id )
12
  {
13
+ $product = Ecwid_Product::get_by_id( $id );
14
+
15
+ $url = $product->link;
16
+
 
 
 
 
 
 
 
17
  if ( $url ) {
18
  return $url;
19
  }
22
  }
23
 
24
  public static function get_product_url_from_api( $id ) {
25
+
26
+ if ( Ecwid_Api_V3::is_available() ) {
27
 
28
+ $api = new Ecwid_Api_V3();
29
 
30
  $product = $api->get_product( $id );
31
 
44
 
45
  public static function get_category_url( $id )
46
  {
47
+ $category = Ecwid_Category::get_by_id( $id );
48
+
49
+ $url = $category->link;
50
+
51
+ if ( $url ) {
52
+ return $url;
53
+ }
54
+
55
+
56
  if ( $id == 0 ) {
57
  return self::get_store_url();
58
  }
59
 
60
+ if ( Ecwid_Api_V3::is_available() ) {
61
+ $api = new Ecwid_Api_V3();
62
 
63
  $category = $api->get_category( $id );
64
 
includes/shortcodes/class-ecwid-shortcode-categories.php CHANGED
@@ -13,11 +13,7 @@ class Ecwid_Shortcode_Categories extends Ecwid_Shortcode_Base {
13
  }
14
 
15
  public function get_ecwid_widget_function_name() {
16
- if ( get_option('ecwid_use_new_horizontal_categories') ) {
17
- return 'xCategoriesV2';
18
- } else {
19
- return 'xCategories';
20
- }
21
  }
22
 
23
  public function render_placeholder() {
13
  }
14
 
15
  public function get_ecwid_widget_function_name() {
16
+ return 'xCategoriesV2';
 
 
 
 
17
  }
18
 
19
  public function render_placeholder() {
includes/shortcodes/class-ecwid-shortcode-productbrowser.php CHANGED
@@ -31,9 +31,9 @@ class Ecwid_Shortcode_ProductBrowser extends Ecwid_Shortcode_Base {
31
  $store_id = get_ecwid_store_id();
32
 
33
  $plain_content = '';
34
-
35
  $html_catalog_params = false;
36
- if ( ecwid_can_display_html_catalog() ) {
37
  $html_catalog_params = ecwid_parse_escaped_fragment($_GET['_escaped_fragment_']);
38
  } elseif ( Ecwid_Seo_Links::is_enabled() && Ecwid_Store_Page::is_store_page() ) {
39
  $html_catalog_params = Ecwid_Seo_Links::maybe_extract_html_catalog_params();
@@ -46,7 +46,7 @@ class Ecwid_Shortcode_ProductBrowser extends Ecwid_Shortcode_Base {
46
  $classname = $this->_get_html_class_name();
47
  $result = <<<HTML
48
  <div id="ecwid-store-$store_id" class="ecwid-shopping-cart-$classname">
49
- {$plain_content}
50
  </div>
51
  HTML;
52
 
31
  $store_id = get_ecwid_store_id();
32
 
33
  $plain_content = '';
34
+
35
  $html_catalog_params = false;
36
+ if ( ecwid_should_display_escaped_fragment_catalog() ) {
37
  $html_catalog_params = ecwid_parse_escaped_fragment($_GET['_escaped_fragment_']);
38
  } elseif ( Ecwid_Seo_Links::is_enabled() && Ecwid_Store_Page::is_store_page() ) {
39
  $html_catalog_params = Ecwid_Seo_Links::maybe_extract_html_catalog_params();
46
  $classname = $this->_get_html_class_name();
47
  $result = <<<HTML
48
  <div id="ecwid-store-$store_id" class="ecwid-shopping-cart-$classname">
49
+ <div id="ecwid-html-catalog-$store_id">{$plain_content}</div>
50
  </div>
51
  HTML;
52
 
includes/shortcodes/class-ecwid-shortcode-search.php CHANGED
@@ -13,10 +13,6 @@ class Ecwid_Shortcode_Search extends Ecwid_Shortcode_Base {
13
  }
14
 
15
  public function get_ecwid_widget_function_name() {
16
- if (get_option('ecwid_use_new_search', false)) {
17
- return 'xSearch';
18
- } else {
19
- return 'xSearchPanel';
20
- }
21
  }
22
  }
13
  }
14
 
15
  public function get_ecwid_widget_function_name() {
16
+ return 'xSearch';
 
 
 
 
17
  }
18
  }
includes/themes.php CHANGED
@@ -60,7 +60,8 @@ function ecwid_apply_theme($theme_name = null)
60
  'uncode' => array( 'css-no-parent' ),
61
  'ribosome' => array( 'css' ),
62
  'optimizepress' => array( 'css' ),
63
- 'edge' => array( 'js', 'scroll' )
 
64
  );
65
  $generic_themes = apply_filters('ecwid_generic_themes', $generic_themes);
66
 
60
  'uncode' => array( 'css-no-parent' ),
61
  'ribosome' => array( 'css' ),
62
  'optimizepress' => array( 'css' ),
63
+ 'edge' => array( 'js', 'scroll' ),
64
+ 'newsmag' => array( 'css-no-parent')
65
  );
66
  $generic_themes = apply_filters('ecwid_generic_themes', $generic_themes);
67
 
includes/themes/class-ecwid-theme-trend.php CHANGED
@@ -64,8 +64,12 @@ if (typeof ecwid_shortcodes != 'undefined') {
64
  script.type = 'text/javascript';
65
  script.src = 'https://app.ecwid.com/script.js?$ecwid_store_id';
66
  script.id = 'ecwid-script'
67
- document.body.appendChild(script);
68
- } else {
 
 
 
 
69
  ecwid_onBodyDone();
70
  }
71
 
64
  script.type = 'text/javascript';
65
  script.src = 'https://app.ecwid.com/script.js?$ecwid_store_id';
66
  script.id = 'ecwid-script'
67
+
68
+ document.body.appendChild(script);
69
+
70
+ var catalog = document.getElementById('ecwid-html-catalog-$ecwid_store_id');
71
+ catalog.parentElement.removeChild(catalog);
72
+ } else {
73
  ecwid_onBodyDone();
74
  }
75
 
includes/widgets/class-ecwid-widget-floating-shopping-cart.php CHANGED
@@ -44,6 +44,10 @@ class Ecwid_Widget_Floating_Shopping_Cart extends WP_Widget {
44
 
45
  public function render() {
46
 
 
 
 
 
47
  $position = get_option(self::OPTION_DISPLAY_POSITION);
48
 
49
  if (!$position) {
44
 
45
  public function render() {
46
 
47
+ if (Ecwid_Ajax_Defer_Renderer::get_instance()->is_enabled()) {
48
+ return;
49
+ }
50
+
51
  $position = get_option(self::OPTION_DISPLAY_POSITION);
52
 
53
  if (!$position) {
includes/widgets/class-ecwid-widget-recently-viewed.php CHANGED
@@ -53,33 +53,31 @@ class Ecwid_Widget_Recently_Viewed extends WP_Widget {
53
 
54
  echo '<div class="ecwid-recently-viewed-products" data-ecwid-max="' . $instance['number_of_products'] . '">';
55
 
56
-
57
- $api = false;
58
- if (ecwid_is_api_enabled()) {
59
- $api = ecwid_new_product_api();
60
- }
61
-
62
  $counter = 0;
63
  $ids = array();
64
  if ($recently_viewed && isset($recently_viewed->products)) {
65
-
66
  for ($i = count($recently_viewed->products) - 1; $i >= 0; $i--) {
67
- $product = $recently_viewed->products[$i];
68
-
 
 
 
 
 
 
 
69
  $counter++;
70
- if (isset($product->id) && isset($product->link)) {
71
  $ids[] = $product->id;
72
  $hide = $counter > $instance['number_of_products'] ? ' hidden' : '';
73
 
74
  $force_image = '';
75
- if ($api) {
76
- $product_https = $api->get_product_https($product->id);
77
- if ( isset( $product_https['imageUrl'] ) ) {
78
- $force_image = $product_https['imageUrl'];
79
- }
80
  }
81
 
82
- $name = isset($product_https) ? $product_https['name']: '';
83
 
84
  echo <<<HTML
85
  <a class="product$hide" href="$product->link" alt="$name" title="$name">
53
 
54
  echo '<div class="ecwid-recently-viewed-products" data-ecwid-max="' . $instance['number_of_products'] . '">';
55
 
 
 
 
 
 
 
56
  $counter = 0;
57
  $ids = array();
58
  if ($recently_viewed && isset($recently_viewed->products)) {
59
+
60
  for ($i = count($recently_viewed->products) - 1; $i >= 0; $i--) {
61
+ $product = Ecwid_Product::get_by_id( $recently_viewed->products[$i]->id );
62
+
63
+ if (!$product) {
64
+ $product = Ecwid_Product::from_stdclass(
65
+ $recently_viewed->products[$i],
66
+ 'imageUrl', 'link'
67
+ );
68
+ }
69
+
70
  $counter++;
71
+ if ( isset( $product->id ) && isset( $product->link ) ) {
72
  $ids[] = $product->id;
73
  $hide = $counter > $instance['number_of_products'] ? ' hidden' : '';
74
 
75
  $force_image = '';
76
+ if ( isset( $product->imageUrl ) && strpos( $product->imageUrl, 'https://' ) == 0 ) {
77
+ $force_image = $product->imageUrl;
 
 
 
78
  }
79
 
80
+ $name = isset( $product->name ) ? $product->name : '';
81
 
82
  echo <<<HTML
83
  <a class="product$hide" href="$product->link" alt="$name" title="$name">
js/floating-shopping-cart.js CHANGED
@@ -17,10 +17,14 @@ var EcwidFloatingShoppingCart = function() {
17
  Ecwid.OnCartChanged.add(function(cartObj) {
18
  changeState(cartObj);
19
  });
 
 
 
 
20
  }
21
  };
22
 
23
- if ( typeof ecwid_floating_shopping_cart == 'undefined' ) {
24
  var ecwid_floating_shopping_cart = new EcwidFloatingShoppingCart();
25
  ecwid_floating_shopping_cart.init();
26
  }
17
  Ecwid.OnCartChanged.add(function(cartObj) {
18
  changeState(cartObj);
19
  });
20
+
21
+ jQuery(document).ready(function() {
22
+ jQuery('body').append(jQuery('.ecwid-float-icons'));
23
+ });
24
  }
25
  };
26
 
27
+ if ( typeof ecwid_floating_shopping_cart == 'undefined' && typeof Ecwid != 'undefined' ) {
28
  var ecwid_floating_shopping_cart = new EcwidFloatingShoppingCart();
29
  ecwid_floating_shopping_cart.init();
30
  }
languages/ecwid-shopping-cart-ru_RU.mo CHANGED
Binary file
languages/ecwid-shopping-cart-ru_RU.po CHANGED
@@ -1494,7 +1494,7 @@ msgid "Quantity"
1494
  msgstr "Количество"
1495
 
1496
  #: templates/product-popup.php:176
1497
- msgid "«Add to bag» button"
1498
  msgstr "Кнопка \"Купить\""
1499
 
1500
  #: templates/product-popup.php:196
1494
  msgstr "Количество"
1495
 
1496
  #: templates/product-popup.php:176
1497
+ msgid "«Buy now» button"
1498
  msgstr "Кнопка \"Купить\""
1499
 
1500
  #: templates/product-popup.php:196
lib/ecwid_api_v3.php CHANGED
@@ -9,8 +9,12 @@ class Ecwid_Api_V3
9
  const OAUTH_URL = 'https://my.ecwid.com/api/oauth/token';
10
 
11
  const TOKEN_OPTION_NAME = 'ecwid_oauth_token';
 
 
12
 
13
  public $store_id = null;
 
 
14
 
15
  public function __construct() {
16
 
@@ -22,10 +26,11 @@ class Ecwid_Api_V3
22
  $this->_products_api_url = $this->_api_url . $this->store_id . '/products';
23
  }
24
 
25
- public function is_available()
26
  {
27
- $token = $this->_load_token();
28
- if ( $token ) {
 
29
  return true;
30
  }
31
 
@@ -81,12 +86,18 @@ class Ecwid_Api_V3
81
 
82
  $result = json_decode( $result['data'] );
83
 
 
 
 
 
 
 
84
  return $result;
85
  }
86
 
87
  public function get_category($categoryId)
88
  {
89
- if (!isset($categoryId)) {
90
  return false;
91
  }
92
 
@@ -141,14 +152,15 @@ class Ecwid_Api_V3
141
  $result = EcwidPlatform::get_from_products_cache( $url );
142
 
143
  if (!$result) {
 
144
  $result = EcwidPlatform::fetch_url( $url );
145
- }
146
 
147
- if ($result['code'] != '200') {
148
- return false;
149
- }
150
 
151
- EcwidPlatform::store_in_products_cache( $url, $result );
 
152
 
153
  $result = json_decode($result['data']);
154
 
@@ -157,10 +169,10 @@ class Ecwid_Api_V3
157
 
158
  public function search_products($input_params) {
159
  $params = array('token');
160
- $passthru = array( 'updatedFrom', 'offset', 'limit', 'sortBy', 'keyword', 'baseUrl', 'cleanUrls' );
161
  foreach ($passthru as $name) {
162
  if ( array_key_exists( $name, $input_params ) ) {
163
- $params[$name] = $input_params[$name];
164
  }
165
  }
166
 
@@ -180,15 +192,22 @@ class Ecwid_Api_V3
180
  $result = EcwidPlatform::get_from_products_cache( $url );
181
  if (!$result ) {
182
  $result = EcwidPlatform::fetch_url( $url );
183
- }
 
 
184
 
185
- if ($result['code'] != '200') {
186
- return false;
187
  }
188
 
189
- EcwidPlatform::store_in_products_cache( $url, $result );
190
 
191
  $result = json_decode($result['data']);
 
 
 
 
 
 
 
192
  return $result;
193
  }
194
 
@@ -334,6 +353,12 @@ class Ecwid_Api_V3
334
 
335
  public function get_store_profile() {
336
 
 
 
 
 
 
 
337
  $url = $this->_api_url . $this->store_id . '/profile';
338
 
339
  $params = array(
@@ -343,7 +368,11 @@ class Ecwid_Api_V3
343
  $url = $this->build_request_url($url, $params);
344
  $result = EcwidPlatform::fetch_url($url);
345
 
346
- return json_decode($result['data']);
 
 
 
 
347
  }
348
 
349
  public function create_store()
9
  const OAUTH_URL = 'https://my.ecwid.com/api/oauth/token';
10
 
11
  const TOKEN_OPTION_NAME = 'ecwid_oauth_token';
12
+
13
+ const PROFILE_CACHE_NAME = 'apiv3_store_profile';
14
 
15
  public $store_id = null;
16
+
17
+ protected static $profile = null;
18
 
19
  public function __construct() {
20
 
26
  $this->_products_api_url = $this->_api_url . $this->store_id . '/products';
27
  }
28
 
29
+ public static function is_available()
30
  {
31
+ $token = self::_load_token();
32
+
33
+ if ( $token && $token != get_option( self::TOKEN_OPTION_NAME ) ) {
34
  return true;
35
  }
36
 
86
 
87
  $result = json_decode( $result['data'] );
88
 
89
+ if ( !empty( $result->items ) ) {
90
+ foreach ( $result->items as $item ) {
91
+ Ecwid_Category::from_stdclass( $item );
92
+ }
93
+ }
94
+
95
  return $result;
96
  }
97
 
98
  public function get_category($categoryId)
99
  {
100
+ if (!isset($categoryId) || $categoryId == 0 ) {
101
  return false;
102
  }
103
 
152
  $result = EcwidPlatform::get_from_products_cache( $url );
153
 
154
  if (!$result) {
155
+
156
  $result = EcwidPlatform::fetch_url( $url );
 
157
 
158
+ if ($result['code'] != '200') {
159
+ return false;
160
+ }
161
 
162
+ EcwidPlatform::store_in_products_cache( $url, $result );
163
+ }
164
 
165
  $result = json_decode($result['data']);
166
 
169
 
170
  public function search_products($input_params) {
171
  $params = array('token');
172
+ $passthru = array( 'updatedFrom', 'offset', 'limit', 'sortBy', 'keyword', 'baseUrl', 'cleanUrls', 'category' );
173
  foreach ($passthru as $name) {
174
  if ( array_key_exists( $name, $input_params ) ) {
175
+ $params[$name] = (string)$input_params[$name];
176
  }
177
  }
178
 
192
  $result = EcwidPlatform::get_from_products_cache( $url );
193
  if (!$result ) {
194
  $result = EcwidPlatform::fetch_url( $url );
195
+ if ($result['code'] != '200') {
196
+ return false;
197
+ }
198
 
199
+ EcwidPlatform::store_in_products_cache( $url, $result );
 
200
  }
201
 
 
202
 
203
  $result = json_decode($result['data']);
204
+
205
+ if ( !empty( $result->items ) ) {
206
+ foreach ( $result->items as $item ) {
207
+ Ecwid_Product::from_stdclass( $item );
208
+ }
209
+ }
210
+
211
  return $result;
212
  }
213
 
353
 
354
  public function get_store_profile() {
355
 
356
+ $profile = EcwidPlatform::cache_get( self::PROFILE_CACHE_NAME );
357
+
358
+ if ($profile) {
359
+ return $profile;
360
+ }
361
+
362
  $url = $this->_api_url . $this->store_id . '/profile';
363
 
364
  $params = array(
368
  $url = $this->build_request_url($url, $params);
369
  $result = EcwidPlatform::fetch_url($url);
370
 
371
+ $profile = json_decode($result['data']);
372
+
373
+ EcwidPlatform::cache_set( self::PROFILE_CACHE_NAME, $profile, 60 * 5 );
374
+
375
+ return self::$profile;
376
  }
377
 
378
  public function create_store()
lib/ecwid_catalog.php CHANGED
@@ -15,235 +15,131 @@ class EcwidCatalog
15
 
16
  public function get_product($id)
17
  {
18
-
19
- $params = array
20
- (
21
- array("alias" => "p", "action" => "product", "params" => array("id" => $id)),
22
- array("alias" => "pf", "action" => "profile")
23
- );
24
-
25
- $batch_result = $this->ecwid_api->get_batch_request($params);
26
-
27
- $product = $batch_result["p"];
28
- $profile = $batch_result["pf"];
29
-
30
- $return = $this->_l('');
31
-
32
- if (is_array($product))
33
- {
34
 
35
- $return .= $this->_l('<div itemscope itemtype="http://schema.org/Product">', 1);
36
- $return .= $this->_l('<h2 class="ecwid_catalog_product_name" itemprop="name">' . EcwidPlatform::esc_html($product["name"]) . '</h2>');
37
- $return .= $this->_l('<p class="ecwid_catalog_product_sku" itemprop="sku">' . EcwidPlatform::esc_html($product["sku"]) . '</p>');
38
-
39
- if (!empty($product["thumbnailUrl"]))
40
- {
41
- $return .= $this->_l('<div class="ecwid_catalog_product_image">', 1);
42
- $return .= $this->_l(
43
- sprintf(
44
- '<img itemprop="image" src="%s" alt="%s" />',
45
- EcwidPlatform::esc_attr($product['originalImageUrl']),
46
- EcwidPlatform::esc_attr($product['name'] . ' ' . $product['sku'])
47
- )
48
- );
49
- $return .= $this->_l('</div>', -1);
50
- }
51
-
52
- if(isset($product['categories']) && is_array($product["categories"]))
53
- {
54
- foreach ($product["categories"] as $ecwid_category)
55
- {
56
- if($ecwid_category["defaultCategory"] == true)
57
- {
58
- $return .= $this->_l('<div class="ecwid_catalog_product_category">' . EcwidPlatform::esc_html($ecwid_category['name']) . '</div>');
59
- }
60
- }
61
- }
62
-
63
- $return .= $this->_l('<div class="ecwid_catalog_product_price" itemprop="offers" itemscope itemtype="http://schema.org/Offer">', 1);
64
- $return .= $this->_l(EcwidPlatform::get_price_label() . ': <span itemprop="price">' . EcwidPlatform::esc_html($product["price"]) . '</span>');
65
-
66
- $return .= $this->_l('<span itemprop="priceCurrency">' . EcwidPlatform::esc_html($profile['currency']) . '</span>');
67
- if (!isset($product['quantity']) || (isset($product['quantity']) && $product['quantity'] > 0)) {
68
- $return .= $this->_l('<link itemprop="availability" href="http://schema.org/InStock" />In stock');
69
- }
70
- $return .= $this->_l('</div>', -1);
71
-
72
- $return .= $this->_l('<div class="ecwid_catalog_product_description" itemprop="description">', 1);
73
- $return .= $this->_l($product['description']);
74
- $return .= $this->_l('</div>', -1);
75
-
76
- if (is_array($product['attributes']) && !empty($product['attributes'])) {
77
-
78
- foreach ($product['attributes'] as $attribute) {
79
- if (trim($attribute['value']) != '') {
80
- $return .= $this->_l('<div class="ecwid_catalog_product_attribute">', 1);
81
-
82
- $attr_string = EcwidPlatform::esc_html($attribute['name']) . ':';
83
-
84
- if (isset($attribute['internalName']) && $attribute['internalName'] == 'Brand') {
85
- $attr_string .= '<span itemprop="brand">' . EcwidPlatform::esc_html($attribute['value']) . '</span>';
86
- } else {
87
- $attr_string .= EcwidPlatform::esc_html($attribute['value']);
88
- }
89
-
90
- $return .= $this->_l($attr_string);
91
- $return .= $this->_l('</div>', -1);
92
- }
93
- }
94
- }
95
-
96
- if (is_array($product["options"]))
97
- {
98
- $allowed_types = array('TEXTFIELD', 'DATE', 'TEXTAREA', 'SELECT', 'RADIO', 'CHECKBOX');
99
- foreach($product["options"] as $product_options)
100
- {
101
- if (!in_array($product_options['type'], $allowed_types)) continue;
102
-
103
- $return .= $this->_l('<div class="ecwid_catalog_product_options">', 1);
104
- $return .=$this->_l('<span>' . EcwidPlatform::esc_html($product_options["name"]) . '</span>');
105
-
106
- if($product_options["type"] == "TEXTFIELD" || $product_options["type"] == "DATE")
107
- {
108
- $return .=$this->_l('<input type="text" size="40" name="'. EcwidPlatform::esc_attr($product_options["name"]) . '">');
109
- }
110
- if($product_options["type"] == "TEXTAREA")
111
- {
112
- $return .=$this->_l('<textarea name="' . EcwidPlatform::esc_attr($product_options["name"]) . '"></textarea>');
113
- }
114
- if ($product_options["type"] == "SELECT")
115
- {
116
- $return .= $this->_l('<select name="'. $product_options["name"].'">', 1);
117
- foreach ($product_options["choices"] as $options_param)
118
- {
119
- $return .= $this->_l(
120
- sprintf(
121
- '<option value="%s">%s (%s)</option>',
122
- EcwidPlatform::esc_attr($options_param['text']),
123
- EcwidPlatform::esc_html($options_param['text']),
124
- EcwidPlatform::esc_html($options_param['priceModifier'])
125
- )
126
- );
127
- }
128
- $return .= $this->_l('</select>', -1);
129
- }
130
- if($product_options["type"] == "RADIO")
131
- {
132
- foreach ($product_options["choices"] as $options_param)
133
- {
134
- $return .= $this->_l(
135
- sprintf(
136
- '<input type="radio" name="%s" value="%s" />%s (%s)',
137
- EcwidPlatform::esc_attr($product_options['name']),
138
- EcwidPlatform::esc_attr($options_param['text']),
139
- EcwidPlatform::esc_html($options_param['text']),
140
- EcwidPlatform::esc_html($options_param['priceModifier'])
141
- )
142
- );
143
- }
144
- }
145
- if($product_options["type"] == "CHECKBOX")
146
- {
147
- foreach ($product_options["choices"] as $options_param)
148
- {
149
- $return .= $this->_l(
150
- sprintf(
151
- '<input type="checkbox" name="%s" value="%s" />%s (%s)',
152
- EcwidPlatform::esc_attr($product_options['name']),
153
- EcwidPlatform::esc_attr($options_param['text']),
154
- EcwidPlatform::esc_html($options_param['text']),
155
- EcwidPlatform::esc_html($options_param['priceModifier'])
156
- )
157
- );
158
- }
159
- }
160
-
161
- $return .= $this->_l('</div>', -1);
162
- }
163
- }
164
-
165
- if (is_array($product["galleryImages"]))
166
- {
167
- foreach ($product["galleryImages"] as $galleryimage)
168
- {
169
- if (empty($galleryimage["alt"])) $galleryimage["alt"] = htmlspecialchars($product["name"]);
170
- $return .= $this->_l(
171
- sprintf(
172
- '<img src="%s" alt="%s" title="%s" />',
173
- EcwidPlatform::esc_attr($galleryimage['url']),
174
- EcwidPlatform::esc_attr($galleryimage['alt']),
175
- EcwidPlatform::esc_attr($galleryimage['alt'])
176
- )
177
- );
178
- }
179
- }
180
-
181
- $return .= $this->_l("</div>", -1);
182
- }
183
 
 
 
 
184
  return $return;
185
  }
186
 
187
  public function get_category($id)
188
  {
189
- $params = array
190
- (
191
- array("alias" => "c", "action" => "categories", "params" => array("parent" => $id)),
192
- array("alias" => "p", "action" => "products", "params" => array("category" => $id)),
193
- array("alias" => "pf", "action" => "profile")
194
- );
195
  if ($id > 0) {
196
- $params[] = array('alias' => 'category', "action" => "category", "params" => array("id" => $id));
197
  }
 
 
 
 
 
 
198
 
199
- $batch_result = $this->ecwid_api->get_batch_request($params);
200
-
201
- $category = $id > 0 ? $batch_result['category'] : null;
202
- $categories = $batch_result["c"];
203
- $products = $batch_result["p"];
204
- $profile = $batch_result["pf"];
205
 
206
- $return = $this->_l('');
 
207
 
208
- if (!is_null($category)) {
209
- $return .= $this->_l('<h2>' . EcwidPlatform::esc_html($category['name']) . '</h2>');
210
- $return .= $this->_l('<div>' . $category['description'] . '</div>');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  }
212
-
213
- if (is_array($categories))
214
- {
215
- foreach ($categories as $category)
216
- {
217
- $category_url = Ecwid_Store_Page::get_category_url( $category['id'] );
218
-
219
- $category_name = $category["name"];
220
- $return .= $this->_l('<div class="ecwid_catalog_category_name">', 1);
221
- $return .= $this->_l('<a href="' . EcwidPlatform::esc_attr($category_url) . '">' . EcwidPlatform::esc_html($category_name) . '</a>');
222
- $return .= $this->_l('</div>', -1);
223
  }
224
- }
225
-
226
- if (is_array($products))
227
- {
228
- foreach ($products as $product)
229
- {
230
 
231
- $product_url = Ecwid_Store_Page::get_product_url( $product['id'] );
232
-
233
- $product_name = $product['name'];
234
- $product_price = $product['price'] . ' ' . $profile['currency'];
235
- $return .= $this->_l('<div>', 1);
236
- $return .= $this->_l('<span class="ecwid_product_name">', 1);
237
- $return .= $this->_l('<a href="' . EcwidPlatform::esc_attr($product_url) . '">' . EcwidPlatform::esc_html($product_name) . '</a>');
238
- $return .= $this->_l('</span>', -1);
239
- $return .= $this->_l('<span class="ecwid_product_price">' . EcwidPlatform::esc_html($product_price) . '</span>');
240
- $return .= $this->_l('</div>', -1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  }
 
 
 
 
 
 
 
242
  }
243
-
244
- return $return;
245
  }
246
-
 
 
 
 
 
 
 
 
 
247
  public function parse_escaped_fragment($escaped_fragment)
248
  {
249
  $fragment = urldecode($escaped_fragment);
@@ -263,106 +159,4 @@ class EcwidCatalog
263
 
264
  return $return;
265
  }
266
-
267
- public function get_category_name($id)
268
- {
269
- $category = $this->ecwid_api->get_category($id);
270
-
271
- $result = '';
272
- if (is_array($category) && isset($category['name'])) {
273
- $result = $category['name'];
274
- }
275
-
276
- return $result;
277
- }
278
-
279
- public function get_product_name($id)
280
- {
281
- $product = $this->ecwid_api->get_product($id);
282
-
283
- $result = '';
284
- if (is_array($product) && isset($product['name'])) {
285
- $result = $product['name'];
286
- }
287
-
288
- return $result;
289
- }
290
-
291
-
292
- public function get_category_description($id)
293
- {
294
- $category = $this->ecwid_api->get_category($id);
295
-
296
- $result = '';
297
- if (is_array($category) && isset($category['description'])) {
298
- $result = $category['description'];
299
- }
300
-
301
- return $result;
302
- }
303
-
304
- public function get_product_description($id)
305
- {
306
- $product = $this->ecwid_api->get_product($id);
307
-
308
- $result = '';
309
- if (is_array($product) && isset($product['description'])) {
310
- $result = $product['description'];
311
- }
312
-
313
- return $result;
314
- }
315
-
316
- public function get_product_url($product)
317
- {
318
- if (is_numeric($product) && $this->ecwid_api->is_api_enabled()) {
319
- $product = $this->ecwid_api->get_product($product);
320
- }
321
-
322
- return $this->get_entity_url($product, 'p');
323
- }
324
-
325
- public function get_category_url($category)
326
- {
327
- if (is_numeric($category) && $this->ecwid_api->is_api_enabled()) {
328
- $category = $this->ecwid_api->get_category($category);
329
- }
330
-
331
- return $this->get_entity_url($category, 'c');
332
- }
333
-
334
- protected function get_entity_url($entity, $type) {
335
-
336
- $link = $this->store_base_url;
337
-
338
- if (is_numeric($entity)) {
339
- return $link . '#!/' . $type . '/' . $entity;
340
- } elseif (is_array($entity) && isset($entity['url'])) {
341
- $link .= substr($entity['url'], strpos($entity['url'], '#'));
342
- }
343
-
344
- return $link;
345
-
346
- }
347
-
348
- /*
349
- * A helper function to produce indented html output.
350
- * Indent change need to be 1 for opening tag lines and -1 for closing tag lines.
351
- * Regular lines should omit the second parameter.
352
- * Example:
353
- * _l('<parent-tag>', 1);
354
- * _l('<content-tag>content</content-tag>');
355
- * _l('</parent-tag>', -1)
356
- *
357
- */
358
- protected function _l($code, $indent_change = 0)
359
- {
360
- static $indent = 0;
361
-
362
- if ($indent_change < 0) $indent -= 1;
363
- $str = str_repeat(' ', $indent) . $code . "\n";
364
- if ($indent_change > 0) $indent += 1;
365
-
366
- return $str;
367
- }
368
  }
15
 
16
  public function get_product($id)
17
  {
18
+ $result = $this->_get_data_for_product($id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
+ ob_start();
21
+ $product = $result->product;
22
+ $formats = $result->formats;
23
+ require dirname(__FILE__) . '/html-catalog-templates/product.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
+ $return = ob_get_contents();
26
+ ob_end_clean();
27
+
28
  return $return;
29
  }
30
 
31
  public function get_category($id)
32
  {
33
+ $data = $this->_get_data_for_category( $id, @$_GET['offset'] );
34
+
35
+ $main_category = null;
 
 
 
36
  if ($id > 0) {
37
+ $main_category = $data->main_category;
38
  }
39
+ $categories = $data->categories;
40
+ $products = $data->products;
41
+ $formats = $data->formats;
42
+
43
+ ob_start();
44
+ require dirname(__FILE__) . '/html-catalog-templates/category.php';
45
 
46
+ $return = ob_get_contents();
47
+ ob_end_clean();
 
 
 
 
48
 
49
+ return $return;
50
+ }
51
 
52
+ protected function _get_data_for_product( $id )
53
+ {
54
+ if ( Ecwid_Api_V3::is_available() ) {
55
+ $api = new Ecwid_Api_V3();
56
+
57
+ $product = Ecwid_Product::get_by_id( $id );
58
+
59
+ $profile = $api->get_store_profile();
60
+
61
+ return (object) array(
62
+ 'product' => $product,
63
+ 'formats' => $profile->formatsAndUnits
64
+ );
65
+ } else {
66
+
67
+ $params = array
68
+ (
69
+ array("alias" => "product", "action" => "product", "params" => array("id" => $id)),
70
+ array("alias" => "formats", "action" => "profile")
71
+ );
72
+
73
+ $batch_result = $this->_get_apiv1_batch_result( $params );
74
+
75
+ return $batch_result;
76
  }
77
+
78
+ }
79
+
80
+ protected function _get_data_for_category( $id, $offset )
81
+ {
82
+ if ( Ecwid_Api_V3::is_available() ) {
83
+ $api = new Ecwid_Api_V3();
84
+
85
+ $main_category = null;
86
+ if ($id > 0) {
87
+ $main_category = $api->get_category( $id );
88
  }
 
 
 
 
 
 
89
 
90
+ $get_categories_params = array(
91
+ 'parent' => $id
92
+ );
93
+ if ($offset) {
94
+ $get_categories_params['offset'] = $offset;
95
+ }
96
+ $categories = $api->get_categories( $get_categories_params );
97
+
98
+ $get_products_params = array(
99
+ 'category' => $id
100
+ );
101
+ if ($offset) {
102
+ $get_products_params['offset'] = $offset;
103
+ }
104
+ $products = $api->search_products( $get_products_params );
105
+
106
+ $profile = $api->get_store_profile();
107
+
108
+ return (object) array(
109
+ 'main_category' => $main_category,
110
+ 'categories' => $categories->items,
111
+ 'products' => $products->items,
112
+ 'formats' => $profile->formatsAndUnits
113
+ );
114
+ } else {
115
+ $params = array
116
+ (
117
+ array("alias" => "categories", "action" => "categories", "params" => array("parent" => $id)),
118
+ array("alias" => "products", "action" => "products", "params" => array("category" => $id)),
119
+ array("alias" => "formats", "action" => "profile")
120
+ );
121
+ if ($id > 0) {
122
+ $params[] = array('alias' => 'main_category', "action" => "category", "params" => array("id" => $id));
123
  }
124
+
125
+ $batch_result = $this->_get_apiv1_batch_result( $params );
126
+ if ( !isset($batch_result->main_category) ) {
127
+ $batch_result->main_category = null;
128
+ }
129
+
130
+ return $batch_result;
131
  }
 
 
132
  }
133
+
134
+ protected function _get_apiv1_batch_result($params) {
135
+ $batch_result = $this->ecwid_api->get_batch_request($params);
136
+ if ( is_array( $batch_result ) ) {
137
+ $batch_result = $this->ecwid_api->get_batch_request($params);
138
+ }
139
+
140
+ return $batch_result;
141
+ }
142
+
143
  public function parse_escaped_fragment($escaped_fragment)
144
  {
145
  $fragment = urldecode($escaped_fragment);
159
 
160
  return $return;
161
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  }
lib/ecwid_catalog_entry.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ abstract class Ecwid_Catalog_Entry {
4
+
5
+ protected $_data;
6
+ protected $_cache_name_prefix = null;
7
+ protected $_link_prefix = null;
8
+
9
+ abstract protected function _get_from_local_object_cache( $id );
10
+ abstract protected function _put_into_local_object_cache( $id );
11
+
12
+ protected function __construct()
13
+ {
14
+ $this->_data = new stdClass();
15
+ }
16
+
17
+ public function __get( $name ) {
18
+
19
+ if ( $name == 'link' ) {
20
+ return $this->get_link();
21
+ }
22
+
23
+ return $this->_data->$name;
24
+ }
25
+
26
+ public function __isset( $name ) {
27
+
28
+ if ($name == 'link') {
29
+ $link = $this->get_link();
30
+ return (bool) $link;
31
+ }
32
+
33
+ return isset( $this->_data->$name );
34
+ }
35
+
36
+ public static function from_stdclass( $data ) {
37
+ trigger_error('from_stdclass should never be called from Ecwid_catalog_Entry');
38
+
39
+ return false;
40
+ }
41
+
42
+ public static function get_by_id( $id ) {
43
+ trigger_error('get_by_id should never be called from Ecwid_catalog_Entry');
44
+
45
+ return false;
46
+ }
47
+
48
+ public function get_link( $baseUrl = false )
49
+ {
50
+ if ( Ecwid_Seo_Links::is_enabled() ) {
51
+ return $this->get_seo_link( $baseUrl );
52
+ } else {
53
+ if ( $this->_data->name && $this->_data->id ) {
54
+ if ( !$baseUrl ) {
55
+ $baseUrl = Ecwid_Store_Page::get_store_url();
56
+ }
57
+ $url = $baseUrl;
58
+
59
+ $url .= '#!/' . urlencode( $this->_data->name ) . '/' . $this->_link_prefix . '/' . $this->_data->id;
60
+
61
+ return $url;
62
+ }
63
+ }
64
+
65
+ return false;
66
+ }
67
+
68
+
69
+ public function get_seo_link( $baseUrl = false )
70
+ {
71
+ if ( isset( $this->_data->seo_link ) ) {
72
+ return $this->_data->seo_link;
73
+ } else if ( $this->_data->id && $this->_data->name ) {
74
+
75
+ if ( !$baseUrl ) {
76
+ $baseUrl = Ecwid_Store_Page::get_store_url();
77
+ }
78
+ $url = $baseUrl;
79
+
80
+ $url .= '/' . urlencode( $this->_data->name ) . '-' . $this->_link_prefix . $this->_data->id;
81
+
82
+ return $url;
83
+ }
84
+
85
+ return false;
86
+ }
87
+
88
+ protected function _get_cache_key_by_id( $id ) {
89
+ return $this->_cache_name_prefix . $id;
90
+ }
91
+ }
lib/ecwid_category.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once dirname(__FILE__) . '/ecwid_catalog_entry.php';
4
+
5
+ class Ecwid_Category extends Ecwid_Catalog_Entry
6
+ {
7
+ protected static $categories = array();
8
+ protected $_cache_name_prefix = 'ecwid-category-';
9
+ protected $_link_prefix = 'c';
10
+
11
+ protected function _get_from_local_object_cache( $id ) {
12
+ if ( isset( self::$categories[$id] ) ) {
13
+ return self::$categories[$id];
14
+ }
15
+
16
+ return null;
17
+ }
18
+
19
+ protected function _put_into_local_object_cache( $obj ) {
20
+ if ( !isset( $obj->id ) ) {
21
+ return false;
22
+ }
23
+
24
+ self::$categories[$obj->id] = $obj;
25
+ }
26
+
27
+ public static function from_stdclass( $data ) {
28
+
29
+ $entry = new Ecwid_Category();
30
+
31
+ $entry->_init_from_stdclass( $data );
32
+
33
+ $entry->_put_into_local_object_cache( $entry );
34
+ }
35
+
36
+
37
+ public static function get_by_id( $id )
38
+ {
39
+ $e = new Ecwid_Category();
40
+
41
+ if ( $e->_get_from_local_object_cache($id) ) {
42
+ return $e->_get_from_local_object_cache($id);
43
+ }
44
+
45
+ $entry_data = $e->_get_from_cache( $id );
46
+
47
+ if ( !$entry_data ) {
48
+ $e->_load($id);
49
+ } else {
50
+ $e->_init_from_stdclass( $entry_data );
51
+ }
52
+
53
+ $e->_put_into_local_object_cache($e);
54
+
55
+ return $e;
56
+ }
57
+
58
+ protected function _get_from_cache( $id ) {
59
+ return EcwidPlatform::get_from_categories_cache( $this->_get_cache_key_by_id( $id ) );
60
+ }
61
+
62
+ protected function _init_from_stdclass( $data )
63
+ {
64
+ $this->_data = $data;
65
+
66
+ EcwidPlatform::store_in_categories_cache(
67
+ $this->_get_cache_key_by_id( $data->id ),
68
+ $data
69
+ );
70
+ }
71
+
72
+ protected function _load($id) {
73
+
74
+ $data = null;
75
+ if ( Ecwid_Api_V3::is_available() ) {
76
+ $api = new Ecwid_Api_V3();
77
+ $data = $api->get_category($id);
78
+
79
+ if ( $data && Ecwid_Seo_Links::is_enabled() ) {
80
+ $data->seo_link = $data->url;
81
+ }
82
+ } else {
83
+ $api = ecwid_new_product_api();
84
+ $data = $api->get_category($id);
85
+ }
86
+
87
+ if ($data) {
88
+
89
+ $this->_init_from_stdclass($data);
90
+ }
91
+
92
+ return $data;
93
+ }
94
+ }
lib/ecwid_platform.php CHANGED
@@ -287,9 +287,9 @@ class EcwidPlatform {
287
  self::cache_set( $name, $to_store, MONTH_IN_SECONDS );
288
  }
289
 
290
- static public function get_from_categories_cache( $url )
291
  {
292
- $cache_name = self::_build_cache_name( $url, 'categories' );
293
 
294
  $result = self::cache_get( $cache_name );
295
  if ( $result['time'] > EcwidPlatform::get( self::CATEGORIES_CACHE_VALID_FROM ) ) {
@@ -299,9 +299,9 @@ class EcwidPlatform {
299
  return false;
300
  }
301
 
302
- static public function get_from_products_cache( $url )
303
  {
304
- $cache_name = self::_build_cache_name( $url, 'products' );
305
 
306
  $result = self::cache_get( $cache_name );
307
 
287
  self::cache_set( $name, $to_store, MONTH_IN_SECONDS );
288
  }
289
 
290
+ static public function get_from_categories_cache( $key )
291
  {
292
+ $cache_name = self::_build_cache_name( $key, 'categories' );
293
 
294
  $result = self::cache_get( $cache_name );
295
  if ( $result['time'] > EcwidPlatform::get( self::CATEGORIES_CACHE_VALID_FROM ) ) {
299
  return false;
300
  }
301
 
302
+ static public function get_from_products_cache( $key )
303
  {
304
+ $cache_name = self::_build_cache_name( $key, 'products' );
305
 
306
  $result = self::cache_get( $cache_name );
307
 
lib/ecwid_product.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once dirname(__FILE__) . '/ecwid_catalog_entry.php';
4
+
5
+ class Ecwid_Product extends Ecwid_Catalog_Entry
6
+ {
7
+ protected static $products = array();
8
+ protected $_cache_name_prefix = 'ecwid-product-';
9
+ protected $_link_prefix = 'p';
10
+
11
+ protected function _get_from_local_object_cache( $id ) {
12
+ if ( isset( self::$products[$id] ) ) {
13
+ return self::$products[$id];
14
+ }
15
+
16
+ return null;
17
+ }
18
+
19
+ protected function _put_into_local_object_cache( $obj ) {
20
+ if ( !isset( $obj->id ) ) {
21
+ return false;
22
+ }
23
+
24
+ self::$products[$obj->id] = $obj;
25
+ }
26
+
27
+ protected static function _new_this() {
28
+ return new Ecwid_Category();
29
+ }
30
+
31
+ public static function from_stdclass( $data ) {
32
+
33
+ $entry = new Ecwid_Product();
34
+
35
+ $entry->_init_from_stdclass( $data );
36
+
37
+ $entry->_put_into_local_object_cache( $entry );
38
+ }
39
+
40
+ public static function get_by_id( $id )
41
+ {
42
+ if ( $product = self::_get_from_local_object_cache($id) ) {
43
+ return $product;
44
+ }
45
+
46
+ $p = new Ecwid_Product();
47
+
48
+ $product_data = $p->_get_from_cache( $id );
49
+
50
+ if ( !$product_data ) {
51
+ $p->_load($id);
52
+ } else {
53
+ $p->_init_from_stdclass($product_data);
54
+ }
55
+
56
+ self::_put_into_local_object_cache($p);
57
+
58
+ return $p;
59
+ }
60
+
61
+ protected function _get_from_cache( $id ) {
62
+ return EcwidPlatform::get_from_products_cache( $this->_get_cache_key_by_id( $id ) );
63
+ }
64
+
65
+ protected function _init_from_stdclass( $data )
66
+ {
67
+ $this->_data = $data;
68
+
69
+ EcwidPlatform::store_in_products_cache(
70
+ $this->_get_cache_key_by_id( $data->id ),
71
+ $data
72
+ );
73
+ }
74
+
75
+
76
+ protected function _load($id) {
77
+
78
+ $data = null;
79
+ if ( Ecwid_Api_V3::is_available() ) {
80
+ $api = new Ecwid_Api_V3();
81
+ $data = $api->get_product($id);
82
+
83
+ if ( $data && Ecwid_Seo_Links::is_enabled() ) {
84
+ $data->seo_link = $data->url;
85
+ }
86
+ } else {
87
+ $api = ecwid_new_product_api();
88
+ $data = $api->get_product_https($id);
89
+ }
90
+
91
+ if ($data) {
92
+ $this->_init_from_stdclass( $data );
93
+ }
94
+
95
+ return $data;
96
+ }
97
+ }
lib/ecwid_product_api.php CHANGED
@@ -41,12 +41,11 @@ class EcwidProductApi {
41
 
42
  $fetch_result = $request->do_request();
43
 
44
-
45
  if ($fetch_result['code'] == 200) {
46
  $this->error = '';
47
  $this->error_code = '';
48
  $json = $fetch_result['data'];
49
- $result = json_decode($json, true);
50
  } else {
51
  $this->error = $fetch_result['data'];
52
  $this->error_code = $fetch_result['code'];
@@ -189,6 +188,7 @@ class EcwidProductApi {
189
  $api_url = $this->ECWID_PRODUCT_API_ENDPOINT . "/" . $this->store_id . "/batch?". $api_url;
190
 
191
  $data = EcwidPlatform::get_from_products_cache($api_url);
 
192
  if (!$data) {
193
  $data = $this->process_request($api_url);
194
  EcwidPlatform::store_in_products_cache($api_url, $data);
@@ -221,7 +221,7 @@ class EcwidProductApi {
221
 
222
  $result = $this->process_request($api_url);
223
 
224
- return $this->error_code === '' && $result && !isset($result['error']);
225
  }
226
 
227
  function get_method_response_stream($method)
41
 
42
  $fetch_result = $request->do_request();
43
 
 
44
  if ($fetch_result['code'] == 200) {
45
  $this->error = '';
46
  $this->error_code = '';
47
  $json = $fetch_result['data'];
48
+ $result = json_decode($json);
49
  } else {
50
  $this->error = $fetch_result['data'];
51
  $this->error_code = $fetch_result['code'];
188
  $api_url = $this->ECWID_PRODUCT_API_ENDPOINT . "/" . $this->store_id . "/batch?". $api_url;
189
 
190
  $data = EcwidPlatform::get_from_products_cache($api_url);
191
+
192
  if (!$data) {
193
  $data = $this->process_request($api_url);
194
  EcwidPlatform::store_in_products_cache($api_url, $data);
221
 
222
  $result = $this->process_request($api_url);
223
 
224
+ return $this->error_code === '' && $result && !isset($result->error);
225
  }
226
 
227
  function get_method_response_stream($method)
lib/ecwid_requests.php CHANGED
@@ -346,14 +346,17 @@ class Ecwid_HTTP_Get_Fopen extends Ecwid_HTTP_Get {
346
 
347
  foreach ($meta['wrapper_data'] as $item) {
348
 
 
 
 
 
 
349
  $match = array();
350
  if (preg_match('|HTTP/\d\.\d\s+(\d+)\s+(.*)|',$item, $match)) {
351
  $result['code'] = $match[1];
352
  $result['message'] = $match[2];
353
  }
354
 
355
- if (!is_string($item)) continue;
356
-
357
  $colon_pos = strpos($item, ':');
358
 
359
  if (!$colon_pos) continue;
@@ -442,6 +445,11 @@ class Ecwid_HTTP_Post_Fopen extends Ecwid_Http_Post {
442
 
443
  foreach ($meta['wrapper_data'] as $item) {
444
 
 
 
 
 
 
445
  $match = array();
446
  if (preg_match('|HTTP/\d\.\d\s+(\d+)\s+(.*)|',$item, $match)) {
447
  $result['code'] = $match[1];
346
 
347
  foreach ($meta['wrapper_data'] as $item) {
348
 
349
+ if (!is_string($item)) {
350
+ ecwid_log_error(json_encode($item));
351
+ continue;
352
+ }
353
+
354
  $match = array();
355
  if (preg_match('|HTTP/\d\.\d\s+(\d+)\s+(.*)|',$item, $match)) {
356
  $result['code'] = $match[1];
357
  $result['message'] = $match[2];
358
  }
359
 
 
 
360
  $colon_pos = strpos($item, ':');
361
 
362
  if (!$colon_pos) continue;
445
 
446
  foreach ($meta['wrapper_data'] as $item) {
447
 
448
+ if (!is_string($item)) {
449
+ ecwid_log_error(json_encode($item));
450
+ continue;
451
+ }
452
+
453
  $match = array();
454
  if (preg_match('|HTTP/\d\.\d\s+(\d+)\s+(.*)|',$item, $match)) {
455
  $result['code'] = $match[1];
lib/html-catalog-templates/category.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <?php if ( $main_category ): ?>
3
+
4
+ <h1 class="category-name"><?php echo $main_category->name; ?></h1>
5
+ <?php if ( $main_category->description ): ?>
6
+ <div class="category-description"><?php echo $main_category->description; ?></div>
7
+ <?php endif; ?>
8
+
9
+ <?php endif; ?>
10
+
11
+ <?php if ( $categories ): foreach ( $categories as $category ): ?>
12
+ <div class="category-<?php echo $category->id; ?>">
13
+ <a href="<?php echo Ecwid_Store_Page::get_category_url( $category->id ); ?>">
14
+ <?php echo EcwidPlatform::esc_html( $category->name ); ?>
15
+ </a>
16
+ </div>
17
+ <?php endforeach; endif; ?>
18
+
19
+ <?php if ( $products ): foreach ( $products as $product ): ?>
20
+
21
+ <div class="product-<?php echo $product->id; ?>">
22
+ <span class="product-name">
23
+ <a href="<?php echo Ecwid_Store_Page::get_product_url( $product->id ); ?>">
24
+ <?php echo EcwidPlatform::esc_html( $product->name ); ?>
25
+ </a>
26
+ </span>
27
+ <span class="product-price">
28
+ <?php echo $product->price . ' ' . $formats->currency; ?>
29
+ </span>
30
+ </div>
31
+
32
+ <?php endforeach; endif; ?>
lib/html-catalog-templates/product.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <div itemscope itemtype="http://schema.org/Product">
3
+
4
+ <h1 itemprop="name"><?php echo EcwidPlatform::esc_html( $product->name ); ?></h1>
5
+ <p itemprop="sku"><?php echo EcwidPlatform::esc_html( $product->sku ); ?></p>
6
+ <img itemprop="image" src="<?php echo EcwidPlatform::esc_attr( $product->originalImageUrl ); ?>" alt="<?php echo EcwidPlatform::esc_attr( $product->name . ' ' . $product->sku); ?>" />
7
+ <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
8
+ <span itemprop="price" content="<?php echo EcwidPlatform::esc_html( $product->price ); ?>"><?php
9
+ echo EcwidPlatform::esc_html(
10
+ $formats->currencyPrefix . $product->price . $formats->currencySuffix
11
+ );
12
+ ?></span>
13
+ <span itemprop="priceCurrency" content="<?php echo EcwidPlatform::esc_attr( $formats->currency ); ?>"></span>
14
+ <?php if ( !isset( $product->quantity) || $product->quantity > 0): ?><link itemprop="availability" href="http://schema.org/InStock" />In stock<?php endif; ?>
15
+ </div>
16
+ <?php if ( isset( $product->attributes ) && is_array( $product->attributes ) && !empty( $product->attributes) ): ?>
17
+ <div class="attributes">
18
+ <?php foreach ( $product->attributes as $attribute ):
19
+ ?> <div><?php
20
+ echo $attribute->name . ':';
21
+ if ( isset( $attribute->internalName ) && $attribute->internalName == 'Brand'
22
+ ||
23
+ isset( $attribute->type ) && $attribute->type == 'BRAND'
24
+ ):
25
+ ?><span itemprop="brand"><?php echo EcwidPlatform::esc_html( $attribute->value ); ?></span><?php
26
+ else:
27
+ echo EcwidPlatform::esc_html( $attribute->value );
28
+ endif;
29
+ ?></div>
30
+ <?php
31
+ endforeach; ?></div>
32
+ <?php endif; ?>
33
+ <?php if ( isset( $product->options) && is_array( $product->options ) && !empty( $product->options ) ): ?>
34
+ <?php foreach ( $product->options as $option ): ?>
35
+ <div class="option">
36
+ <span class="name"><?php echo $option->name; ?></span>
37
+ <span class="input"><?php
38
+ if ( $option->type == 'TEXTAREA' ):
39
+ ?>
40
+ <textarea name="<?php echo EcwidPlatform::esc_attr( $option->name ); ?>"></textarea>
41
+ <?php elseif ( $option->type == 'SELECT' ): ?>
42
+ <select name="<?php echo EcwidPlatform::esc_attr( $option->name ); ?>"><?php
43
+ foreach( $option->choices as $param ): ?>
44
+ <option value="<?php echo EcwidPlatform::esc_attr( $param->text ); ?>"><?php
45
+ echo EcwidPlatform::esc_html( $param->text );
46
+ echo ' ';
47
+ echo EcwidPlatform::esc_html( $param->priceModifier );
48
+ ?></option><?php endforeach;
49
+ ?>
50
+ </select><?php
51
+ elseif ( $option->type == 'RADIO' ):
52
+ foreach ( $option->choices as $param ): ?>
53
+ <?php echo sprintf(
54
+ '<input type="radio" name="%s" value="%s" />%s (%s)',
55
+ EcwidPlatform::esc_attr( $option->name ),
56
+ EcwidPlatform::esc_attr( $param->text ),
57
+ EcwidPlatform::esc_html( $param->text ),
58
+ EcwidPlatform::esc_html( $param->priceModifier )
59
+ ); ?>
60
+ <?php endforeach; ?>
61
+ <?php elseif ( $option->type == 'CHECKBOX'): foreach ( $option->choices as $param ): ?>
62
+ <?php echo sprintf(
63
+ '<input type="checkbox" name="%s[]" value="%s" />%s (%s)',
64
+ EcwidPlatform::esc_attr( $option->name ),
65
+ EcwidPlatform::esc_attr( $param->text ),
66
+ EcwidPlatform::esc_html( $param->text ),
67
+ EcwidPlatform::esc_html( $param->priceModifier )
68
+ ); ?>
69
+ <?php endforeach; ?>
70
+ <?php else: ?>
71
+ <input type="text" name="<?php echo EcwidPlatform::esc_attr( $option->name ); ?>" /><?php
72
+ endif;
73
+ ?>
74
+ </span>
75
+ </div>
76
+ <?php endforeach;
77
+ endif; ?>
78
+ <?php if ( $product->galleryImages ) foreach ( $product->galleryImages as $image):
79
+ ?><img src="<?php echo EcwidPlatform::esc_attr( $image->url ); ?>" alt="<?php echo EcwidPlatform::esc_attr( $image->alt ? $image->alt : $product->name ); ?>" />
80
+ <?php endforeach; ?>
81
+ </div>
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: Ecwid
3
  Tags: ecommerce, downloadable products, Facebook ecommerce, online store, paypal, product catalog, shop, shopping cart, store
4
  Requires at least: 3.5
5
  Tested up to: 4.8
6
- Stable tag: 5.3.1
7
 
8
  Powerful, easy to use ecommerce shopping cart. Bank level PCI DSS Level 1 security. iPhone & Android apps. Superb support. Free plan available.
9
 
@@ -149,6 +149,14 @@ You can use Ecwid’s built-in import tools to copy your store products from any
149
  * [Ecwid eCommerce Forums](https://www.ecwid.com/forums/forumdisplay.php?f=19)
150
 
151
  == Changelog ==
 
 
 
 
 
 
 
 
152
  = 5.3.1 =
153
  - **Fix for the “Add product” button in the WordPress editor.** The button was broken in the latest version (5.3) — it generated invalid shortcode for the single product widgets. The problem didn’t affect existing product widgets, but the new ones didn’t render. It’s now fixed. If you faced a trouble adding product widgets to your pages and posts, please update the plugin and try again.
154
 
3
  Tags: ecommerce, downloadable products, Facebook ecommerce, online store, paypal, product catalog, shop, shopping cart, store
4
  Requires at least: 3.5
5
  Tested up to: 4.8
6
+ Stable tag: 5.4
7
 
8
  Powerful, easy to use ecommerce shopping cart. Bank level PCI DSS Level 1 security. iPhone & Android apps. Superb support. Free plan available.
9
 
149
  * [Ecwid eCommerce Forums](https://www.ecwid.com/forums/forumdisplay.php?f=19)
150
 
151
  == Changelog ==
152
+ = 5.4 =
153
+ - **Improvements in the SEO friendly versions of product pages, which are indexed by search engines.** This includes optimized product price format, canonical tags and minor adjustments for SEO titles and descriptions. This is another improvement for search crawlers to better index store pages.
154
+ - **Adjustments for the “All in one SEO” plugin** to make sure it works well with the Ecwid’s new clean URLs.
155
+ - **Fixed “preg match” PHP warning messages**, which appeared on some sites with the Ecwid ecommerce plugin enabled.
156
+ - **Fixed an issue with site images in the Newsmag Wordpress theme** — some images were not displayed well with Ecwid. We fixed that so everything should work fine in the Newsmag theme now.
157
+ - **Several fixes and improvements for the floating minicart widget.**
158
+ - **Loading speed improvements.** We optimized the plugin code to render store pages and widgets faster.
159
+
160
  = 5.3.1 =
161
  - **Fix for the “Add product” button in the WordPress editor.** The button was broken in the latest version (5.3) — it generated invalid shortcode for the single product widgets. The problem didn’t affect existing product widgets, but the new ones didn’t render. It’s now fixed. If you faced a trouble adding product widgets to your pages and posts, please update the plugin and try again.
162
 
templates/ecwid-admin.php CHANGED
@@ -20,6 +20,6 @@
20
  </script>
21
 
22
 
23
- <iframe seamless id="ecwid-frame" frameborder="0" width="100%" height="700" scrolling="no"></iframe>
24
 
25
  <?php require_once ECWID_PLUGIN_DIR . 'templates/admin-footer.php'; ?>
20
  </script>
21
 
22
 
23
+ <iframe seamless id="ecwid-frame" frameborder="0" width="100%" height="700" scrolling="yes"></iframe>
24
 
25
  <?php require_once ECWID_PLUGIN_DIR . 'templates/admin-footer.php'; ?>
templates/product-popup.php CHANGED
@@ -173,7 +173,7 @@
173
  ecwidRenderCheckboxOption({
174
  'section': 'display-options',
175
  'name': 'addtobag',
176
- 'label': '<?php _e( '«Add to bag» button', 'ecwid-shopping-cart' ); ?>'
177
  });
178
  });
179
  </script>
173
  ecwidRenderCheckboxOption({
174
  'section': 'display-options',
175
  'name': 'addtobag',
176
+ 'label': '<?php _e( '«Buy now» button', 'ecwid-shopping-cart' ); ?>'
177
  });
178
  });
179
  </script>