I'm currently building a webstore for a client that needs to display hundreds of items on a single page and have customers enter the quantity that they want for each into the form. This modules works perfectly for the base functionality required. However, since there are hundreds of items on the page, and it is perfectly acceptable for a customer to add at least 1 of each product to the cart, this module needs to be able to handle any number of products added to the cart at once. Currently, when adding hundreds of items at once, a PHP timeout error will occur. As such, I propose that we implement the Batch API as an optional feature for handling large submissions.
To this end, I have already started trying to cobble together some form of Batch processing. If I manage to make it work I'll provide a patch that adds the feature.
As a side note, if this works it will provide a better solution to #1959530: 'Add to Cart' process slows as more products added
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | commerce_add_to_cart_extras-batch_processing-2221707-1.patch | 7.99 KB | redeight |
Comments
Comment #1
redeight commentedPatch adds an option to the views field to enable batch processing of the add to cart form submission.
Please note, while it works, this doesn't necessarily speed up the add to cart process at all. It simply avoids the PHP Timeout issue when adding TONS of items all at once using the quantity field.
If anyone can come up with a better/faster solution please do. I'm gonna be researching speeding this up as commerce_add_to_cart seems to be REALLY slow.
Comment #2
redeight commentedComment #3
redeight commentedAfter some further research I came up with an ajax solution that worked for my use case. Unfortunately my solution required significant rewrites and changes a serious amount of functionality. It hides the submit button and instead submits a cart item every time the quantity field changes. To facilitate this I added a feature to pull in the contents of the user's cart and update the quantity fields in the views form to match the cart. I also had to add a way of deleting line items from the cart if the quantity field were cleared or set to 0. Anyone interested in the code can check out my sandbox project. Commerce Add to Cart Ajax
Comment #4
maxplus commented@RedEight
Very nice sandbox project, I'm testing it right away!
Comment #5
maxplus commented@RedEight
I have tested your ajax module and it works good.
In my use case the load time for every ajax action was slowing down the input for the customer, so I went back to using "Commerce Add to Cart Extras"
The problem now is like you mentioned that when using a big page with a lot of quantity fields, it can take a very long time to submit, in my case sometimes more then 120 seconds.
So I will try to use your patch from #1 to make sure the end user does not get a php timeout
Comment #6
maxplus commented@RedEight
I have manually applied your patch to the current Commerce Add to Cart Extras module, and it is working good for me.
I'm very satisfied about the fact that I now do not get a php time out anymore AND that the user can see the progress of the mass adding to cart action.
Thanks for this useful contribution!