commerce icon indicating copy to clipboard operation
commerce copied to clipboard

[5.x]: Implementing category-based pricing rules at the product level

Open romainpoirier opened this issue 1 year ago • 3 comments

What happened?

Description

As indicated in the official Craft Commerce 5 documentation:

Commerce ships with two types of purchasables: variants and donations. Products are not purchasables.

Problem

In my project, I am importing customer categories via FeedMe. I then add these categories at the product level. This serves two purposes:

  1. The import of categories must be done at the product level because FeedMe requires it.
  2. Adding the categories at this level allows me to filter them in the Entries list.

Need

I need to implement Pricing Rules based on categories. For a given product, all variants should inherit the same Pricing Rules based on the category associated with the product.

Question

How can I add Pricing Rules at the product level so that all variants inherit these rules?

Steps to reproduce

  1. Import customer categories via FeedMe.
  2. Assign categories to a product.
  3. Attempt to set Pricing Rules at the product level for all variants to inherit.

Expected behavior

All variants of a product should inherit the same Pricing Rules based on the category associated with the product.

Actual behavior

Currently, it seems that Pricing Rules can only be applied at the variant level, not the product level, causing inconsistencies in applying rules based on product categories.

Craft CMS version

5.2.9

Craft Commerce version

5.0.14

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

romainpoirier avatar Jul 31 '24 13:07 romainpoirier

Hi @romainpoirier

We have just pushed Commerce 5.1.0-beta.1 which includes updates to catalog pricing rules. We have now added specific "Match Product" and "Match Variant" conditions that will allow you to target those elements.

In your case, you will be able to use the "Related To" rule in the product condition.

Thanks!

nfourtythree avatar Aug 15 '24 06:08 nfourtythree

Thank you! I will test this. Do you have any idea of the public release date for this version?

romainpoirier avatar Aug 16 '24 06:08 romainpoirier

Hi @romainpoirier

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!

nfourtythree avatar Sep 05 '24 06:09 nfourtythree

hi @nfourtythree

Thanks for the update, it's really helpful. I still have a small request and a problem.

Request For the Match Product and Match Variant conditions: Would it be possible to choose multiple items in the category type custom fields? Currently, we can only add one category and we can't add other rules with the same custom field.

Problem I need to add a customer condition based on a customer category. I've created a Related To Category rule, but it doesn't work as expected. Pricing rules are available for all customers, event if they don't have any categories. If I try with another rule like email for example, it works fine. Woud it be a solution to add custom fields in Customer conditions as you've made for Product and Variant?

Thanks!

thibaultjadoul avatar Sep 06 '24 08:09 thibaultjadoul

@thibaultjadoul ~sorry for missing this. Can you make a discussion with this feature request and an explainer like you have above. We can then track the request in an open discussion item. Thanks!~

See latest comment.

lukeholder avatar Feb 04 '25 03:02 lukeholder

Hi @thibaultjadoul

Thank you for your message.

If you update to the latest version of Craft and Commerce I believe you will now see that you are able to achieve what you have outlined.

In Commerce we have introduce "Match Product" and "Match Variant" conditions which specifically all matching of condition rules of those levels.

Along with that Craft updated element condition rules (relevant in your case for categories) that allows for the selection of multiple elements, previously it was just one.

Hope this helps, let me know if you need any further guidance, thanks!

nfourtythree avatar Feb 04 '25 13:02 nfourtythree