#How do i create a discount on 3rd item in the cart?

3 messages · Page 1 of 1 (latest)

orchid path
#

I need to implement a discount when there are 3 items in the cart, the 3rd item is 50% off. How can I go about implementing such a discount? Can anyone help?

So far Ive tried using the updateCart function on the frontend when addItem function is triggered, but the data passed in for updateCart, takes in a data type of class StorePostCartsCartReq which does not include total or subtotal. Even the Cart table in the postgresql database doesn't have a total or subtotal field in any of the tables. I think the price is calculated by using the line_item table which has both unit_price and quantity. This is probably why Im facing such difficulty in trying to apply discount on a specific item in the cart, as Medusa only allows discount to be applied on all items in the cart. Which has been confirmed by @dim gale when I asked it.
https://discord.com/channels/876835651130097704/1225937626675150959
But I think the discount on the 3rd item in the cart can be implemented if I use a custom-service. But can anyone help me figure out how I might go about doing that?

orchid path
#

Can someone help me with this please

hexed breach
#

You may try something like this:

  1. create subscriber for cart.updated event
  2. create a discount which will be applicable for products which specific tag
  3. when the 3rd item is added, set a tag to this item and use store api to update the cart with discount code