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