laravelshoppingcart icon indicating copy to clipboard operation
laravelshoppingcart copied to clipboard

Cartcondition only for one quantity on certain item

Open hakimihamdan88 opened this issue 10 years ago • 10 comments

Can i apply cartcondition only for one quantity for item?

Let say, id 1, buy 2 quantities, i want to set cartcondition only for 1 quantity

is it possbile?

hakimihamdan88 avatar Sep 17 '15 04:09 hakimihamdan88

Hello @hakimihamdan88,

Currently, it is not possible. As item with same id's are treated as 1 cart item and so it shares the same item condition. Did you find any workarounds in your case? If so, suggestions are welcome to support this. Thanks!

darryldecode avatar Sep 21 '15 01:09 darryldecode

The product conditions could have a different target (eg. Subtotal) to identify a set of conditions to be applied after calculating price * quantity. The value should be referred to item price. In this way, we can emulate a discount on the first product. For example, -100% means '1 product free', -200% means 'two products free' (we should check that price cannot become less than zero), -10 as fixed value means '-10$ if you buy at least one product of this kind' or '-10$ on the first product', basically it's the same.

Something like:

  1. Get the price
  2. Apply conditions that have target = item to get newprice
  3. Calculate subtotal = newprice * quantity
  4. apply condition that have target = subtotal (based on newprice, so 100% means 1 product free, 200% 2 product free and so on. We should check that price cannot became less tha zero.)
  5. return the result.

What do you think?

SimoTod avatar Sep 27 '15 22:09 SimoTod

+1 I need this too...

jurienhamaker avatar Nov 26 '15 09:11 jurienhamaker

ps. @SimoTod that's not a good way to do it. What if you want to apply -10% on one item, and another -10% on the second, but not on the third.

if you would do -20%, it would remove it from the first item in your logic.

I rather like something like:

new CartCondition([
            'name' => 'Your condition name',
            'type' => 'your type',
            'target' => 'item',
            'value' => '-10%',
            'quantity' => 1
        ]);

this would apply to only one 1 of the item.

jurienhamaker avatar Nov 26 '15 09:11 jurienhamaker

@HazeDevelopment Under the wood, both algorithms compute the same result.

E.g. Consider a product with price = x, 3 item in the cart, -10% on tw items. (x - (0.1 * x)) + (x - (0.1 * x)) + x = 2.8x -> Your way. (3* x) - (0.2 * x) = 2.8x -> My way.

However, I agree with you that your sintax is more expressive and less error prone to quantity check.

SimoTod avatar Nov 28 '15 23:11 SimoTod

I know, it sure does the same, but as developer you would like to let users have an experience with your work, hence why mine is more logical to most people (I am almost sure of)

but I guess the @darryldecode isn't doing much with his lib anymore, as other issues are still open for way too long.

jurienhamaker avatar Dec 01 '15 20:12 jurienhamaker

Yes, indeed. I thought that quantity check is enormously easier in your version, too. (To avoid to apply more discount than necessary) Maybe Darryl is busy, but he is certainly willing to merge a PR. If you like, you can work on this issue. In your opinion, when is the best moment to apply this kind of conditions during the flow? Even if item related, I am not sure that would be a good idea to apply it on ItemCondition class. When I will print the cart on a web page, maybe I should show the row subtotal as currently is and I should apply these conditions when we calculate the grand total. How it sound?

SimoTod avatar Dec 01 '15 21:12 SimoTod

Hi @HazeDevelopment, sorry I was just busy. I am aware of this but as I see on the discussion here, this issue has different solution with different effects so I am not yet sure the better way to do it. Maybe until we could come up and agree in one solution here. Feel free to do a PR :)

darryldecode avatar Dec 02 '15 00:12 darryldecode

+1

dennisoderwald avatar Dec 08 '15 16:12 dennisoderwald

Wouldn't it be the case to apply the condition to the item before sending it to the cart?

webfelipemaia avatar Jun 22 '20 05:06 webfelipemaia