2
Answers
Submit handler for quantity change in cart?
Hi all,
I am writing a Commerce submodule that needs to run some code on the line items in an order after the Update Cart or Checkout buttons are clicked in the shopping cart form... but I'm not sure where to put it. More specifically, I need to see if the user updated the quantity of a line item in their cart and then write code that acts on the quantity change (without using Rules).
I am already using hook_form_FORM_ID_alter() to alter the Remove buttons in the shopping cart, I figured I could just add a submit handler in this hook but that doesn't seem to work:
function MYMODULE_form_views_form_commerce_cart_form_default_alter(&$form, &$form_state) {
$form['#submit'][] = 'MYMODULE_cart_submit';
}
function MYMODULE_cart_submit($form, &$form_state) {
dsm($form);
}
When I hit either Update Cart or Checkout, dsm doesn't load on the next page. If I try dsm('hello, world!'), I don't get that either. Am I in the right spot? I assumed I could just work with $form_save in the submit handler, and then resave the line items using
commerce_line_item_save($line_item).
Thanks! :)