laravelshoppingcart icon indicating copy to clipboard operation
laravelshoppingcart copied to clipboard

Apply cart condition once on cart item regardless of its quantity

Open HuyPham55 opened this issue 3 years ago • 5 comments

First I'm not sure if this is the right place for discussions/questions Second I want to apply an item condition (Per-Item Bases) only one only one time for a row, is this possible?

For example, I have a row with quantity = 3 and price = 200. However I want to apply an discount (-50) for only the first, the 2 following will have original price, so the subtotal of that row is 150+200+200 = 550.

I've read the document thoroughly and tried my luck with addItemCondition. But instead it applies to all items in that row so the subtoal ended up being 150*3 = 450.

How I am supposed to achieve this?

HuyPham55 avatar Jul 12 '22 03:07 HuyPham55

Hmm looks like "Condition on Per-Item Bases" is just for that.. it is right there in the Readme. You can apply it on add, or later:

Add condition to existing Item on the cart: Cart::addItemCondition($productId, $itemCondition)

Works fine for me. Maybe check if you've given the right $productId

Cheers

Blum avatar Jul 12 '22 06:07 Blum

Not sure if you've read my question entirely. It's about the quantity of the condition, not how to add condition to a cart item

HuyPham55 avatar Jul 19 '22 09:07 HuyPham55

If you want to achieve this, you should somehow save the second and the third product with different ID, so they won't get under the condition like the first one. But I don't think this could happen for the products under the same ID in the cart.

I would make it with some checks on adding, if the product exists in the cart, to save it with some prefix (or suffix) on the ID. And to apply this condition only on the products that have no suffix. Something like that.

Cheers

Blum avatar Jul 19 '22 10:07 Blum

If you want to achieve this, you should somehow save the second and the third product with different ID, so they won't get under the condition like the first one. But I don't think this could happen for the products under the same ID in the cart.

I would make it with some checks on adding, if the product exists in the cart, to save it with some prefix (or suffix) on the ID. And to apply this condition only on the products that have no suffix. Something like that.

Cheers

That requires extra work when it comes to display the shopping cart items (adding/subtracting product quantity to be specific) since you are creating a whole new row, while in fact, it's the same product. I just wondering if there is any native way or integrated configuration for that. Thank you anyway

HuyPham55 avatar Jul 20 '22 03:07 HuyPham55