Discount conditions #1148
Replies: 2 comments 1 reply
-
What I would suggest is something alongs the line (from the discussion I had with @olivermrbl)
And then for the base discount class from which the entity extends would hold a method alongs the line (which is the solution I would prefer since it is more flexible)
Or to try something like this
I did not get the time to tests the second one, but Ive already used the first one for another project (using sequelize) where I had a table |
Beta Was this translation helpful? Give feedback.
-
I like the overall idea of this approach a lot since it's very easy to work with. Though as we've discussed in Discord, it works well for cases where referential integrity is not an absolute must (e.g. for registering changes as you mention in your comment). But in our case, we want to ensure that the So for now, we'll proceed with the "Join table per relation" approach. |
Beta Was this translation helpful? Give feedback.
-
Goal
Allow store managers to create discounts, that are only applicable for a specific product collection (e.g. to use in flash sales), customer group (e.g. offering a discount only to VIP Customers), product type, products, or product tags.
What we have right now
Represents a promotion that can be applied to a cart.
Rule that governs how a
Discount
is calculated when applied to a cart. TheDiscountRule
currently hasvalid_for
which holds all products to which the discount is applicable.What we want
We want to introduce the notion of a
DiscountRuleCondition
and killvalid_for
onDiscountRule
. TheDiscountRuleCondition
should hold the applicable products, product collections, product types, product tags, or customer groups mentioned in the Goal section. So it's essentially an extension ofvalid_for
, we are looking to add.Current approach
Our current entity
DiscountRule
would be updated to have a relation like so:This relation,
conditions
, determines for which products, product types, product tags, customer groups, and product collections the discount is applicable, as we've already mentioned a couple of times.The schema for
DiscountRuleCondition
is currently scoped to be:Though this is sub-optimal, since it would require us to add entities for each of the different types of conditions to have referential integrity like so:
This quickly becomes ugly, and if we continue with this pattern going forward, we would end up with a huge amount of entities in the db over time.
Optimal implementation
It would be optimal to have a somewhat dynamic condition type i.e modeling the
DicountRuleCondition
more generally like so:And again, add it as a relation to our existing
DiscountRule
like so:We might encounter some issues with foreign keys on the latter approach, since entries of
DiscountRuleConditionType
could point to missing resources. Hope that some of you might have some input to how and if we can go about it like this 💜Beta Was this translation helpful? Give feedback.
All reactions