Merge pull request #16767 from hjoelr/bugfix-coupon-cache

Bugfix: coupon object cache not being cleared upon deletion
This commit is contained in:
Claudiu Lodromanean 2017-09-17 09:45:45 -07:00 committed by GitHub
commit f9120672bd
2 changed files with 16 additions and 0 deletions

View File

@ -185,6 +185,9 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
if ( $args['force_delete'] ) {
wp_delete_post( $id );
wp_cache_delete( WC_Cache_Helper::get_cache_prefix( 'coupons' ) . 'coupon_id_from_code_' . $coupon->get_code(), 'coupons' );
$coupon->set_id( 0 );
do_action( 'woocommerce_delete_coupon', $id );
} else {

View File

@ -44,6 +44,19 @@ class WC_Tests_Coupon_Data_Store extends WC_Unit_Test_Case {
$this->assertEquals( 0, $coupon->get_id() );
}
/**
* Test coupon accurately cleans up object cache upon deletion.
*/
public function test_coupon_cache_deletion() {
$coupon = WC_Helper_Coupon::create_coupon( 'test' );
$coupon->delete( true );
$cache_name = WC_Cache_Helper::get_cache_prefix( 'coupons' ) . 'coupon_id_from_code_' . $coupon->get_code();
$ids = wp_cache_get( $cache_name, 'coupons' );
$this->assertEquals( false, $ids, sprintf( 'Object cache for %s was not removed upon deletion of coupon.', $cache_name ) );
}
/**
* Test coupon update.
* @since 3.0.0