Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This update introduces several enhancements to the cart system, focusing on improving the user experience and adding functionality for discount codes, shipping costs, and persistent carts.
Discount Feature
Added functionality to apply a discount code to the cart, reducing the total price.
Users can input a discount code, and the cart will automatically apply the discount to the total.
New methods:
applyDiscount($code, $amount): Applies the discount code and amount.
getTotalWithDiscount(): Returns the total price after applying the discount.
Shipping Costs
Implemented a way to add shipping costs to the cart total.
The shipping cost can be set manually, and it will be added to the total amount at checkout.
New methods:
setShippingCost($cost): Sets the shipping cost.
getTotalWithShipping(): Returns the total cost after adding shipping.
Persistent Cart for Logged-in Users
Added the ability to save the cart data into a database for logged-in users.
This allows users to maintain their cart items between sessions, ensuring a smoother shopping experience.
New methods:
saveToDatabase($userId): Saves the cart items to the database for the given user.
loadFromDatabase($userId): Loads the cart from the database when the user logs in.
Bug Fixes