Plugin Directory

Changeset 3239265


Ignore:
Timestamp:
02/12/2025 10:14:39 AM (14 months ago)
Author:
Ecwid
Message:

Update to version 6.12.27 from GitHub

Location:
ecwid-shopping-cart
Files:
14 edited
1 copied

Legend:

Unmodified
Added
Removed
  • ecwid-shopping-cart/tags/6.12.27/ecwid-shopping-cart.php

    r3231865 r3239265  
    66Text Domain: ecwid-shopping-cart
    77Author: Ecwid Ecommerce
    8 Version: 6.12.26
     8Version: 6.12.27
    99Author URI: https://ecwid.to/ecwid-site
    1010License: GPLv2 or later
     
    16971697        ),
    16981698
     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
    16991707        Ec_Store_Defer_Init::OPTION_NAME => array(
    17001708            'values' => array(
  • ecwid-shopping-cart/tags/6.12.27/includes/class-ecwid-product-popup.php

    r3223401 r3239265  
    3636        }
    3737
    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 ) ) {
    3940            return;
    4041        }
  • ecwid-shopping-cart/tags/6.12.27/includes/class-ecwid-static-page.php

    r3231865 r3239265  
    33class Ecwid_Static_Page {
    44
    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';
    67
    78    const OPTION_VALUE_ENABLED  = 'Y';
     
    1920            add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
    2021        }
     22
     23        add_action( 'update_option_' . self::OPTION_NEW_IS_ENABLED, array( $this, 'clear_cache' ), 10, 3 );
    2124    }
    2225
     
    5457    }
    5558
    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        }
    6566
    6667        if ( ! isset( $params['mode'] ) ) {
     
    6869        }
    6970
    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;
    8172    }
    8273
     
    8980
    9081        $store_page_params = Ecwid_Store_Page::get_store_page_params();
    91         $endpoint_params   = false;
     82        $endpoint_params = false;
     83        $query_params = array();
    9284
    9385        // for cases of early access to the page if the cache is empty and need to get store block params
     
    9991        }
    10092
    101         $params = array();
    102 
    10393        if ( Ecwid_Seo_Links::is_enabled() || ecwid_is_demo_store() ) {
    104             $params['clean_urls'] = 'true';
     94            $query_params['clean_urls'] = 'true';
    10595        } 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();
    110100
    111101        if ( array_key_exists( 'offset', $_GET ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
    112             $params['offset'] = intval( $_GET['offset'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
     102            $query_params['offset'] = intval( $_GET['offset'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
    113103        }
    114104
    115105        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();
    120110
    121111        $storefront_view_params = array( 'show_root_categories', 'enable_catalog_on_one_page' );
     
    142132
    143133                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;
    146136                } else {
    147                     $params[ 'tplvar_ec.storefront.' . $name ] = $value;
     137                    $query_params[ 'tplvar_ec.storefront.' . $name ] = $value;
    148138                }
    149139            }
     
    154144        if ( ! empty( $hreflang_items ) ) {
    155145            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        }
    174171
    175172        $dynamic_css = '';
     
    178175        }
    179176
    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
    181181        if ( $cached_data ) {
     182            if ( isset( $cached_data->staticContent ) ) {
     183                $static_content = $cached_data->staticContent;
     184            } else {
     185                $static_content = $cached_data;
     186            }
     187
    182188            $is_css_defined     = ! empty( $dynamic_css );
    183             $is_css_already_set = in_array( $dynamic_css, $cached_data->cssFiles, true ); //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
     189            $is_css_already_set = in_array( $dynamic_css, $static_content->cssFiles, true ); //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
    184190            $is_home_page       = Ecwid_Store_Page::is_store_home_page();
    185191
    186192            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 );
    196208
    197209        return $fetched_data;
    198210    }
    199211
    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
    216237                return null;
    217238            }
    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 ) ) {
    219249            //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
    220257            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 ) ) {
    225262                $pattern = '/<img(.*?)>/is';
    226263
    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 );
    228265            }
    229266
    230267            EcwidPlatform::encode_fields_with_emoji(
    231                 $fetched_data,
     268                $static_content,
    232269                array( 'htmlCode', 'metaDescriptionHtml', 'ogTagsHtml', 'jsonLDHtml' )
    233270            );
    234271
    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 );
    237274            } else {
    238275                $last_update = time();
     
    240277            //phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
    241278
     279            if ( ! empty( $data->staticContent ) ) {
     280                $data->staticContent = $static_content;
     281            }
     282
     283            $cache_key = serialize($query_params);
     284
    242285            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;
    246289        }//end if
    247290
     
    409452        }
    410453
    411         if ( get_option( self::OPTION_IS_ENABLED ) === '' ) {
     454        if ( get_option( self::OPTION_IS_ENABLED, self::OPTION_VALUE_AUTO ) === self::OPTION_VALUE_AUTO ) {
    412455            return true;
    413456        }
     
    415458        return false;
    416459    }
     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    }
    417482}
    418483
  • ecwid-shopping-cart/tags/6.12.27/includes/shortcodes/class-ecwid-shortcode-productbrowser.php

    r3223401 r3239265  
    6363        $code .= '<div id="static-ec-store-container">';
    6464        $code .= htmlspecialchars_decode( Ecwid_Static_Page::get_html_code() );
     65        $code .= '</div>';
    6566
    6667        $js_code = Ecwid_Static_Page::get_js_code();
     
    6869            $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;
    6970        }
    70         $code .= '</div>';
    7171
    7272        $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  
    4141    protected static $profile = null;
    4242
    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;
    5052
    5153    public function __construct() {
    5254
    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();
    6267
    6368        add_option( self::OPTION_API_STATUS, self::API_STATUS_UNDEFINED );
     
    182187
    183188        $url = $this->build_request_url(
    184             $this->_categories_api_url,
     189            $this->categories_api_url,
    185190            $params
    186191        );
     
    260265
    261266        $url = $this->build_request_url(
    262             $this->_categories_api_url . '/' . $category_id,
     267            $this->categories_api_url . '/' . $category_id,
    263268            $params
    264269        );
     
    318323
    319324        $url = $this->build_request_url(
    320             $this->_products_api_url . '/' . $product_id,
     325            $this->products_api_url . '/' . $product_id,
    321326            $params
    322327        );
     
    370375
    371376        $url = $this->build_request_url(
    372             $this->_products_api_url,
     377            $this->products_api_url,
    373378            $params
    374379        );
     
    424429
    425430        $url = $this->build_request_url(
    426             $this->_products_api_url . '/deleted',
     431            $this->products_api_url . '/deleted',
    427432            $params
    428433        );
     
    462467
    463468        $url = $this->build_request_url(
    464             $this->_products_api_url,
     469            $this->products_api_url,
    465470            $params
    466471        );
     
    556561        );
    557562
    558         $url = $this->build_request_url( $this->_stores_api_url, $params );
     563        $url = $this->build_request_url( $this->stores_api_url, $params );
    559564
    560565        $request = Ecwid_Http::create_get(
     
    583588        }
    584589
    585         $url = $this->_api_url . $this->store_id . '/latest-stats';
     590        $url = $this->api_url . $this->store_id . '/latest-stats';
    586591
    587592        $params = array();
     
    635640
    636641        $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 );
    638643
    639644        if ( empty( $options ) ) {
     
    685690        $request_params = array();
    686691
    687         $url = $this->build_request_url( $this->_profile_api_url, $request_params );
     692        $url = $this->build_request_url( $this->profile_api_url, $request_params );
    688693
    689694        $result = $this->_do_put( $url, $params );
     
    830835            'returnApiToken' => 'true',
    831836        );
    832         $url            = $this->build_request_url( $this->_stores_api_url, $request_params );
     837        $url            = $this->build_request_url( $this->stores_api_url, $request_params );
    833838
    834839        $result = EcwidPlatform::http_post_request(
     
    891896    public function create_product( $params ) {
    892897        $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 );
    894899
    895900        $params = $this->_sanitize_product_data( $params );
     
    903908        $request_params = array();
    904909
    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 );
    906911
    907912        $result = $this->_do_post( $url, $params );
     
    913918        $request_params = array();
    914919
    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 );
    916921
    917922        $params = $this->_sanitize_product_data( $params );
     
    951956        $request_params = array();
    952957
    953         $url = $this->build_request_url( $this->_categories_api_url, $request_params );
     958        $url = $this->build_request_url( $this->categories_api_url, $request_params );
    954959
    955960        $params = $this->_sanitize_category_data( $params );
     
    964969        $request_params = array();
    965970
    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 );
    967972
    968973        $params = $this->_sanitize_category_data( $params );
     
    9951000                    'Authorization' => 'Bearer ' . self::get_token(),
    9961001                ),
    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 ),
    9981003            );
    9991004        }
     
    10061011    public function upload_category_image( $params ) {
    10071012        $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 );
    10091014
    10101015        $result = $this->_do_post( $url, $params['data'], true );
     
    10151020    public function upload_product_image( $params ) {
    10161021        $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 );
    10181023
    10191024        $result = $this->_do_post( $url, $params['data'], true );
     
    10241029    public function upload_product_gallery_image( $params ) {
    10251030        $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 );
    10271032
    10281033        $result = $this->_do_post( $url, $params['data'], true );
     
    10341039    public function upload_product_variation_image( $params ) {
    10351040        $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 );
    10371042
    10381043        $result = $this->_do_post( $url, $params['data'], true );
     
    10451050
    10461051        $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 );
    10481053
    10491054        if ( empty( $options ) ) {
     
    11501155            'stopOnFirstFailure' => 'false',
    11511156        );
    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 );
    11531158
    11541159        $result = $this->_do_post( $url, $params );
     
    11631168
    11641169        $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 );
    11661171
    11671172        if ( empty( $options ) ) {
     
    12841289        );
    12851290    }
     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    }
    12861372}
  • ecwid-shopping-cart/tags/6.12.27/lib/ecwid_platform.php

    r3202954 r3239265  
    1010    protected static $ecwid_plugin_data = null;
    1111
    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';
    1313    const CATEGORIES_CACHE_VALID_FROM           = 'categories_cache_valid_from';
    1414    const PRODUCTS_CACHE_VALID_FROM             = 'products_cache_valid_from';
    1515    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';
    1717
    1818    const OPTION_LOG_CACHE         = 'ecwid_log_cache';
     
    409409
    410410    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 );
    412412    }
    413413
     
    476476
    477477    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' );
    479479
    480480        $result = self::cache_get( $cache_name );
     
    484484            self::get( self::PRODUCTS_CACHE_VALID_FROM ),
    485485            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 )
    487487        );
    488488
     
    496496        );
    497497
    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;
    500508        } 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        }
    508516
    509517        return false;
     
    565573
    566574    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 );
    568576    }
    569577
    570578    public static function force_static_pages_cache_reset( $time = null ) {
    571579        $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 );
    573581    }
    574582
  • ecwid-shopping-cart/tags/6.12.27/readme.txt

    r3231865 r3239265  
    66Requires at least: 4.4
    77Tested up to: 6.7
    8 Stable tag: 6.12.26
     8Stable tag: 6.12.27
    99
    1010Powerful, easy to use ecommerce shopping cart for WordPress. Sell on Facebook and Instagram. iPhone & Android apps. Superb support. Free plan available.
     
    154154
    155155== 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
    156160= 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.
    158162- Fixed an issue where refreshing a product page would sometimes redirect users to the main storefront page.
    159163- Internal improvements and optimizations.
  • ecwid-shopping-cart/trunk/ecwid-shopping-cart.php

    r3231865 r3239265  
    66Text Domain: ecwid-shopping-cart
    77Author: Ecwid Ecommerce
    8 Version: 6.12.26
     8Version: 6.12.27
    99Author URI: https://ecwid.to/ecwid-site
    1010License: GPLv2 or later
     
    16971697        ),
    16981698
     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
    16991707        Ec_Store_Defer_Init::OPTION_NAME => array(
    17001708            'values' => array(
  • ecwid-shopping-cart/trunk/includes/class-ecwid-product-popup.php

    r3223401 r3239265  
    3636        }
    3737
    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 ) ) {
    3940            return;
    4041        }
  • ecwid-shopping-cart/trunk/includes/class-ecwid-static-page.php

    r3231865 r3239265  
    33class Ecwid_Static_Page {
    44
    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';
    67
    78    const OPTION_VALUE_ENABLED  = 'Y';
     
    1920            add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
    2021        }
     22
     23        add_action( 'update_option_' . self::OPTION_NEW_IS_ENABLED, array( $this, 'clear_cache' ), 10, 3 );
    2124    }
    2225
     
    5457    }
    5558
    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        }
    6566
    6667        if ( ! isset( $params['mode'] ) ) {
     
    6869        }
    6970
    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;
    8172    }
    8273
     
    8980
    9081        $store_page_params = Ecwid_Store_Page::get_store_page_params();
    91         $endpoint_params   = false;
     82        $endpoint_params = false;
     83        $query_params = array();
    9284
    9385        // for cases of early access to the page if the cache is empty and need to get store block params
     
    9991        }
    10092
    101         $params = array();
    102 
    10393        if ( Ecwid_Seo_Links::is_enabled() || ecwid_is_demo_store() ) {
    104             $params['clean_urls'] = 'true';
     94            $query_params['clean_urls'] = 'true';
    10595        } 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();
    110100
    111101        if ( array_key_exists( 'offset', $_GET ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
    112             $params['offset'] = intval( $_GET['offset'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
     102            $query_params['offset'] = intval( $_GET['offset'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
    113103        }
    114104
    115105        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();
    120110
    121111        $storefront_view_params = array( 'show_root_categories', 'enable_catalog_on_one_page' );
     
    142132
    143133                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;
    146136                } else {
    147                     $params[ 'tplvar_ec.storefront.' . $name ] = $value;
     137                    $query_params[ 'tplvar_ec.storefront.' . $name ] = $value;
    148138                }
    149139            }
     
    154144        if ( ! empty( $hreflang_items ) ) {
    155145            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        }
    174171
    175172        $dynamic_css = '';
     
    178175        }
    179176
    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
    181181        if ( $cached_data ) {
     182            if ( isset( $cached_data->staticContent ) ) {
     183                $static_content = $cached_data->staticContent;
     184            } else {
     185                $static_content = $cached_data;
     186            }
     187
    182188            $is_css_defined     = ! empty( $dynamic_css );
    183             $is_css_already_set = in_array( $dynamic_css, $cached_data->cssFiles, true ); //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
     189            $is_css_already_set = in_array( $dynamic_css, $static_content->cssFiles, true ); //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
    184190            $is_home_page       = Ecwid_Store_Page::is_store_home_page();
    185191
    186192            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 );
    196208
    197209        return $fetched_data;
    198210    }
    199211
    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
    216237                return null;
    217238            }
    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 ) ) {
    219249            //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
    220257            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 ) ) {
    225262                $pattern = '/<img(.*?)>/is';
    226263
    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 );
    228265            }
    229266
    230267            EcwidPlatform::encode_fields_with_emoji(
    231                 $fetched_data,
     268                $static_content,
    232269                array( 'htmlCode', 'metaDescriptionHtml', 'ogTagsHtml', 'jsonLDHtml' )
    233270            );
    234271
    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 );
    237274            } else {
    238275                $last_update = time();
     
    240277            //phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
    241278
     279            if ( ! empty( $data->staticContent ) ) {
     280                $data->staticContent = $static_content;
     281            }
     282
     283            $cache_key = serialize($query_params);
     284
    242285            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;
    246289        }//end if
    247290
     
    409452        }
    410453
    411         if ( get_option( self::OPTION_IS_ENABLED ) === '' ) {
     454        if ( get_option( self::OPTION_IS_ENABLED, self::OPTION_VALUE_AUTO ) === self::OPTION_VALUE_AUTO ) {
    412455            return true;
    413456        }
     
    415458        return false;
    416459    }
     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    }
    417482}
    418483
  • ecwid-shopping-cart/trunk/includes/shortcodes/class-ecwid-shortcode-productbrowser.php

    r3223401 r3239265  
    6363        $code .= '<div id="static-ec-store-container">';
    6464        $code .= htmlspecialchars_decode( Ecwid_Static_Page::get_html_code() );
     65        $code .= '</div>';
    6566
    6667        $js_code = Ecwid_Static_Page::get_js_code();
     
    6869            $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;
    6970        }
    70         $code .= '</div>';
    7171
    7272        $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  
    4141    protected static $profile = null;
    4242
    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;
    5052
    5153    public function __construct() {
    5254
    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();
    6267
    6368        add_option( self::OPTION_API_STATUS, self::API_STATUS_UNDEFINED );
     
    182187
    183188        $url = $this->build_request_url(
    184             $this->_categories_api_url,
     189            $this->categories_api_url,
    185190            $params
    186191        );
     
    260265
    261266        $url = $this->build_request_url(
    262             $this->_categories_api_url . '/' . $category_id,
     267            $this->categories_api_url . '/' . $category_id,
    263268            $params
    264269        );
     
    318323
    319324        $url = $this->build_request_url(
    320             $this->_products_api_url . '/' . $product_id,
     325            $this->products_api_url . '/' . $product_id,
    321326            $params
    322327        );
     
    370375
    371376        $url = $this->build_request_url(
    372             $this->_products_api_url,
     377            $this->products_api_url,
    373378            $params
    374379        );
     
    424429
    425430        $url = $this->build_request_url(
    426             $this->_products_api_url . '/deleted',
     431            $this->products_api_url . '/deleted',
    427432            $params
    428433        );
     
    462467
    463468        $url = $this->build_request_url(
    464             $this->_products_api_url,
     469            $this->products_api_url,
    465470            $params
    466471        );
     
    556561        );
    557562
    558         $url = $this->build_request_url( $this->_stores_api_url, $params );
     563        $url = $this->build_request_url( $this->stores_api_url, $params );
    559564
    560565        $request = Ecwid_Http::create_get(
     
    583588        }
    584589
    585         $url = $this->_api_url . $this->store_id . '/latest-stats';
     590        $url = $this->api_url . $this->store_id . '/latest-stats';
    586591
    587592        $params = array();
     
    635640
    636641        $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 );
    638643
    639644        if ( empty( $options ) ) {
     
    685690        $request_params = array();
    686691
    687         $url = $this->build_request_url( $this->_profile_api_url, $request_params );
     692        $url = $this->build_request_url( $this->profile_api_url, $request_params );
    688693
    689694        $result = $this->_do_put( $url, $params );
     
    830835            'returnApiToken' => 'true',
    831836        );
    832         $url            = $this->build_request_url( $this->_stores_api_url, $request_params );
     837        $url            = $this->build_request_url( $this->stores_api_url, $request_params );
    833838
    834839        $result = EcwidPlatform::http_post_request(
     
    891896    public function create_product( $params ) {
    892897        $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 );
    894899
    895900        $params = $this->_sanitize_product_data( $params );
     
    903908        $request_params = array();
    904909
    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 );
    906911
    907912        $result = $this->_do_post( $url, $params );
     
    913918        $request_params = array();
    914919
    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 );
    916921
    917922        $params = $this->_sanitize_product_data( $params );
     
    951956        $request_params = array();
    952957
    953         $url = $this->build_request_url( $this->_categories_api_url, $request_params );
     958        $url = $this->build_request_url( $this->categories_api_url, $request_params );
    954959
    955960        $params = $this->_sanitize_category_data( $params );
     
    964969        $request_params = array();
    965970
    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 );
    967972
    968973        $params = $this->_sanitize_category_data( $params );
     
    9951000                    'Authorization' => 'Bearer ' . self::get_token(),
    9961001                ),
    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 ),
    9981003            );
    9991004        }
     
    10061011    public function upload_category_image( $params ) {
    10071012        $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 );
    10091014
    10101015        $result = $this->_do_post( $url, $params['data'], true );
     
    10151020    public function upload_product_image( $params ) {
    10161021        $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 );
    10181023
    10191024        $result = $this->_do_post( $url, $params['data'], true );
     
    10241029    public function upload_product_gallery_image( $params ) {
    10251030        $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 );
    10271032
    10281033        $result = $this->_do_post( $url, $params['data'], true );
     
    10341039    public function upload_product_variation_image( $params ) {
    10351040        $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 );
    10371042
    10381043        $result = $this->_do_post( $url, $params['data'], true );
     
    10451050
    10461051        $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 );
    10481053
    10491054        if ( empty( $options ) ) {
     
    11501155            'stopOnFirstFailure' => 'false',
    11511156        );
    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 );
    11531158
    11541159        $result = $this->_do_post( $url, $params );
     
    11631168
    11641169        $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 );
    11661171
    11671172        if ( empty( $options ) ) {
     
    12841289        );
    12851290    }
     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    }
    12861372}
  • ecwid-shopping-cart/trunk/lib/ecwid_platform.php

    r3202954 r3239265  
    1010    protected static $ecwid_plugin_data = null;
    1111
    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';
    1313    const CATEGORIES_CACHE_VALID_FROM           = 'categories_cache_valid_from';
    1414    const PRODUCTS_CACHE_VALID_FROM             = 'products_cache_valid_from';
    1515    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';
    1717
    1818    const OPTION_LOG_CACHE         = 'ecwid_log_cache';
     
    409409
    410410    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 );
    412412    }
    413413
     
    476476
    477477    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' );
    479479
    480480        $result = self::cache_get( $cache_name );
     
    484484            self::get( self::PRODUCTS_CACHE_VALID_FROM ),
    485485            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 )
    487487        );
    488488
     
    496496        );
    497497
    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;
    500508        } 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        }
    508516
    509517        return false;
     
    565573
    566574    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 );
    568576    }
    569577
    570578    public static function force_static_pages_cache_reset( $time = null ) {
    571579        $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 );
    573581    }
    574582
  • ecwid-shopping-cart/trunk/readme.txt

    r3231865 r3239265  
    66Requires at least: 4.4
    77Tested up to: 6.7
    8 Stable tag: 6.12.26
     8Stable tag: 6.12.27
    99
    1010Powerful, easy to use ecommerce shopping cart for WordPress. Sell on Facebook and Instagram. iPhone & Android apps. Superb support. Free plan available.
     
    154154
    155155== 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
    156160= 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.
    158162- Fixed an issue where refreshing a product page would sometimes redirect users to the main storefront page.
    159163- Internal improvements and optimizations.
Note: See TracChangeset for help on using the changeset viewer.