-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure coupon brand restrictions are uploaded to Google Merchant Center. #2697
base: develop
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #2697 +/- ##
===========================================
+ Coverage 65.1% 65.8% +0.8%
- Complexity 4658 4665 +7
===========================================
Files 812 477 -335
Lines 24578 19456 -5122
Branches 1254 0 -1254
===========================================
- Hits 15990 12807 -3183
+ Misses 8416 6649 -1767
+ Partials 172 0 -172
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Thanks for the good catch @eason9487. I've updated the PR and it's ready for another round. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work. Tested that the brand restrictions of coupons can be converted to product IDs and then synced to Google Merchant Center.
However, just noticed there may be another concern. If a product is later created/updated to attach or detach a brand having associations with coupon restrictions, the brand restrictions (converted to associated product IDs) of those coupons won't be synced.
@@ -258,6 +259,61 @@ public function test_product_type_restrictions() { | |||
$this->assertEquals( [ 'Alpha Category > Beta Category' ], $adapted_coupon->getProductTypeExclusion() ); | |||
} | |||
|
|||
public function test_brand_restrictions() { | |||
if ( version_compare( WC_VERSION, '9.4', '<' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest adding a compatibility code comment to make it easier to search for compatibility codes in the future.
// compatibility-code "WC < 9.4" -- additional inline description
Changes proposed in this Pull Request:
Closes #2693.
Since WooCommerce 9.4, WooCommerce Brands is now part of the WooCommerce core, the merchant can add brand restrictions when editing coupons, but G4W plugin does not upload the corresponding coupon brand restrictions to Google Merchant Center.
This PR adds coupon restrictions for brands when generating the coupon (promotions) payload for updating to Google Merchant Center.
Note that
WC_Coupon
class does not have a method to get the brand restrictions like other restrictions do. This PR uses get_post_meta() to get the brands from a coupon, then uses get_objects_in_term() to get a list of product IDs from that brand.Refer to the following tables to better understand the data:
wp_postmeta
get_post_meta()
product_brands
andexclude_product_brands
wp_terms
wp_term_taxonomy
product_brand
)wp_term_relationships
get_objects_in_term()
product_brand
inget_objects_in_term()
Updated 28th Nov
For querying brands from a coupon from post_meta, I found in class-wc-brands-brand-settings-manager.php I can use it like:
However, since we do not expect all merchants update to latest WooCommerce, we also need to ensure backward compatibility for those who still use WC Brands plugin. The code above was available since WC Brands plugin version 1.6.65, so I lean towards to still querying post_meta manually as it's safest for all version and in core.
Screenshots:
Detailed test instructions:
wc_feature_woocommerce_brands_enabled
andwoocommerce_remote_variant_assignment
wp option update wc_feature_woocommerce_brands_enabled 'yes' wp option update woocommerce_remote_variant_assignment 2
Products > Brands
, e.g.Screen.Recording.2024-11-27.at.15.07.31.mov
WooCommerce > Status > Scheduled Actions
, search for the jobgla/jobs/update_coupon/process_item
, run it manually if it is still pending to save timeScreen.Recording.2024-11-27.at.15.24.52.mov
Additional details:
Changelog entry