As brief explainer, the cache managers essentially listen for changes to specific objects (posts or crud objects) for changes to specific meta keys or properties. When a relevant change occurs, the cache manager's job is to trigger a hook to let the cache's know that the cache needs to be updated.
Prior to this PR the WCS_Related_Order_Store_Cached_CPT cache still used the old WCS_Post_Meta_Cache_Manager which meant changes to related order meta flags (eg subscription_renewal) on HPOS environments wouldn't be picked up by the WCS_Post_Meta_Cache_Manager, and so the subscription's related order cache wouldn't be updated.
This PR fixes that.
Note
This PR mostly impacts 3rd parties who set or change related order meta via update_meta() rather than use the related order APIs like WCS_Related_Order_Store::instance()->add_relation()
How to test this PR
Enable HPOS tables.
Run the following code snippets.
After running each snippet, observe the subscription related order in the UI and in the database to ensure the expected outcome is achieved.
Enable CPT tables.
Run the following code snippets.
After running each snippet, observe the subscription related order in the UI and in the database to ensure the expected outcome is achieved.
Code snippets for testing
New order
$order = new WC_Order();
$order->update_meta_data( '_subscription_renewal', 925 ); // <- Where 925 is a subscription ID.
$order->save();
Expectation: A newly created order is created. The subscription 925 has the new order in its renewal order related cache.
Change order
$order = wc_get_order( 123 ); // <- where 123 is the order you created in the last test (a renewal order).
$order->update_meta_data( '_subscription_renewal', 100 ); // <- Where 925 is a different subscription ID.
$order->save();
Expectation: The order (123) changes from being a renewal order for 925, to being a renewal order for 927. Subscription 925 shouldn't have the renewal order 123 in its cache, 927 should.
Delete relation
$order = wc_get_order( 123 ); // <- where 123 is the order you created in the last test (a renewal order).
$order->delete_meta_data( '_subscription_renewal' ); // <- Where 925 is a different subscription ID.
$order->save();
Expectation: The order (123) changes from being a renewal order for 925, to no longer being a renewal order at all.
Product impact
[x] Added changelog entry (or does not apply)
[ ] Will this PR affect WooCommerce Subscriptions? yes/no/tbc, add issue ref
[ ] Will this PR affect WooCommerce Payments? yes/no/tbc, add issue ref
[ ] Added deprecated functions, hooks or classes to the spreadsheet
Fixes #339
Description
In https://github.com/Automattic/woocommerce-subscriptions-core/pull/304 I introduced a new cache manager that works with CRUD objects rather than hooking onto post related hooks.
As brief explainer, the cache managers essentially listen for changes to specific objects (posts or crud objects) for changes to specific meta keys or properties. When a relevant change occurs, the cache manager's job is to trigger a hook to let the cache's know that the cache needs to be updated.
Prior to this PR the
WCS_Related_Order_Store_Cached_CPT
cache still used the oldWCS_Post_Meta_Cache_Manager
which meant changes to related order meta flags (egsubscription_renewal
) on HPOS environments wouldn't be picked up by theWCS_Post_Meta_Cache_Manager
, and so the subscription's related order cache wouldn't be updated.This PR fixes that.
How to test this PR
Code snippets for testing
New order
Expectation: A newly created order is created. The subscription 925 has the new order in its renewal order related cache.
Change order
Expectation: The order (123) changes from being a renewal order for 925, to being a renewal order for 927. Subscription 925 shouldn't have the renewal order 123 in its cache, 927 should.
Delete relation
Expectation: The order (123) changes from being a renewal order for 925, to no longer being a renewal order at all.
Product impact