Changeset 3239265
- Timestamp:
- 02/12/2025 10:14:39 AM (14 months ago)
- Location:
- ecwid-shopping-cart
- Files:
-
- 14 edited
- 1 copied
-
tags/6.12.27 (copied) (copied from ecwid-shopping-cart/trunk)
-
tags/6.12.27/ecwid-shopping-cart.php (modified) (2 diffs)
-
tags/6.12.27/includes/class-ecwid-product-popup.php (modified) (1 diff)
-
tags/6.12.27/includes/class-ecwid-static-page.php (modified) (12 diffs)
-
tags/6.12.27/includes/shortcodes/class-ecwid-shortcode-productbrowser.php (modified) (2 diffs)
-
tags/6.12.27/lib/ecwid_api_v3.php (modified) (26 diffs)
-
tags/6.12.27/lib/ecwid_platform.php (modified) (6 diffs)
-
tags/6.12.27/readme.txt (modified) (2 diffs)
-
trunk/ecwid-shopping-cart.php (modified) (2 diffs)
-
trunk/includes/class-ecwid-product-popup.php (modified) (1 diff)
-
trunk/includes/class-ecwid-static-page.php (modified) (12 diffs)
-
trunk/includes/shortcodes/class-ecwid-shortcode-productbrowser.php (modified) (2 diffs)
-
trunk/lib/ecwid_api_v3.php (modified) (26 diffs)
-
trunk/lib/ecwid_platform.php (modified) (6 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ecwid-shopping-cart/tags/6.12.27/ecwid-shopping-cart.php
r3231865 r3239265 6 6 Text Domain: ecwid-shopping-cart 7 7 Author: Ecwid Ecommerce 8 Version: 6.12.2 68 Version: 6.12.27 9 9 Author URI: https://ecwid.to/ecwid-site 10 10 License: GPLv2 or later … … 1697 1697 ), 1698 1698 1699 Ecwid_Static_Page::OPTION_NEW_IS_ENABLED => array( 1700 'values' => array( 1701 Ecwid_Static_Page::OPTION_VALUE_AUTO, 1702 Ecwid_Static_Page::OPTION_VALUE_ENABLED, 1703 Ecwid_Static_Page::OPTION_VALUE_DISABLED 1704 ) 1705 ), 1706 1699 1707 Ec_Store_Defer_Init::OPTION_NAME => array( 1700 1708 'values' => array( -
ecwid-shopping-cart/tags/6.12.27/includes/class-ecwid-product-popup.php
r3223401 r3239265 36 36 } 37 37 38 if ( $is_post_screen && ! in_array( $current_screen->post_type, array( 'page', 'post' ) ) ) { //phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict 38 $post_types = get_post_types( array( 'public' => true ) ); 39 if ( $is_post_screen && ! in_array( $current_screen->post_type, $post_types, true ) ) { 39 40 return; 40 41 } -
ecwid-shopping-cart/tags/6.12.27/includes/class-ecwid-static-page.php
r3231865 r3239265 3 3 class Ecwid_Static_Page { 4 4 5 const OPTION_IS_ENABLED = 'ecwid_static_home_page_enabled'; 5 const OPTION_IS_ENABLED = 'ecwid_static_home_page_enabled'; 6 const OPTION_NEW_IS_ENABLED = 'ecwid_new_static_home_page_enabled'; 6 7 7 8 const OPTION_VALUE_ENABLED = 'Y'; … … 19 20 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 20 21 } 22 23 add_action( 'update_option_' . self::OPTION_NEW_IS_ENABLED, array( $this, 'clear_cache' ), 10, 3 ); 21 24 } 22 25 … … 54 57 } 55 58 56 protected static function get_endpoint_url( $params = false ) { 57 58 if ( ! $params ) { 59 if ( ecwid_is_applicable_escaped_fragment() ) { 60 $params = ecwid_parse_escaped_fragment(); 61 } else { 62 $params = Ecwid_Seo_Links::maybe_extract_html_catalog_params(); 63 } 64 } 59 protected static function get_endpoint_params() { 60 61 if ( ecwid_is_applicable_escaped_fragment() ) { 62 $params = ecwid_parse_escaped_fragment(); 63 } else { 64 $params = Ecwid_Seo_Links::maybe_extract_html_catalog_params(); 65 } 65 66 66 67 if ( ! isset( $params['mode'] ) ) { … … 68 69 } 69 70 70 $url = 'https://' . Ecwid_Config::get_static_pages_api_domain() . '/'; 71 $url .= sprintf( '%s-page/', $params['mode'] ); 72 $url .= sprintf( '%s/', get_ecwid_store_id() ); 73 74 if ( isset( $params['id'] ) ) { 75 $url .= sprintf( '%s/', $params['id'] ); 76 } 77 78 $url .= 'static-code?'; 79 80 return $url; 71 return $params; 81 72 } 82 73 … … 89 80 90 81 $store_page_params = Ecwid_Store_Page::get_store_page_params(); 91 $endpoint_params = false; 82 $endpoint_params = false; 83 $query_params = array(); 92 84 93 85 // for cases of early access to the page if the cache is empty and need to get store block params … … 99 91 } 100 92 101 $params = array();102 103 93 if ( Ecwid_Seo_Links::is_enabled() || ecwid_is_demo_store() ) { 104 $ params['clean_urls'] = 'true';94 $query_params['clean_urls'] = 'true'; 105 95 } else { 106 $ params['clean_urls'] = 'false';107 } 108 109 $ params['base_url'] = get_permalink();96 $query_params['clean_urls'] = 'false'; 97 } 98 99 $query_params['base_url'] = get_permalink(); 110 100 111 101 if ( array_key_exists( 'offset', $_GET ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended 112 $ params['offset'] = intval( $_GET['offset'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended102 $query_params['offset'] = intval( $_GET['offset'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended 113 103 } 114 104 115 105 if ( ! array_key_exists( 'category', $_GET ) && isset( $store_page_params['default_category_id'] ) && intval( $store_page_params['default_category_id'] ) > 0 ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended 116 $ params['default_category_id'] = $store_page_params['default_category_id'];117 } 118 119 $ params['lang'] = self::get_accept_language();106 $query_params['default_category_id'] = $store_page_params['default_category_id']; 107 } 108 109 $query_params['lang'] = self::get_accept_language(); 120 110 121 111 $storefront_view_params = array( 'show_root_categories', 'enable_catalog_on_one_page' ); … … 142 132 143 133 if ( strpos( $name, 'chameleon' ) !== false ) { 144 $name = str_replace( 'chameleon_', '', $name );145 $ params[ 'tplvar_ec.chameleon.' . $name ] = $value;134 $name = str_replace( 'chameleon_', '', $name ); 135 $query_params[ 'tplvar_ec.chameleon.' . $name ] = $value; 146 136 } else { 147 $ params[ 'tplvar_ec.storefront.' . $name ] = $value;137 $query_params[ 'tplvar_ec.storefront.' . $name ] = $value; 148 138 } 149 139 } … … 154 144 if ( ! empty( $hreflang_items ) ) { 155 145 foreach ( $hreflang_items as $lang => $link ) { 156 $params[ 'international_pages[' . $lang . ']' ] = $link; 157 } 158 } 159 160 if ( ! empty( $params['default_category_id'] ) ) { 161 $endpoint_params = array( 162 'mode' => 'category', 163 'id' => $params['default_category_id'], 164 ); 165 } 166 167 $url = self::get_endpoint_url( $endpoint_params ); 168 169 foreach ( $params as $name => $value ) { 170 $url .= $name . '=' . rawurlencode( $value ) . '&'; 171 } 172 173 $url = substr( $url, 0, -1 ); 146 $query_params[ 'international_pages[' . $lang . ']' ] = $link; 147 } 148 } 149 150 if ( self::is_need_to_use_new_endpoint() ) { 151 $query_params['getStaticContent'] = 'true'; 152 $query_params['slug'] = self::get_current_storefront_page_slug(); 153 154 if ( empty( $query_params['slug'] ) ) { 155 $query_params['storeRootPage'] = 'true'; 156 } else { 157 $query_params['storeRootPage'] = 'false'; 158 } 159 } else { 160 if ( ! empty( $query_params['default_category_id'] ) ) { 161 $endpoint_params = array( 162 'mode' => 'category', 163 'id' => $query_params['default_category_id'], 164 ); 165 } 166 167 if( empty( $endpoint_params ) ) { 168 $endpoint_params = self::get_endpoint_params(); 169 } 170 } 174 171 175 172 $dynamic_css = ''; … … 178 175 } 179 176 180 $cached_data = EcwidPlatform::get_from_static_pages_cache( $url ); 177 $cache_key = serialize($query_params); 178 179 $cached_data = EcwidPlatform::get_from_static_pages_cache( $cache_key ); 180 181 181 if ( $cached_data ) { 182 if ( isset( $cached_data->staticContent ) ) { 183 $static_content = $cached_data->staticContent; 184 } else { 185 $static_content = $cached_data; 186 } 187 182 188 $is_css_defined = ! empty( $dynamic_css ); 183 $is_css_already_set = in_array( $dynamic_css, $ cached_data->cssFiles, true ); //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase189 $is_css_already_set = in_array( $dynamic_css, $static_content->cssFiles, true ); //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 184 190 $is_home_page = Ecwid_Store_Page::is_store_home_page(); 185 191 186 192 if ( $is_home_page && $is_css_defined && ! $is_css_already_set ) { 187 $cached_data->cssFiles = array( $dynamic_css ); //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 188 189 EcwidPlatform::save_in_static_pages_cache( $url, $cached_data ); 190 } 191 192 return $cached_data; 193 } 194 195 $fetched_data = self::get_static_snapshot( $url, $dynamic_css ); 193 $static_content->cssFiles = array( $dynamic_css ); //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 194 195 if ( isset( $cached_data->staticContent ) ) { 196 $cached_data->staticContent = $static_content; 197 } else { 198 $cached_data = $static_content; 199 } 200 201 EcwidPlatform::save_in_static_pages_cache( $cache_key, $cached_data ); 202 } 203 204 return $static_content; 205 } 206 207 $fetched_data = self::get_static_snapshot( $endpoint_params, $query_params, $dynamic_css ); 196 208 197 209 return $fetched_data; 198 210 } 199 211 200 protected static function get_static_snapshot( $url, $dynamic_css = '' ) { 201 202 $fetched_data = EcwidPlatform::fetch_url( 203 $url, 204 array( 205 'timeout' => 3, 206 'headers' => array( 207 'ACCEPT-LANGUAGE' => self::get_accept_language(), 208 ), 209 ) 210 ); 211 212 if ( $fetched_data && isset( $fetched_data['data'] ) ) { 213 $fetched_data = json_decode( $fetched_data['data'] ); 214 215 if ( empty( $fetched_data ) || ! is_object( $fetched_data ) ) { 212 protected static function get_current_storefront_page_slug() { 213 $slug = ''; 214 215 $page_id = get_queried_object_id(); 216 $page_link = get_permalink( $page_id ); 217 $page_permalink = wp_make_link_relative( $page_link ); 218 219 $current_url = add_query_arg( null, null ); 220 221 $url = str_replace( $page_permalink, '/', $current_url ); 222 223 if ( preg_match( '/\/([^\/\?]+)/', $url, $matches ) ) { 224 $slug = $matches[1]; 225 } 226 227 return $slug; 228 } 229 230 protected static function get_static_snapshot( $endpoint_params, $query_params, $dynamic_css = '' ) { 231 232 if ( self::is_need_to_use_new_endpoint() ) { 233 $api = new Ecwid_Api_V3(); 234 $data = $api->get_storefront_widget_page( $query_params ); 235 236 if ( empty( $data->staticContent ) || ! is_object( $data->staticContent ) ) { //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 216 237 return null; 217 238 } 218 239 } else { 240 $api = new Ecwid_Api_V3(); 241 $data = $api->get_static_page( $endpoint_params, $query_params ); 242 243 if ( empty( $data ) || ! is_object( $data ) ) { 244 return null; 245 } 246 }//end if 247 248 if ( ! empty( $data ) ) { 219 249 //phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 250 251 if ( ! empty( $data->staticContent ) ) { 252 $static_content = $data->staticContent; 253 } else { 254 $static_content = $data; 255 } 256 220 257 if ( ! empty( $dynamic_css ) ) { 221 $ fetched_data->cssFiles = array( $dynamic_css );222 } 223 224 if ( ! empty( $ fetched_data->htmlCode ) ) {258 $static_content->cssFiles = array( $dynamic_css ); 259 } 260 261 if ( ! empty( $static_content->htmlCode ) ) { 225 262 $pattern = '/<img(.*?)>/is'; 226 263 227 $ fetched_data->htmlCode = preg_replace( $pattern, '<img $1 decoding="async" loading="lazy">', $fetched_data->htmlCode );264 $static_content->htmlCode = preg_replace( $pattern, '<img $1 decoding="async" loading="lazy">', $static_content->htmlCode ); 228 265 } 229 266 230 267 EcwidPlatform::encode_fields_with_emoji( 231 $ fetched_data,268 $static_content, 232 269 array( 'htmlCode', 'metaDescriptionHtml', 'ogTagsHtml', 'jsonLDHtml' ) 233 270 ); 234 271 235 if ( isset( $ fetched_data->lastUpdated ) ) {236 $last_update = substr( $ fetched_data->lastUpdated, 0, -3 );272 if ( isset( $static_content->lastUpdated ) ) { 273 $last_update = substr( $static_content->lastUpdated, 0, -3 ); 237 274 } else { 238 275 $last_update = time(); … … 240 277 //phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 241 278 279 if ( ! empty( $data->staticContent ) ) { 280 $data->staticContent = $static_content; 281 } 282 283 $cache_key = serialize($query_params); 284 242 285 EcwidPlatform::invalidate_static_pages_cache_from( $last_update ); 243 EcwidPlatform::save_in_static_pages_cache( $ url, $fetched_data );244 245 return $ fetched_data;286 EcwidPlatform::save_in_static_pages_cache( $cache_key, $data ); 287 288 return $static_content; 246 289 }//end if 247 290 … … 409 452 } 410 453 411 if ( get_option( self::OPTION_IS_ENABLED ) === '') {454 if ( get_option( self::OPTION_IS_ENABLED, self::OPTION_VALUE_AUTO ) === self::OPTION_VALUE_AUTO ) { 412 455 return true; 413 456 } … … 415 458 return false; 416 459 } 460 461 public static function is_need_to_use_new_endpoint() { 462 if ( get_option( self::OPTION_NEW_IS_ENABLED ) === self::OPTION_VALUE_ENABLED ) { 463 return true; 464 } 465 466 if ( get_option( self::OPTION_NEW_IS_ENABLED ) === self::OPTION_VALUE_DISABLED ) { 467 return false; 468 } 469 470 if ( get_option( self::OPTION_NEW_IS_ENABLED, self::OPTION_VALUE_AUTO ) === '' && get_ecwid_store_id() % 4 === 0 ) { 471 return true; 472 } 473 474 return false; 475 } 476 477 public function clear_cache( $old_value, $value, $option ) { 478 if( $old_value !== $value ) { 479 EcwidPlatform::clear_all_transients(); 480 } 481 } 417 482 } 418 483 -
ecwid-shopping-cart/tags/6.12.27/includes/shortcodes/class-ecwid-shortcode-productbrowser.php
r3223401 r3239265 63 63 $code .= '<div id="static-ec-store-container">'; 64 64 $code .= htmlspecialchars_decode( Ecwid_Static_Page::get_html_code() ); 65 $code .= '</div>'; 65 66 66 67 $js_code = Ecwid_Static_Page::get_js_code(); … … 68 69 $code .= sprintf( '<!--noptimize--><script id="ec-static-inline-js" data-cfasync="false" data-no-optimize="1" type="text/javascript">%s</script><!--/noptimize-->', $js_code ) . PHP_EOL; 69 70 } 70 $code .= '</div>';71 71 72 72 $force_dynamic_js_code = 'if( typeof window.ec.storefront.staticPages != "undefined" && typeof window.ec.storefront.staticPages.forceDynamicLoadingIfRequired != "undefined" ) { -
ecwid-shopping-cart/tags/6.12.27/lib/ecwid_api_v3.php
r3231865 r3239265 41 41 protected static $profile = null; 42 42 43 protected $_api_url; 44 protected $_stores_api_url; 45 protected $_categories_api_url; 46 protected $_products_api_url; 47 protected $_profile_api_url; 48 protected $_starter_site_api_url; 49 protected $_batch_requests_api_url; 43 protected $api_url; 44 protected $stores_api_url; 45 protected $categories_api_url; 46 protected $products_api_url; 47 protected $profile_api_url; 48 protected $starter_site_api_url; 49 protected $batch_requests_api_url; 50 protected $storefront_widget_pages_api_url; 51 protected $static_pages_api_url; 50 52 51 53 public function __construct() { 52 54 53 $this->store_id = EcwidPlatform::get_store_id(); 54 $this->_api_url = 'https://' . Ecwid_Config::get_api_domain() . '/api/v3/'; 55 $this->_stores_api_url = $this->_api_url . 'stores'; 56 57 $this->_categories_api_url = $this->_api_url . $this->store_id . '/categories'; 58 $this->_products_api_url = $this->_api_url . $this->store_id . '/products'; 59 $this->_profile_api_url = $this->_api_url . $this->store_id . '/profile'; 60 $this->_starter_site_api_url = $this->_api_url . $this->store_id . '/startersite'; 61 $this->_batch_requests_api_url = $this->_api_url . $this->store_id . '/batch'; 55 $this->store_id = EcwidPlatform::get_store_id(); 56 $this->api_url = 'https://' . Ecwid_Config::get_api_domain() . '/api/v3/'; 57 $this->stores_api_url = $this->api_url . 'stores'; 58 59 $this->categories_api_url = $this->api_url . $this->store_id . '/categories'; 60 $this->products_api_url = $this->api_url . $this->store_id . '/products'; 61 $this->profile_api_url = $this->api_url . $this->store_id . '/profile'; 62 $this->starter_site_api_url = $this->api_url . $this->store_id . '/startersite'; 63 $this->batch_requests_api_url = $this->api_url . $this->store_id . '/batch'; 64 $this->storefront_widget_pages_api_url = $this->api_url . $this->store_id . '/storefront-widget-pages'; 65 66 $this->static_pages_api_url = 'https://' . Ecwid_Config::get_static_pages_api_domain(); 62 67 63 68 add_option( self::OPTION_API_STATUS, self::API_STATUS_UNDEFINED ); … … 182 187 183 188 $url = $this->build_request_url( 184 $this-> _categories_api_url,189 $this->categories_api_url, 185 190 $params 186 191 ); … … 260 265 261 266 $url = $this->build_request_url( 262 $this-> _categories_api_url . '/' . $category_id,267 $this->categories_api_url . '/' . $category_id, 263 268 $params 264 269 ); … … 318 323 319 324 $url = $this->build_request_url( 320 $this-> _products_api_url . '/' . $product_id,325 $this->products_api_url . '/' . $product_id, 321 326 $params 322 327 ); … … 370 375 371 376 $url = $this->build_request_url( 372 $this-> _products_api_url,377 $this->products_api_url, 373 378 $params 374 379 ); … … 424 429 425 430 $url = $this->build_request_url( 426 $this-> _products_api_url . '/deleted',431 $this->products_api_url . '/deleted', 427 432 $params 428 433 ); … … 462 467 463 468 $url = $this->build_request_url( 464 $this-> _products_api_url,469 $this->products_api_url, 465 470 $params 466 471 ); … … 556 561 ); 557 562 558 $url = $this->build_request_url( $this-> _stores_api_url, $params );563 $url = $this->build_request_url( $this->stores_api_url, $params ); 559 564 560 565 $request = Ecwid_Http::create_get( … … 583 588 } 584 589 585 $url = $this-> _api_url . $this->store_id . '/latest-stats';590 $url = $this->api_url . $this->store_id . '/latest-stats'; 586 591 587 592 $params = array(); … … 635 640 636 641 $options = $this->build_request_headers(); 637 $url = $this->build_request_url( $this-> _profile_api_url, $params );642 $url = $this->build_request_url( $this->profile_api_url, $params ); 638 643 639 644 if ( empty( $options ) ) { … … 685 690 $request_params = array(); 686 691 687 $url = $this->build_request_url( $this-> _profile_api_url, $request_params );692 $url = $this->build_request_url( $this->profile_api_url, $request_params ); 688 693 689 694 $result = $this->_do_put( $url, $params ); … … 830 835 'returnApiToken' => 'true', 831 836 ); 832 $url = $this->build_request_url( $this-> _stores_api_url, $request_params );837 $url = $this->build_request_url( $this->stores_api_url, $request_params ); 833 838 834 839 $result = EcwidPlatform::http_post_request( … … 891 896 public function create_product( $params ) { 892 897 $request_params = array(); 893 $url = $this->build_request_url( $this-> _products_api_url, $request_params );898 $url = $this->build_request_url( $this->products_api_url, $request_params ); 894 899 895 900 $params = $this->_sanitize_product_data( $params ); … … 903 908 $request_params = array(); 904 909 905 $url = $this->build_request_url( $this-> _products_api_url . '/' . $params['productId'] . '/combinations', $request_params );910 $url = $this->build_request_url( $this->products_api_url . '/' . $params['productId'] . '/combinations', $request_params ); 906 911 907 912 $result = $this->_do_post( $url, $params ); … … 913 918 $request_params = array(); 914 919 915 $url = $this->build_request_url( $this-> _products_api_url . '/' . $product_id, $request_params );920 $url = $this->build_request_url( $this->products_api_url . '/' . $product_id, $request_params ); 916 921 917 922 $params = $this->_sanitize_product_data( $params ); … … 951 956 $request_params = array(); 952 957 953 $url = $this->build_request_url( $this-> _categories_api_url, $request_params );958 $url = $this->build_request_url( $this->categories_api_url, $request_params ); 954 959 955 960 $params = $this->_sanitize_category_data( $params ); … … 964 969 $request_params = array(); 965 970 966 $url = $this->build_request_url( $this-> _categories_api_url . '/' . $category_id, $request_params );971 $url = $this->build_request_url( $this->categories_api_url . '/' . $category_id, $request_params ); 967 972 968 973 $params = $this->_sanitize_category_data( $params ); … … 995 1000 'Authorization' => 'Bearer ' . self::get_token(), 996 1001 ), 997 'url' => $this->build_request_url( $this-> _products_api_url . '/' . $id, $request_params ),1002 'url' => $this->build_request_url( $this->products_api_url . '/' . $id, $request_params ), 998 1003 ); 999 1004 } … … 1006 1011 public function upload_category_image( $params ) { 1007 1012 $request_params = array(); 1008 $url = $this->build_request_url( $this-> _categories_api_url . '/' . $params['categoryId'] . '/image', $request_params );1013 $url = $this->build_request_url( $this->categories_api_url . '/' . $params['categoryId'] . '/image', $request_params ); 1009 1014 1010 1015 $result = $this->_do_post( $url, $params['data'], true ); … … 1015 1020 public function upload_product_image( $params ) { 1016 1021 $request_params = array(); 1017 $url = $this->build_request_url( $this-> _products_api_url . '/' . $params['productId'] . '/image', $request_params );1022 $url = $this->build_request_url( $this->products_api_url . '/' . $params['productId'] . '/image', $request_params ); 1018 1023 1019 1024 $result = $this->_do_post( $url, $params['data'], true ); … … 1024 1029 public function upload_product_gallery_image( $params ) { 1025 1030 $request_params = array(); 1026 $url = $this->build_request_url( $this-> _products_api_url . '/' . $params['productId'] . '/gallery', $request_params );1031 $url = $this->build_request_url( $this->products_api_url . '/' . $params['productId'] . '/gallery', $request_params ); 1027 1032 1028 1033 $result = $this->_do_post( $url, $params['data'], true ); … … 1034 1039 public function upload_product_variation_image( $params ) { 1035 1040 $request_params = array(); 1036 $url = $this->build_request_url( $this-> _products_api_url . '/' . $params['productId'] . '/combinations/' . $params['variationId'] . '/image', $request_params );1041 $url = $this->build_request_url( $this->products_api_url . '/' . $params['productId'] . '/combinations/' . $params['variationId'] . '/image', $request_params ); 1037 1042 1038 1043 $result = $this->_do_post( $url, $params['data'], true ); … … 1045 1050 1046 1051 $options = $this->build_request_headers(); 1047 $url = $this->build_request_url( $this-> _starter_site_api_url, $request_params );1052 $url = $this->build_request_url( $this->starter_site_api_url, $request_params ); 1048 1053 1049 1054 if ( empty( $options ) ) { … … 1150 1155 'stopOnFirstFailure' => 'false', 1151 1156 ); 1152 $url = $this->build_request_url( $this-> _batch_requests_api_url, $request_params );1157 $url = $this->build_request_url( $this->batch_requests_api_url, $request_params ); 1153 1158 1154 1159 $result = $this->_do_post( $url, $params ); … … 1163 1168 1164 1169 $options = $this->build_request_headers(); 1165 $url = $this->build_request_url( $this-> _batch_requests_api_url, $params );1170 $url = $this->build_request_url( $this->batch_requests_api_url, $params ); 1166 1171 1167 1172 if ( empty( $options ) ) { … … 1284 1289 ); 1285 1290 } 1291 1292 public function build_static_pages_request_url( $params ) { 1293 $allowed_modes = array( 1294 'home', 1295 'product', 1296 'category' 1297 ); 1298 $default_mode = 'home'; 1299 1300 if( empty( $params['mode'] ) || ! in_array( $params['mode'], $allowed_modes ) ) { 1301 $mode = $default_mode; 1302 } else { 1303 $mode = $params['mode']; 1304 } 1305 1306 if( empty( $params['id'] ) || $mode === $default_mode ) { 1307 $id = false; 1308 } else { 1309 $id = intval($params['id']); 1310 } 1311 1312 $url = $this->static_pages_api_url . '/' . $mode . '-page/' . $this->store_id; 1313 1314 if( ! empty( $id ) ) { 1315 $url .= '/' . $id; 1316 } 1317 1318 $url .= '/static-code'; 1319 1320 return $url; 1321 } 1322 1323 public function get_static_page( $endpoint_params, $query_params ) { 1324 1325 $url = $this->build_static_pages_request_url( $endpoint_params ); 1326 1327 $options = array( 1328 'timeout' => 3 1329 ); 1330 1331 $url = $this->build_request_url( 1332 $url, 1333 $query_params 1334 ); 1335 1336 $result = EcwidPlatform::fetch_url( $url, $options ); 1337 1338 if ( $result['code'] != '200' ) { 1339 return false; 1340 } 1341 1342 $data = json_decode( $result['data'] ); 1343 1344 return $data; 1345 } 1346 1347 public function get_storefront_widget_page( $params ) { 1348 1349 if ( empty( $params['slug'] ) && empty( $params['storeRootPage'] ) ) { 1350 return false; 1351 } 1352 1353 $options = $this->build_request_headers(); 1354 1355 $options['timeout'] = 3; 1356 1357 $url = $this->build_request_url( 1358 $this->storefront_widget_pages_api_url, 1359 $params 1360 ); 1361 1362 $result = EcwidPlatform::fetch_url( $url, $options ); 1363 1364 if ( $result['code'] != '200' ) { 1365 return false; 1366 } 1367 1368 $data = json_decode( $result['data'] ); 1369 1370 return $data; 1371 } 1286 1372 } -
ecwid-shopping-cart/tags/6.12.27/lib/ecwid_platform.php
r3202954 r3239265 10 10 protected static $ecwid_plugin_data = null; 11 11 12 const FORCES_ CATALOG_CACHE_RESET_VALID_FROM = 'forced_catalog_cache_reset_valid_from';12 const FORCES_PAGES_CACHE_RESET_VALID_FROM = 'forced_pages_cache_reset_valid_from'; 13 13 const CATEGORIES_CACHE_VALID_FROM = 'categories_cache_valid_from'; 14 14 const PRODUCTS_CACHE_VALID_FROM = 'products_cache_valid_from'; 15 15 const PROFILE_CACHE_VALID_FROM = 'profile_cache_valid_from'; 16 const CATALOG_CACHE_VALID_FROM = 'catalog_valid_from';16 const PAGES_CACHE_VALID_FROM = 'pages_valid_from'; 17 17 18 18 const OPTION_LOG_CACHE = 'ecwid_log_cache'; … … 409 409 410 410 public static function save_in_static_pages_cache( $url, $data ) { 411 self::save_in_cache( $url, ' catalog', $data, WEEK_IN_SECONDS );411 self::save_in_cache( $url, 'pages', $data, WEEK_IN_SECONDS ); 412 412 } 413 413 … … 476 476 477 477 public static function get_from_static_pages_cache( $key ) { 478 $cache_name = self::_build_cache_name( $key, ' catalog' );478 $cache_name = self::_build_cache_name( $key, 'pages' ); 479 479 480 480 $result = self::cache_get( $cache_name ); … … 484 484 self::get( self::PRODUCTS_CACHE_VALID_FROM ), 485 485 self::get( self::PROFILE_CACHE_VALID_FROM ), 486 self::get( self::FORCES_ CATALOG_CACHE_RESET_VALID_FROM )486 self::get( self::FORCES_PAGES_CACHE_RESET_VALID_FROM ) 487 487 ); 488 488 … … 496 496 ); 497 497 498 if ( $result && isset( $result['data']->lastUpdated ) && $result['data']->lastUpdated > $valid_from ) { 499 return $result['data']; 498 if( $result ) { 499 if( isset( $result['data']->staticContent ) ) { 500 $data = $result['data']->staticContent; 501 } else { 502 $data = $result['data']; 503 } 504 } 505 506 if ( $result && isset( $data->lastUpdated ) && $data->lastUpdated > $valid_from ) { 507 return $data; 500 508 } else { 501 self::cache_reset( $cache_name );502 503 $page_id = get_the_ID();504 if ( ! empty( $page_id ) ) {505 do_action( 'ecwid_clean_external_cache_for_page', $page_id );506 }507 }509 self::cache_reset( $cache_name ); 510 511 $page_id = get_the_ID(); 512 if ( ! empty( $page_id ) ) { 513 do_action( 'ecwid_clean_external_cache_for_page', $page_id ); 514 } 515 } 508 516 509 517 return false; … … 565 573 566 574 public static function invalidate_static_pages_cache_from( $time = null ) { 567 self::_invalidate_cache_from( self:: CATALOG_CACHE_VALID_FROM, $time );575 self::_invalidate_cache_from( self::PAGES_CACHE_VALID_FROM, $time ); 568 576 } 569 577 570 578 public static function force_static_pages_cache_reset( $time = null ) { 571 579 $time = is_null( $time ) ? time() : $time; 572 self::set( self::FORCES_ CATALOG_CACHE_RESET_VALID_FROM, $time );580 self::set( self::FORCES_PAGES_CACHE_RESET_VALID_FROM, $time ); 573 581 } 574 582 -
ecwid-shopping-cart/tags/6.12.27/readme.txt
r3231865 r3239265 6 6 Requires at least: 4.4 7 7 Tested up to: 6.7 8 Stable tag: 6.12.2 68 Stable tag: 6.12.27 9 9 10 10 Powerful, easy to use ecommerce shopping cart for WordPress. Sell on Facebook and Instagram. iPhone & Android apps. Superb support. Free plan available. … … 154 154 155 155 == Changelog == 156 = 6.12.27 - Feb 12, 2024 = 157 - Fixed an issue in the admin area where the product popup would not work on pages with a custom type. 158 - Internal improvements and optimizations. 159 156 160 = 6.12.26 - Jan 30, 2024 = 157 - Improved compatibility with the WPML plugin. Fixed an issue where translation loading for the `sitepress-multilingual-cs`domain was triggered too early on some ecommerce sites.161 - Improved compatibility with the WPML plugin. Fixed an issue where translation loading for the "sitepress-multilingual-cs" domain was triggered too early on some ecommerce sites. 158 162 - Fixed an issue where refreshing a product page would sometimes redirect users to the main storefront page. 159 163 - Internal improvements and optimizations. -
ecwid-shopping-cart/trunk/ecwid-shopping-cart.php
r3231865 r3239265 6 6 Text Domain: ecwid-shopping-cart 7 7 Author: Ecwid Ecommerce 8 Version: 6.12.2 68 Version: 6.12.27 9 9 Author URI: https://ecwid.to/ecwid-site 10 10 License: GPLv2 or later … … 1697 1697 ), 1698 1698 1699 Ecwid_Static_Page::OPTION_NEW_IS_ENABLED => array( 1700 'values' => array( 1701 Ecwid_Static_Page::OPTION_VALUE_AUTO, 1702 Ecwid_Static_Page::OPTION_VALUE_ENABLED, 1703 Ecwid_Static_Page::OPTION_VALUE_DISABLED 1704 ) 1705 ), 1706 1699 1707 Ec_Store_Defer_Init::OPTION_NAME => array( 1700 1708 'values' => array( -
ecwid-shopping-cart/trunk/includes/class-ecwid-product-popup.php
r3223401 r3239265 36 36 } 37 37 38 if ( $is_post_screen && ! in_array( $current_screen->post_type, array( 'page', 'post' ) ) ) { //phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict 38 $post_types = get_post_types( array( 'public' => true ) ); 39 if ( $is_post_screen && ! in_array( $current_screen->post_type, $post_types, true ) ) { 39 40 return; 40 41 } -
ecwid-shopping-cart/trunk/includes/class-ecwid-static-page.php
r3231865 r3239265 3 3 class Ecwid_Static_Page { 4 4 5 const OPTION_IS_ENABLED = 'ecwid_static_home_page_enabled'; 5 const OPTION_IS_ENABLED = 'ecwid_static_home_page_enabled'; 6 const OPTION_NEW_IS_ENABLED = 'ecwid_new_static_home_page_enabled'; 6 7 7 8 const OPTION_VALUE_ENABLED = 'Y'; … … 19 20 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 20 21 } 22 23 add_action( 'update_option_' . self::OPTION_NEW_IS_ENABLED, array( $this, 'clear_cache' ), 10, 3 ); 21 24 } 22 25 … … 54 57 } 55 58 56 protected static function get_endpoint_url( $params = false ) { 57 58 if ( ! $params ) { 59 if ( ecwid_is_applicable_escaped_fragment() ) { 60 $params = ecwid_parse_escaped_fragment(); 61 } else { 62 $params = Ecwid_Seo_Links::maybe_extract_html_catalog_params(); 63 } 64 } 59 protected static function get_endpoint_params() { 60 61 if ( ecwid_is_applicable_escaped_fragment() ) { 62 $params = ecwid_parse_escaped_fragment(); 63 } else { 64 $params = Ecwid_Seo_Links::maybe_extract_html_catalog_params(); 65 } 65 66 66 67 if ( ! isset( $params['mode'] ) ) { … … 68 69 } 69 70 70 $url = 'https://' . Ecwid_Config::get_static_pages_api_domain() . '/'; 71 $url .= sprintf( '%s-page/', $params['mode'] ); 72 $url .= sprintf( '%s/', get_ecwid_store_id() ); 73 74 if ( isset( $params['id'] ) ) { 75 $url .= sprintf( '%s/', $params['id'] ); 76 } 77 78 $url .= 'static-code?'; 79 80 return $url; 71 return $params; 81 72 } 82 73 … … 89 80 90 81 $store_page_params = Ecwid_Store_Page::get_store_page_params(); 91 $endpoint_params = false; 82 $endpoint_params = false; 83 $query_params = array(); 92 84 93 85 // for cases of early access to the page if the cache is empty and need to get store block params … … 99 91 } 100 92 101 $params = array();102 103 93 if ( Ecwid_Seo_Links::is_enabled() || ecwid_is_demo_store() ) { 104 $ params['clean_urls'] = 'true';94 $query_params['clean_urls'] = 'true'; 105 95 } else { 106 $ params['clean_urls'] = 'false';107 } 108 109 $ params['base_url'] = get_permalink();96 $query_params['clean_urls'] = 'false'; 97 } 98 99 $query_params['base_url'] = get_permalink(); 110 100 111 101 if ( array_key_exists( 'offset', $_GET ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended 112 $ params['offset'] = intval( $_GET['offset'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended102 $query_params['offset'] = intval( $_GET['offset'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended 113 103 } 114 104 115 105 if ( ! array_key_exists( 'category', $_GET ) && isset( $store_page_params['default_category_id'] ) && intval( $store_page_params['default_category_id'] ) > 0 ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended 116 $ params['default_category_id'] = $store_page_params['default_category_id'];117 } 118 119 $ params['lang'] = self::get_accept_language();106 $query_params['default_category_id'] = $store_page_params['default_category_id']; 107 } 108 109 $query_params['lang'] = self::get_accept_language(); 120 110 121 111 $storefront_view_params = array( 'show_root_categories', 'enable_catalog_on_one_page' ); … … 142 132 143 133 if ( strpos( $name, 'chameleon' ) !== false ) { 144 $name = str_replace( 'chameleon_', '', $name );145 $ params[ 'tplvar_ec.chameleon.' . $name ] = $value;134 $name = str_replace( 'chameleon_', '', $name ); 135 $query_params[ 'tplvar_ec.chameleon.' . $name ] = $value; 146 136 } else { 147 $ params[ 'tplvar_ec.storefront.' . $name ] = $value;137 $query_params[ 'tplvar_ec.storefront.' . $name ] = $value; 148 138 } 149 139 } … … 154 144 if ( ! empty( $hreflang_items ) ) { 155 145 foreach ( $hreflang_items as $lang => $link ) { 156 $params[ 'international_pages[' . $lang . ']' ] = $link; 157 } 158 } 159 160 if ( ! empty( $params['default_category_id'] ) ) { 161 $endpoint_params = array( 162 'mode' => 'category', 163 'id' => $params['default_category_id'], 164 ); 165 } 166 167 $url = self::get_endpoint_url( $endpoint_params ); 168 169 foreach ( $params as $name => $value ) { 170 $url .= $name . '=' . rawurlencode( $value ) . '&'; 171 } 172 173 $url = substr( $url, 0, -1 ); 146 $query_params[ 'international_pages[' . $lang . ']' ] = $link; 147 } 148 } 149 150 if ( self::is_need_to_use_new_endpoint() ) { 151 $query_params['getStaticContent'] = 'true'; 152 $query_params['slug'] = self::get_current_storefront_page_slug(); 153 154 if ( empty( $query_params['slug'] ) ) { 155 $query_params['storeRootPage'] = 'true'; 156 } else { 157 $query_params['storeRootPage'] = 'false'; 158 } 159 } else { 160 if ( ! empty( $query_params['default_category_id'] ) ) { 161 $endpoint_params = array( 162 'mode' => 'category', 163 'id' => $query_params['default_category_id'], 164 ); 165 } 166 167 if( empty( $endpoint_params ) ) { 168 $endpoint_params = self::get_endpoint_params(); 169 } 170 } 174 171 175 172 $dynamic_css = ''; … … 178 175 } 179 176 180 $cached_data = EcwidPlatform::get_from_static_pages_cache( $url ); 177 $cache_key = serialize($query_params); 178 179 $cached_data = EcwidPlatform::get_from_static_pages_cache( $cache_key ); 180 181 181 if ( $cached_data ) { 182 if ( isset( $cached_data->staticContent ) ) { 183 $static_content = $cached_data->staticContent; 184 } else { 185 $static_content = $cached_data; 186 } 187 182 188 $is_css_defined = ! empty( $dynamic_css ); 183 $is_css_already_set = in_array( $dynamic_css, $ cached_data->cssFiles, true ); //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase189 $is_css_already_set = in_array( $dynamic_css, $static_content->cssFiles, true ); //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 184 190 $is_home_page = Ecwid_Store_Page::is_store_home_page(); 185 191 186 192 if ( $is_home_page && $is_css_defined && ! $is_css_already_set ) { 187 $cached_data->cssFiles = array( $dynamic_css ); //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 188 189 EcwidPlatform::save_in_static_pages_cache( $url, $cached_data ); 190 } 191 192 return $cached_data; 193 } 194 195 $fetched_data = self::get_static_snapshot( $url, $dynamic_css ); 193 $static_content->cssFiles = array( $dynamic_css ); //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 194 195 if ( isset( $cached_data->staticContent ) ) { 196 $cached_data->staticContent = $static_content; 197 } else { 198 $cached_data = $static_content; 199 } 200 201 EcwidPlatform::save_in_static_pages_cache( $cache_key, $cached_data ); 202 } 203 204 return $static_content; 205 } 206 207 $fetched_data = self::get_static_snapshot( $endpoint_params, $query_params, $dynamic_css ); 196 208 197 209 return $fetched_data; 198 210 } 199 211 200 protected static function get_static_snapshot( $url, $dynamic_css = '' ) { 201 202 $fetched_data = EcwidPlatform::fetch_url( 203 $url, 204 array( 205 'timeout' => 3, 206 'headers' => array( 207 'ACCEPT-LANGUAGE' => self::get_accept_language(), 208 ), 209 ) 210 ); 211 212 if ( $fetched_data && isset( $fetched_data['data'] ) ) { 213 $fetched_data = json_decode( $fetched_data['data'] ); 214 215 if ( empty( $fetched_data ) || ! is_object( $fetched_data ) ) { 212 protected static function get_current_storefront_page_slug() { 213 $slug = ''; 214 215 $page_id = get_queried_object_id(); 216 $page_link = get_permalink( $page_id ); 217 $page_permalink = wp_make_link_relative( $page_link ); 218 219 $current_url = add_query_arg( null, null ); 220 221 $url = str_replace( $page_permalink, '/', $current_url ); 222 223 if ( preg_match( '/\/([^\/\?]+)/', $url, $matches ) ) { 224 $slug = $matches[1]; 225 } 226 227 return $slug; 228 } 229 230 protected static function get_static_snapshot( $endpoint_params, $query_params, $dynamic_css = '' ) { 231 232 if ( self::is_need_to_use_new_endpoint() ) { 233 $api = new Ecwid_Api_V3(); 234 $data = $api->get_storefront_widget_page( $query_params ); 235 236 if ( empty( $data->staticContent ) || ! is_object( $data->staticContent ) ) { //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 216 237 return null; 217 238 } 218 239 } else { 240 $api = new Ecwid_Api_V3(); 241 $data = $api->get_static_page( $endpoint_params, $query_params ); 242 243 if ( empty( $data ) || ! is_object( $data ) ) { 244 return null; 245 } 246 }//end if 247 248 if ( ! empty( $data ) ) { 219 249 //phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 250 251 if ( ! empty( $data->staticContent ) ) { 252 $static_content = $data->staticContent; 253 } else { 254 $static_content = $data; 255 } 256 220 257 if ( ! empty( $dynamic_css ) ) { 221 $ fetched_data->cssFiles = array( $dynamic_css );222 } 223 224 if ( ! empty( $ fetched_data->htmlCode ) ) {258 $static_content->cssFiles = array( $dynamic_css ); 259 } 260 261 if ( ! empty( $static_content->htmlCode ) ) { 225 262 $pattern = '/<img(.*?)>/is'; 226 263 227 $ fetched_data->htmlCode = preg_replace( $pattern, '<img $1 decoding="async" loading="lazy">', $fetched_data->htmlCode );264 $static_content->htmlCode = preg_replace( $pattern, '<img $1 decoding="async" loading="lazy">', $static_content->htmlCode ); 228 265 } 229 266 230 267 EcwidPlatform::encode_fields_with_emoji( 231 $ fetched_data,268 $static_content, 232 269 array( 'htmlCode', 'metaDescriptionHtml', 'ogTagsHtml', 'jsonLDHtml' ) 233 270 ); 234 271 235 if ( isset( $ fetched_data->lastUpdated ) ) {236 $last_update = substr( $ fetched_data->lastUpdated, 0, -3 );272 if ( isset( $static_content->lastUpdated ) ) { 273 $last_update = substr( $static_content->lastUpdated, 0, -3 ); 237 274 } else { 238 275 $last_update = time(); … … 240 277 //phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase 241 278 279 if ( ! empty( $data->staticContent ) ) { 280 $data->staticContent = $static_content; 281 } 282 283 $cache_key = serialize($query_params); 284 242 285 EcwidPlatform::invalidate_static_pages_cache_from( $last_update ); 243 EcwidPlatform::save_in_static_pages_cache( $ url, $fetched_data );244 245 return $ fetched_data;286 EcwidPlatform::save_in_static_pages_cache( $cache_key, $data ); 287 288 return $static_content; 246 289 }//end if 247 290 … … 409 452 } 410 453 411 if ( get_option( self::OPTION_IS_ENABLED ) === '') {454 if ( get_option( self::OPTION_IS_ENABLED, self::OPTION_VALUE_AUTO ) === self::OPTION_VALUE_AUTO ) { 412 455 return true; 413 456 } … … 415 458 return false; 416 459 } 460 461 public static function is_need_to_use_new_endpoint() { 462 if ( get_option( self::OPTION_NEW_IS_ENABLED ) === self::OPTION_VALUE_ENABLED ) { 463 return true; 464 } 465 466 if ( get_option( self::OPTION_NEW_IS_ENABLED ) === self::OPTION_VALUE_DISABLED ) { 467 return false; 468 } 469 470 if ( get_option( self::OPTION_NEW_IS_ENABLED, self::OPTION_VALUE_AUTO ) === '' && get_ecwid_store_id() % 4 === 0 ) { 471 return true; 472 } 473 474 return false; 475 } 476 477 public function clear_cache( $old_value, $value, $option ) { 478 if( $old_value !== $value ) { 479 EcwidPlatform::clear_all_transients(); 480 } 481 } 417 482 } 418 483 -
ecwid-shopping-cart/trunk/includes/shortcodes/class-ecwid-shortcode-productbrowser.php
r3223401 r3239265 63 63 $code .= '<div id="static-ec-store-container">'; 64 64 $code .= htmlspecialchars_decode( Ecwid_Static_Page::get_html_code() ); 65 $code .= '</div>'; 65 66 66 67 $js_code = Ecwid_Static_Page::get_js_code(); … … 68 69 $code .= sprintf( '<!--noptimize--><script id="ec-static-inline-js" data-cfasync="false" data-no-optimize="1" type="text/javascript">%s</script><!--/noptimize-->', $js_code ) . PHP_EOL; 69 70 } 70 $code .= '</div>';71 71 72 72 $force_dynamic_js_code = 'if( typeof window.ec.storefront.staticPages != "undefined" && typeof window.ec.storefront.staticPages.forceDynamicLoadingIfRequired != "undefined" ) { -
ecwid-shopping-cart/trunk/lib/ecwid_api_v3.php
r3231865 r3239265 41 41 protected static $profile = null; 42 42 43 protected $_api_url; 44 protected $_stores_api_url; 45 protected $_categories_api_url; 46 protected $_products_api_url; 47 protected $_profile_api_url; 48 protected $_starter_site_api_url; 49 protected $_batch_requests_api_url; 43 protected $api_url; 44 protected $stores_api_url; 45 protected $categories_api_url; 46 protected $products_api_url; 47 protected $profile_api_url; 48 protected $starter_site_api_url; 49 protected $batch_requests_api_url; 50 protected $storefront_widget_pages_api_url; 51 protected $static_pages_api_url; 50 52 51 53 public function __construct() { 52 54 53 $this->store_id = EcwidPlatform::get_store_id(); 54 $this->_api_url = 'https://' . Ecwid_Config::get_api_domain() . '/api/v3/'; 55 $this->_stores_api_url = $this->_api_url . 'stores'; 56 57 $this->_categories_api_url = $this->_api_url . $this->store_id . '/categories'; 58 $this->_products_api_url = $this->_api_url . $this->store_id . '/products'; 59 $this->_profile_api_url = $this->_api_url . $this->store_id . '/profile'; 60 $this->_starter_site_api_url = $this->_api_url . $this->store_id . '/startersite'; 61 $this->_batch_requests_api_url = $this->_api_url . $this->store_id . '/batch'; 55 $this->store_id = EcwidPlatform::get_store_id(); 56 $this->api_url = 'https://' . Ecwid_Config::get_api_domain() . '/api/v3/'; 57 $this->stores_api_url = $this->api_url . 'stores'; 58 59 $this->categories_api_url = $this->api_url . $this->store_id . '/categories'; 60 $this->products_api_url = $this->api_url . $this->store_id . '/products'; 61 $this->profile_api_url = $this->api_url . $this->store_id . '/profile'; 62 $this->starter_site_api_url = $this->api_url . $this->store_id . '/startersite'; 63 $this->batch_requests_api_url = $this->api_url . $this->store_id . '/batch'; 64 $this->storefront_widget_pages_api_url = $this->api_url . $this->store_id . '/storefront-widget-pages'; 65 66 $this->static_pages_api_url = 'https://' . Ecwid_Config::get_static_pages_api_domain(); 62 67 63 68 add_option( self::OPTION_API_STATUS, self::API_STATUS_UNDEFINED ); … … 182 187 183 188 $url = $this->build_request_url( 184 $this-> _categories_api_url,189 $this->categories_api_url, 185 190 $params 186 191 ); … … 260 265 261 266 $url = $this->build_request_url( 262 $this-> _categories_api_url . '/' . $category_id,267 $this->categories_api_url . '/' . $category_id, 263 268 $params 264 269 ); … … 318 323 319 324 $url = $this->build_request_url( 320 $this-> _products_api_url . '/' . $product_id,325 $this->products_api_url . '/' . $product_id, 321 326 $params 322 327 ); … … 370 375 371 376 $url = $this->build_request_url( 372 $this-> _products_api_url,377 $this->products_api_url, 373 378 $params 374 379 ); … … 424 429 425 430 $url = $this->build_request_url( 426 $this-> _products_api_url . '/deleted',431 $this->products_api_url . '/deleted', 427 432 $params 428 433 ); … … 462 467 463 468 $url = $this->build_request_url( 464 $this-> _products_api_url,469 $this->products_api_url, 465 470 $params 466 471 ); … … 556 561 ); 557 562 558 $url = $this->build_request_url( $this-> _stores_api_url, $params );563 $url = $this->build_request_url( $this->stores_api_url, $params ); 559 564 560 565 $request = Ecwid_Http::create_get( … … 583 588 } 584 589 585 $url = $this-> _api_url . $this->store_id . '/latest-stats';590 $url = $this->api_url . $this->store_id . '/latest-stats'; 586 591 587 592 $params = array(); … … 635 640 636 641 $options = $this->build_request_headers(); 637 $url = $this->build_request_url( $this-> _profile_api_url, $params );642 $url = $this->build_request_url( $this->profile_api_url, $params ); 638 643 639 644 if ( empty( $options ) ) { … … 685 690 $request_params = array(); 686 691 687 $url = $this->build_request_url( $this-> _profile_api_url, $request_params );692 $url = $this->build_request_url( $this->profile_api_url, $request_params ); 688 693 689 694 $result = $this->_do_put( $url, $params ); … … 830 835 'returnApiToken' => 'true', 831 836 ); 832 $url = $this->build_request_url( $this-> _stores_api_url, $request_params );837 $url = $this->build_request_url( $this->stores_api_url, $request_params ); 833 838 834 839 $result = EcwidPlatform::http_post_request( … … 891 896 public function create_product( $params ) { 892 897 $request_params = array(); 893 $url = $this->build_request_url( $this-> _products_api_url, $request_params );898 $url = $this->build_request_url( $this->products_api_url, $request_params ); 894 899 895 900 $params = $this->_sanitize_product_data( $params ); … … 903 908 $request_params = array(); 904 909 905 $url = $this->build_request_url( $this-> _products_api_url . '/' . $params['productId'] . '/combinations', $request_params );910 $url = $this->build_request_url( $this->products_api_url . '/' . $params['productId'] . '/combinations', $request_params ); 906 911 907 912 $result = $this->_do_post( $url, $params ); … … 913 918 $request_params = array(); 914 919 915 $url = $this->build_request_url( $this-> _products_api_url . '/' . $product_id, $request_params );920 $url = $this->build_request_url( $this->products_api_url . '/' . $product_id, $request_params ); 916 921 917 922 $params = $this->_sanitize_product_data( $params ); … … 951 956 $request_params = array(); 952 957 953 $url = $this->build_request_url( $this-> _categories_api_url, $request_params );958 $url = $this->build_request_url( $this->categories_api_url, $request_params ); 954 959 955 960 $params = $this->_sanitize_category_data( $params ); … … 964 969 $request_params = array(); 965 970 966 $url = $this->build_request_url( $this-> _categories_api_url . '/' . $category_id, $request_params );971 $url = $this->build_request_url( $this->categories_api_url . '/' . $category_id, $request_params ); 967 972 968 973 $params = $this->_sanitize_category_data( $params ); … … 995 1000 'Authorization' => 'Bearer ' . self::get_token(), 996 1001 ), 997 'url' => $this->build_request_url( $this-> _products_api_url . '/' . $id, $request_params ),1002 'url' => $this->build_request_url( $this->products_api_url . '/' . $id, $request_params ), 998 1003 ); 999 1004 } … … 1006 1011 public function upload_category_image( $params ) { 1007 1012 $request_params = array(); 1008 $url = $this->build_request_url( $this-> _categories_api_url . '/' . $params['categoryId'] . '/image', $request_params );1013 $url = $this->build_request_url( $this->categories_api_url . '/' . $params['categoryId'] . '/image', $request_params ); 1009 1014 1010 1015 $result = $this->_do_post( $url, $params['data'], true ); … … 1015 1020 public function upload_product_image( $params ) { 1016 1021 $request_params = array(); 1017 $url = $this->build_request_url( $this-> _products_api_url . '/' . $params['productId'] . '/image', $request_params );1022 $url = $this->build_request_url( $this->products_api_url . '/' . $params['productId'] . '/image', $request_params ); 1018 1023 1019 1024 $result = $this->_do_post( $url, $params['data'], true ); … … 1024 1029 public function upload_product_gallery_image( $params ) { 1025 1030 $request_params = array(); 1026 $url = $this->build_request_url( $this-> _products_api_url . '/' . $params['productId'] . '/gallery', $request_params );1031 $url = $this->build_request_url( $this->products_api_url . '/' . $params['productId'] . '/gallery', $request_params ); 1027 1032 1028 1033 $result = $this->_do_post( $url, $params['data'], true ); … … 1034 1039 public function upload_product_variation_image( $params ) { 1035 1040 $request_params = array(); 1036 $url = $this->build_request_url( $this-> _products_api_url . '/' . $params['productId'] . '/combinations/' . $params['variationId'] . '/image', $request_params );1041 $url = $this->build_request_url( $this->products_api_url . '/' . $params['productId'] . '/combinations/' . $params['variationId'] . '/image', $request_params ); 1037 1042 1038 1043 $result = $this->_do_post( $url, $params['data'], true ); … … 1045 1050 1046 1051 $options = $this->build_request_headers(); 1047 $url = $this->build_request_url( $this-> _starter_site_api_url, $request_params );1052 $url = $this->build_request_url( $this->starter_site_api_url, $request_params ); 1048 1053 1049 1054 if ( empty( $options ) ) { … … 1150 1155 'stopOnFirstFailure' => 'false', 1151 1156 ); 1152 $url = $this->build_request_url( $this-> _batch_requests_api_url, $request_params );1157 $url = $this->build_request_url( $this->batch_requests_api_url, $request_params ); 1153 1158 1154 1159 $result = $this->_do_post( $url, $params ); … … 1163 1168 1164 1169 $options = $this->build_request_headers(); 1165 $url = $this->build_request_url( $this-> _batch_requests_api_url, $params );1170 $url = $this->build_request_url( $this->batch_requests_api_url, $params ); 1166 1171 1167 1172 if ( empty( $options ) ) { … … 1284 1289 ); 1285 1290 } 1291 1292 public function build_static_pages_request_url( $params ) { 1293 $allowed_modes = array( 1294 'home', 1295 'product', 1296 'category' 1297 ); 1298 $default_mode = 'home'; 1299 1300 if( empty( $params['mode'] ) || ! in_array( $params['mode'], $allowed_modes ) ) { 1301 $mode = $default_mode; 1302 } else { 1303 $mode = $params['mode']; 1304 } 1305 1306 if( empty( $params['id'] ) || $mode === $default_mode ) { 1307 $id = false; 1308 } else { 1309 $id = intval($params['id']); 1310 } 1311 1312 $url = $this->static_pages_api_url . '/' . $mode . '-page/' . $this->store_id; 1313 1314 if( ! empty( $id ) ) { 1315 $url .= '/' . $id; 1316 } 1317 1318 $url .= '/static-code'; 1319 1320 return $url; 1321 } 1322 1323 public function get_static_page( $endpoint_params, $query_params ) { 1324 1325 $url = $this->build_static_pages_request_url( $endpoint_params ); 1326 1327 $options = array( 1328 'timeout' => 3 1329 ); 1330 1331 $url = $this->build_request_url( 1332 $url, 1333 $query_params 1334 ); 1335 1336 $result = EcwidPlatform::fetch_url( $url, $options ); 1337 1338 if ( $result['code'] != '200' ) { 1339 return false; 1340 } 1341 1342 $data = json_decode( $result['data'] ); 1343 1344 return $data; 1345 } 1346 1347 public function get_storefront_widget_page( $params ) { 1348 1349 if ( empty( $params['slug'] ) && empty( $params['storeRootPage'] ) ) { 1350 return false; 1351 } 1352 1353 $options = $this->build_request_headers(); 1354 1355 $options['timeout'] = 3; 1356 1357 $url = $this->build_request_url( 1358 $this->storefront_widget_pages_api_url, 1359 $params 1360 ); 1361 1362 $result = EcwidPlatform::fetch_url( $url, $options ); 1363 1364 if ( $result['code'] != '200' ) { 1365 return false; 1366 } 1367 1368 $data = json_decode( $result['data'] ); 1369 1370 return $data; 1371 } 1286 1372 } -
ecwid-shopping-cart/trunk/lib/ecwid_platform.php
r3202954 r3239265 10 10 protected static $ecwid_plugin_data = null; 11 11 12 const FORCES_ CATALOG_CACHE_RESET_VALID_FROM = 'forced_catalog_cache_reset_valid_from';12 const FORCES_PAGES_CACHE_RESET_VALID_FROM = 'forced_pages_cache_reset_valid_from'; 13 13 const CATEGORIES_CACHE_VALID_FROM = 'categories_cache_valid_from'; 14 14 const PRODUCTS_CACHE_VALID_FROM = 'products_cache_valid_from'; 15 15 const PROFILE_CACHE_VALID_FROM = 'profile_cache_valid_from'; 16 const CATALOG_CACHE_VALID_FROM = 'catalog_valid_from';16 const PAGES_CACHE_VALID_FROM = 'pages_valid_from'; 17 17 18 18 const OPTION_LOG_CACHE = 'ecwid_log_cache'; … … 409 409 410 410 public static function save_in_static_pages_cache( $url, $data ) { 411 self::save_in_cache( $url, ' catalog', $data, WEEK_IN_SECONDS );411 self::save_in_cache( $url, 'pages', $data, WEEK_IN_SECONDS ); 412 412 } 413 413 … … 476 476 477 477 public static function get_from_static_pages_cache( $key ) { 478 $cache_name = self::_build_cache_name( $key, ' catalog' );478 $cache_name = self::_build_cache_name( $key, 'pages' ); 479 479 480 480 $result = self::cache_get( $cache_name ); … … 484 484 self::get( self::PRODUCTS_CACHE_VALID_FROM ), 485 485 self::get( self::PROFILE_CACHE_VALID_FROM ), 486 self::get( self::FORCES_ CATALOG_CACHE_RESET_VALID_FROM )486 self::get( self::FORCES_PAGES_CACHE_RESET_VALID_FROM ) 487 487 ); 488 488 … … 496 496 ); 497 497 498 if ( $result && isset( $result['data']->lastUpdated ) && $result['data']->lastUpdated > $valid_from ) { 499 return $result['data']; 498 if( $result ) { 499 if( isset( $result['data']->staticContent ) ) { 500 $data = $result['data']->staticContent; 501 } else { 502 $data = $result['data']; 503 } 504 } 505 506 if ( $result && isset( $data->lastUpdated ) && $data->lastUpdated > $valid_from ) { 507 return $data; 500 508 } else { 501 self::cache_reset( $cache_name );502 503 $page_id = get_the_ID();504 if ( ! empty( $page_id ) ) {505 do_action( 'ecwid_clean_external_cache_for_page', $page_id );506 }507 }509 self::cache_reset( $cache_name ); 510 511 $page_id = get_the_ID(); 512 if ( ! empty( $page_id ) ) { 513 do_action( 'ecwid_clean_external_cache_for_page', $page_id ); 514 } 515 } 508 516 509 517 return false; … … 565 573 566 574 public static function invalidate_static_pages_cache_from( $time = null ) { 567 self::_invalidate_cache_from( self:: CATALOG_CACHE_VALID_FROM, $time );575 self::_invalidate_cache_from( self::PAGES_CACHE_VALID_FROM, $time ); 568 576 } 569 577 570 578 public static function force_static_pages_cache_reset( $time = null ) { 571 579 $time = is_null( $time ) ? time() : $time; 572 self::set( self::FORCES_ CATALOG_CACHE_RESET_VALID_FROM, $time );580 self::set( self::FORCES_PAGES_CACHE_RESET_VALID_FROM, $time ); 573 581 } 574 582 -
ecwid-shopping-cart/trunk/readme.txt
r3231865 r3239265 6 6 Requires at least: 4.4 7 7 Tested up to: 6.7 8 Stable tag: 6.12.2 68 Stable tag: 6.12.27 9 9 10 10 Powerful, easy to use ecommerce shopping cart for WordPress. Sell on Facebook and Instagram. iPhone & Android apps. Superb support. Free plan available. … … 154 154 155 155 == Changelog == 156 = 6.12.27 - Feb 12, 2024 = 157 - Fixed an issue in the admin area where the product popup would not work on pages with a custom type. 158 - Internal improvements and optimizations. 159 156 160 = 6.12.26 - Jan 30, 2024 = 157 - Improved compatibility with the WPML plugin. Fixed an issue where translation loading for the `sitepress-multilingual-cs`domain was triggered too early on some ecommerce sites.161 - Improved compatibility with the WPML plugin. Fixed an issue where translation loading for the "sitepress-multilingual-cs" domain was triggered too early on some ecommerce sites. 158 162 - Fixed an issue where refreshing a product page would sometimes redirect users to the main storefront page. 159 163 - Internal improvements and optimizations.
Note: See TracChangeset
for help on using the changeset viewer.