Skip to content

Commit

Permalink
PLUGINS-6711
Browse files Browse the repository at this point in the history
  • Loading branch information
meteor-ec committed Nov 21, 2023
1 parent 62637c5 commit f34a428
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 8 additions & 3 deletions lib/ecwid_api_v3.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,13 @@ public function get_store_profile( $disable_cache = false ) {
$result = EcwidPlatform::fetch_url( $url, $options );

if ( @$result['code'] == '403' ) {
self::set_api_status( self::API_STATUS_ERROR_TOKEN );
self::save_token( '' );
if ( get_option( EcwidPlatform::OPTION_ECWID_CHECK_API_RETRY_AFTER, 0 ) == 0 ) {
self::set_api_status( self::API_STATUS_ERROR_TOKEN );
self::save_token( '' );
} else {
update_option( EcwidPlatform::OPTION_ECWID_CHECK_API_RETRY_AFTER, time() + 5 * MINUTE_IN_SECONDS );
}

return false;
}

Expand All @@ -596,7 +601,7 @@ public function get_store_profile( $disable_cache = false ) {

$profile = json_decode( $result['data'] );

EcwidPlatform::cache_set( self::PROFILE_CACHE_NAME, $profile, 60 * 5 );
EcwidPlatform::cache_set( self::PROFILE_CACHE_NAME, $profile, 10 * MINUTE_IN_SECONDS );

if ( $profile && isset( $profile->settings ) && isset( $profile->settings->hideOutOfStockProductsInStorefront ) ) {
EcwidPlatform::set( 'hide_out_of_stock', $profile->settings->hideOutOfStockProductsInStorefront );
Expand Down
10 changes: 8 additions & 2 deletions lib/ecwid_platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class EcwidPlatform {
const OPTION_LOG_CACHE = 'ecwid_log_cache';
const OPTION_ECWID_PLUGIN_DATA = 'ecwid_plugin_data';

const OPTION_ECWID_CHECK_API_RETRY_AFTER = 'ecwid_api_check_retry_after';

const TRANSIENTS_LIMIT = 500;

public static function get_store_id() {
Expand Down Expand Up @@ -245,7 +247,7 @@ public static function report_error( $error ) {
}

public static function fetch_url( $url, $options = array() ) {
$api_check_retry_after = get_option( 'ecwid_api_check_retry_after', 0 );
$api_check_retry_after = get_option( self::OPTION_ECWID_CHECK_API_RETRY_AFTER, 0 );

if ( $api_check_retry_after > time() ) {
return array(
Expand Down Expand Up @@ -275,7 +277,7 @@ public static function fetch_url( $url, $options = array() ) {
$retry_after = intval( wp_remote_retrieve_header( $result, 'retry-after' ) );

if ( $retry_after > 0 ) {
update_option( 'ecwid_api_check_retry_after', time() + $retry_after );
update_option( self::OPTION_ECWID_CHECK_API_RETRY_AFTER, time() + $retry_after );
}
}

Expand Down Expand Up @@ -308,6 +310,10 @@ public static function fetch_url( $url, $options = array() ) {
);
}

if ( $return['code'] == 200 ) {
update_option( self::OPTION_ECWID_CHECK_API_RETRY_AFTER, 0 );
}

return $return;
}

Expand Down

0 comments on commit f34a428

Please sign in to comment.