We have a client who is asking for "membership" pr...
# support
d
We have a client who is asking for "membership" pricing. E.g. A product is $450 normally but if you have already purchased a membership, lets say, $20/mo, then your price is $400 for the same product. This feels like a somewhat normal feature but I haven't figured out how to implement.
a
I’ve never done this, and I don’t know Solidus well, but I think maybe promotion rules could be what you’re after.
d
That makes sense and since we're just in the early phase of looking into this I haven't dug too much into promotions. Is there a way to automatically apply the promotion? Could this be done at the shopping phase?
a
Yep:
The
Spree::Promotion
model defines essential information about a promotion… `apply_automatically`: If
true
, the promotion is activated and applied automatically once all of the eligibility checks have passed.
d
awesome, thanks!
c
I've done this before with extending the
PricingOptions
class - https://github.com/solidusio/solidus/blob/main/core/app/models/spree/variant/pricing_options.rb and adding your custom logic to the
price_for_options
method on the price selector - https://github.com/solidusio/solidus/blob/main/core/app/models/spree/variant/price_selector.rb#L28-L34 Essentially the data model for
Spree::Price
had to be extended to add another field for category or type that would track which is the "member" price, and you would create a separate
Spree::Price
for each variant that has that. Then you would have some logic that would build the
price_options
passed to
price_for_options
depending on the user member status. This can be tricky to do if you want this pricing to be displayed on PDP etc, as well, so generally we showed both the member and non-member price and if the user is logged in they would get the member price when they add to cart. If a user adds it before they log in you may have to have some custom logic to update the
LineItem#price
because that generally doesn't get updated.
Using promotions for this has some limitations, like the pricing on PDP for example generally doesn't take into account the current order or user state, so customer won't see the member pricing until they add an item to their cart, and also you won't be able to display it without also having stored that or somehow running it through the promotion action to calculate.
Also, in my experience member pricing doesn't follow a standard formula (20% off) so your promotion action may get pretty complicated if you want round pricing for all your items and you don't have a flat % or amount that you are discounting them by for members.
j
Chris's approach is the recommended one. I strongly advise against trying to use the promotion system to do this. The pricing system is meant to be extended for use cases like this, so that's the approach you should use.
d
That makes a lot of sense. Thank you! We still need to figure out what sort of rules/lack of rules we'll need and another challenge is that the store delivered via API in react native. But I think this gives me the direction I need. Thanks!
👍🏼 1
t
The pricing options way is the way to go, IF you do not need to call out the benefit / reduction for ie. bookkeeping or promotional reasons. Then the promotion system can help, because it creates adjustments. Just be aware that the promotion system creates the price adjustment AFTER the customer put something into the cart . If you need to reduce the price on the PDP your best bet is the pricing options.
🙌 1
💯 1
k
👋 here you can find an example of a similar customiziation: https://github.com/solidusio/solidus/issues/5896
🙌 1
👀 1