How do I act after quantity change in cart? I am writing a Commerce submodule that needs to run some code on the line items in an order when 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(&amp;$form, &amp;$form_state) {
  $form['#submit'][] = 'MYMODULE_cart_submit';
}

function MYMODULE_cart_submit($form, &amp;$form_state) {
  dsm($form);
}


When I hit either Update Cart or Checkout, dsm doesn't load on the next page. Am I in the right spot?

Thanks! :)
You could use the Entity API type hooks (load, presave, update etc..) to act when the commerce_line_item is updated

e.g: 

/**
 * Implements hook_entity_update
 */
function MYMODULE_entity_update($entity, $type){

  if($type == 'commerce_line_item'){
    // Do stuff with line item in $entity;
  }

}


You might have access to $entity-&gt;unchanged or similar in $entity which stores the entity content prior to the save. Useful for comparing quantity to see if it's changed!

dpm($entity); // for details.


You can also use hook_ENTITY_TYPE_update

/**
 * Implements hook_ENTITY_TYPE_update
 */
function MYMODULE_commerce_line_item_update($entity){

  dpm($entity);

}


The hooks for load, presave, insert, update and delete are available for all Commerce entity types.