[5.x]: Catalog Pricing Rules not linkable to entry/category?
What happened?
Description
In Commerce 4, sales (now called catalog pricing rules) could be linked to products related to a certain category. This was super easy for shop editors. They could relate certain products to a "super mega sale" category, or select certain brands (every product had a brand category relationship) to give a discount on just these brands. For Commerce 5, this doesn't seem to be the case anymore.
When I select Store Management > Pricing Rules > Match Purchasable > Related to > Category and select a category, the promotion is not applied to the products related to that category. Does Commerce just look at direct variant relationships instead of product relationships? More so: I entrified all categories, but if I do Store Management > Pricing Rules > Match Purchasable > Related to > Entry I can only select one entry at a time (instead of selecting multiple). I now have to add every related entry as a new condition.
Expected behavior
Show promotional price for all products related to a certain category or entry.
Actual behavior
Promotional price doesn't get shown when adding conditionals. It looks like conditions don't work.
What I need
Be able to select a category/product that relates to products. Show the promotional price on products related to the category/entry, like it was in Commerce 4. Be able to select multiple entries when relating to an entry.
This works
This does not work
Craft CMS version
Craft Pro 5.2.0
Craft Commerce version
5.0.10.1
PHP version
8.3.3
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
Hi @bartrylant
Thank you for your message and feedback.
We are currently working on extra features that will solve this in the upcoming Commerce 5.1 release.
If you are in need of this functionality right now you do have an option, although I understand the solution below is not absolutely ideal.
If you add your relationship field to both the product layout and the variant layout. You can then in the Product::EVENT_AFTER_SAVE get all the variants for that product and update their relationship field with the same data and save them with Craft::$app->getElements()->saveElement($variant, false). This will save the same data and also trigger the update of catalog pricing.
This way you the relationship will also live on the variant and you can use the "Related to" rule as you mentioned about.
Again, I realise this isn't the smoothest way but is a solution for now why the functionality is being worked on.
I will keep this issue open and reference it when progress is being made with the 5.1 feature.
Thanks!
Hi @nfourtythree, Is there any ETA about when 5.1 would be released?
@WHITE-developer no exact time sorry but in the next few weeks.
@lukeholder sorry for asking again, do you have a time frame for 5.1 now? 2 weeks, 8 weeks, 12 weeks? :-) Or is this something hat is already present in the 5.1 branch?
Hi all
We have just pushed Commerce 5.1.0-beta.1 which includes updates to catalog pricing rules. We have added specific "Match Product" and "Match Variant" conditions that will allow you to target those elements.
In the use case in this issue you can use the "Related To" rule in the product condition.
Thanks!
Hi All
Commerce 5.1.0 has now been released with updates relating to this issue.
Catalog pricing rules now have Product and Variant conditions to give greater flexibility in which purchasables should be targeted.
Along with that, Craft 5.4 has added the "Not related to" element query parameter and condition rule. This could also be another tool to use when creating conditions on the pricing rules.
Hope this helps, thanks!
Hi. Sorry, I just tested but it does not work as intended. In my example, only the products that are related to the brand "Flaneur" should get 10% off. However, every product is 10%, also the ones not related to the "Flaneur" category. This is the case when I just use "related to", but also when I use the Brand field.
Apply catalog price only on products related to Flaneur
Catalog price is applied to every product
This is the case for every condition I apply to the product. Looks like those conditions get completely ignored.
HI @bartrylant
Apologies there was a slight typo/bug. We have just pushed up a fix for this and cut the 5.1.0.1 release of Commerce.
Running composer update should get you up to speed. Then you can either run craft commerce/pricing-catalog/generate in the command line or resave your Pricing Rule to regenerate the prices.
Please let us know if you continue to see issues.
Thanks!
Great! I can confirm this works now. Thank you for ficing this!