Clear PUI and DCC product status on woocommerce_paypal_payments_clear_apm_product_status event

This commit is contained in:
Pedro Silva 2024-01-04 17:30:50 +00:00
parent 8e71665ec4
commit 5e6d7f97d2
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
3 changed files with 68 additions and 0 deletions

View file

@ -186,4 +186,30 @@ class DCCProductStatus {
return $this->has_request_failure;
}
/**
* Clears the persisted result to force a recheck.
*
* @param Settings|null $settings The settings object.
* We accept a Settings object to don't override other sequential settings that are being updated elsewhere.
* @return void
*/
public function clear( Settings $settings = null ): void {
if ( null === $settings ) {
$settings = $this->settings;
}
// Unset check stored in memory.
$this->current_status_cache = null;
// Unset settings flag.
$settings_key = 'products_dcc_enabled';
if ( $settings->has( $settings_key ) ) {
$settings->set( $settings_key, false );
$settings->persist();
}
// Delete cached value.
$this->cache->delete( self::DCC_STATUS_CACHE_KEY );
}
}

View file

@ -173,4 +173,30 @@ class PayUponInvoiceProductStatus {
return $this->has_request_failure;
}
/**
* Clears the persisted result to force a recheck.
*
* @param Settings|null $settings The settings object.
* We accept a Settings object to don't override other sequential settings that are being updated elsewhere.
* @return void
*/
public function clear( Settings $settings = null ): void {
if ( null === $settings ) {
$settings = $this->settings;
}
// Unset check stored in memory.
$this->current_status_cache = null;
// Unset settings flag.
$settings_key = 'products_pui_enabled';
if ( $settings->has( $settings_key ) ) {
$settings->set( $settings_key, false );
$settings->persist();
}
// Delete cached value.
$this->cache->delete( self::PUI_STATUS_CACHE_KEY );
}
}

View file

@ -430,6 +430,22 @@ class WCGatewayModule implements ModuleInterface {
$c->get( 'wcgateway.cli.settings.command' )
);
}
// Clears product status when appropriate.
add_action(
'woocommerce_paypal_payments_clear_apm_product_status',
function( Settings $settings = null ) use ( $c ): void {
$dcc_product_status = $c->get( 'wcgateway.helper.dcc-product-status' );
if ( $dcc_product_status instanceof DCCProductStatus ) {
$dcc_product_status->clear( $settings );
}
$pui_product_status = $c->get( 'wcgateway.pay-upon-invoice-product-status' );
if ( $pui_product_status instanceof PayUponInvoiceProductStatus ) {
$pui_product_status->clear( $settings );
}
}
);
}
/**