Closed Web10-Joris closed 1 month ago
It's worked this way for a long time.
Originally, when a user added a product that already existed in the cart, it'd just add the product again without adjusting the quantity.
However, I believe there was a reason I ended up switching it to "up" the quantity instead. Although, I can't quite remember the reasoning now.
Since it's worked this way for a while now, I'd be wary of changing it now in case it causes an unexpected behaviour for other sites.
Description
The
CartItemController@store
method is not checking the already added quantity from the existing Line Items. When using{{ sc:cart:addItem }}
it is possible to add more quantity than available when doing multiple 'Add To Cart' submissions (see steps to reproduce).We can avoid this by checking (in antlers) if the product is already added and replace the
addItem
form with a 'View Cart' button, however I think it would be beneficial to have this check in place.Steps to reproduce
For example: Product X has a stock of 1. A visitor adds product X with quantity 1 and navigates to other product Visitor comes back on the productpage for X and adds it again. Now the LineItem of this product X are set to
quantity: 2
.Environment
Application Name: Local Laravel Version: 11.9.2 PHP Version: 8.3.7 Composer Version: 2.7.6 Environment: local Debug Mode: ENABLED URL: localhost Maintenance Mode: OFF
Cache Config: NOT CACHED Events: NOT CACHED Routes: NOT CACHED Views: CACHED
Drivers Broadcasting: null Cache: statamic Database: mysql Logs: stack / single Mail: smtp Queue: redis Session: file
Simple Commerce Currencies: EUR Gateways: Dummy Repository: Customer: DuncanMcClean\SimpleCommerce\Customers\EloquentCustomerRepository Repository: Order: DuncanMcClean\SimpleCommerce\Orders\EloquentOrderRepository Repository: Product: DuncanMcClean\SimpleCommerce\Products\EntryProductRepository Shipping Methods: Free Shipping Tax Engine: DuncanMcClean\SimpleCommerce\Tax\Standard\TaxEngine
Statamic Addons: 4 Sites: 3 (Nederlands, English, German) Stache Watcher: Disabled Static Caching: Disabled Version: 5.6.2 PRO
Statamic Addons aerni/advanced-seo: 2.5.3 aerni/font-awesome: 2.1.0 duncanmcclean/simple-commerce: 7.2.1 statamic-rad-pack/runway: 7.1.1