Closed (fixed)
Project:
Commerce Core
Version:
7.x-1.x-dev
Component:
Cart
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
27 Dec 2011 at 17:23 UTC
Updated:
20 Jan 2017 at 23:05 UTC
Jump to comment: Most recent
Comments
Comment #2
rszrama commentedIt's technically possible using hook_form_alter() on the Add to Cart form, but it's not something I think we'll be putting in core. You would need to add #ajax settings to the quantity widget to work on change.
Comment #3
frixos12 commentedIs there any particular reason for not putting this functionality in core?
More specifically, you think it's better from the customer's point of view to have an update button for the entire shopping cart form?
I am developing an e-shop and i would like to hear your opinion in order to decide the best method for updating a cart.
Thank you
Comment #4
rszrama commentedThere's no particular reason to keep it out of core other than feature bloat; we'd hope to avoid that, so non-essential core features are typically punted to contribs. I'm not sure exactly how we'd integrate a feature like this into the default Cart View, but I know that it should be technically possible in contrib. I'd feel more comfortable moving it to core after seeing how much code it took to achieve and whether or not it resulted in any unintended side effects on that form.
Comment #5
frixos12 commentedHi and thank you for your post!
Can you give me some code hints of how to add #ajax settings inside hook_form_alter??
Thank you
Comment #6
rszrama commentedNothing special - just look at how we use #ajax inside of Commerce and imagine adding it into the form via an alter instead of the original form. If you aren't sure what these things are, I'd recommend getting a Drupal 7 development book.
Comment #8
jonne.freebase commentedIf anyone is wondering how to do this, I managed to make it work with the following code:
(put it in your theme's .js file)
If you use this in conjunction with the DC cart AJAX module, this code will reload the cart form after changing the value of the field. If you know a better way of accomplishing this, please let me know.
Comment #9
ThomasIsabelle commentedHello jonne.freebase,
I followed your suggestion, but it isn't working for me.
1. Installed and enabled the DC cart AJAX module.
2. Set "Use AJAX " to Yes in "admin/structure/views/view/commerce_cart_form/edit" and saved.
3. Inserted your code into "profiles/commerce_kickstart/themes/omega_kickstart/js/omega_kickstart.js" (my site's theme for the Kickstart Commerce demo site.
4. And nothing. Still not auto-updating.
Any thoughts on why?
Thank you!
Tom
Comment #10
alexverb commentedHere's the way rszrama suggested:
I do think that frixos12 is right that this feature should be a simple setting in the cart display settings. This alter probably takes way much effort than just checking a setting. +1 for voting it in core functionality.
One more caveat. This code doesn't take in consideration if a page refresh should happen. Then the price would be back at it's original value for quantity 1 with another quantity as value. Any suggestions for that are welcome...
Comment #11
alexverb commentedNow that I think about it, this all isn't such a good idea when you have other price calculations that have to be taken in consideration. Like for example, buying 10 items gives you 10 percent off... Do you think it's possible to run rules during ajax to calculate the price?
Comment #12
marilena6 commentedHello,
I'm building a directory site with ordering features and I have this issue:
I've created a Product Display which is loaded in a popup after a user clicks on the product. I've added a rule when the user clicks add to cart, a custom .php file is called so the popup is closed and the parent window which contains the cart block is reloaded
but I was wondering if this could be done with Ajax, so when the user closes the popup (if he adds the product) the cart will be automatically reloaded and not the whole parent page.
Comment #13
bellagio commentedHello alexverb, #10 doesn't change price when quantity is changed with fresh install of kickstart profile and mymodule only. could you let us know if your code is working for you?