CodeIgniter Forums
cart with discount option - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: cart with discount option (/thread-69143.html)



cart with discount option - cpuin - 10-13-2017

Hi,

How nice is to find this forum.


I'm using the cart class ( I know that because of some strange reason is deprecated, but I find it useful).
I want to add the option for discount.I add "discount" in the array, but I have no idea wether is possible in my update method to update the amount and in it to deduct % from the amount?


RE: cart with discount option - PaulD - 10-13-2017

I would suggest that you have now outgrown the somewhat limited cart class, and because everyone wants their cart to operate in a different way, you see now why the cart class was deprecated. It is just impossible to allow for all the things people want to do with their carts. And there is no 'right way' to do any of them.

I would suggest you invest some time making your own shopping cart library. That you store you cart contents in a table, and then if you wish, you can do individual discounts, category discounts, basket discounts, volume discounts, free delivery limits, etc etc etc.

When a logged in user comes back, if you keep the carts in a table, their cart will be re-populated with what they had in their cart on their last visit. You can clean out the cart table periodically. When they place an order, you move the cart to an order table, and clean out the cart, so their basket is empty again.

To sort of do what you are suggesting, you could read the item, apply the discount, and store back the new price into the item. But you will not be able to display in your checkout the discount amount (as it is not recorded) nor the reason for the discount.

You should also be able to check if the discount is still valid, if the user has the right to use it (ie first buy discount but it might not be their first purchase), and what the discount value is set to. For instance a 'loyalty' discount might be set to 10% but then be reduced to 9%.

You could keep using the cart, and do all the discount stuff at the checkout. But in the long run I think you will benefit from making your own shopping cart rather than using the deprecated version included only for legacy reasons. And at some point, it will be dropped entirely.

Best wishes,

Paul


RE: cart with discount option - cpuin - 10-13-2017

(10-13-2017, 12:16 PM)PaulD Wrote: Thank you for your time Paul.
It's pity to create new class only because of this.
I'm not making just a site with cart, it's a sophisticated web-based warehouse system.All sells should have an option for discount and yes, it's important after the update the initial value, the % and the discounted value to be displayed.


I would suggest that you have now outgrown the somewhat limited cart class, and because everyone wants their cart to operate in a different way, you see now why the cart class was deprecated. It is just impossible to allow for all the things people want to do with their carts. And there is no 'right way' to do any of them.

I would suggest you invest some time making your own shopping cart library. That you store you cart contents in a table, and then if you wish, you can do individual discounts, category discounts, basket discounts, volume discounts, free delivery limits, etc etc etc.

When a logged in user comes back, if you keep the carts in a table, their cart will be re-populated with what they had in their cart on their last visit. You can clean out the cart table periodically. When they place an order, you move the cart to an order table, and clean out the cart, so their basket is empty again.

To sort of do what you are suggesting, you could read the item, apply the discount, and store back the new price into the item. But you will not be able to display in your checkout the discount amount (as it is not recorded) nor the reason for the discount.

You should also be able to check if the discount is still valid, if the user has the right to use it (ie first buy discount but it might not be their first purchase), and what the discount value is set to. For instance a 'loyalty' discount might be set to 10% but then be reduced to 9%.

You could keep using the cart, and do all the discount stuff at the checkout. But in the long run I think you will benefit from making your own shopping cart rather than using the deprecated version included only for legacy reasons. And at some point, it will be dropped entirely.

Best wishes,

Paul