Druapl 7 Update displayed price of product when quantity changes I'm new to drupal. What I want is the price to be updated for an ubercart product when I change the quantity the same way it happens with the attributes on the product page.

So far I have a custom module to edit the type of the edit quantity form when I add a product in my cart. I turned it to a select box and tried to append the class ajax-processed but nothing happens.
Well after some tail chasing I managed to do it. It probably is a bad solution since I had to modify uc_product_module itself. Here's what I did:

1) Created a custom module that adds two buttons in hook_form_alter- and + that will modify the quantity:

    $form['decrease'] = array(
        '#name' =&gt; 'decrease',
        '#id' =&gt; 'decrease-product-qty',
        '#type' =&gt; 'button',
        '#value' =&gt; t('-'),
        '#prefix' =&gt; '&lt;div class="form-item form-item-qty-btn form-type-uc-quantity form-group"&gt;',
        '#ajax' =&gt; array(
            'wrapper' =&gt; 'wrapper',
            'callback' =&gt; 'decreaseProductQuantity_form_ajax_callback'
        )
    );

/**
 * AJAX callback function for addToCartFormEditQuantity_form().
 */
function decreaseProductQuantity_form_ajax_callback($form, $form_state)
{
    $nid = $form_state['values']['nid'];
    $node = node_load($nid);

//Get current quantity
$quantity = (int)$form['qty']['#value'];
// Adjust
if ($quantity &gt; 1) {
    $quantity--;
}

$form_state['storage']['quantity'] = $quantity;

// Calculate updated price to be displayed
$displayPrice = uc_currency_format($node-&gt;price*$quantity);
// Price textfield id and class
$fieldId = "#total-price-uc-product-" . $nid;
$fieldClass = '.uc-price';

// Update field via command
$commands = array();
$commands[] = ajax_command_invoke('#edit-qty', 'val', array($quantity));
$commands[] = ajax_command_html($fieldClass, $displayPrice);

// Send the command to the page.
$page = array(
    '#type' =&gt; 'ajax',
    '#commands' =&gt; $commands,
);   
return $page; 
}


2) Saved quantity in $form_state['storage']['quantity'] = $quantity; as seen above. In order to keep the value form being erased add use $form['after_build']:

//Inside hook_form_alter
$form['#after_build'][] = 'addToCartFormEditQuantity_after_build';

function addToCartFormEditQuantity_after_build(&amp;$element, &amp;$form_state)
{
    $form_state['storage']['quantity'] = (int)$element['qty']['#value'];
    return $element;
}


3) Final step modified ubercart/uc_product/uc_product.module function uc_product_view_ajax_commands:

 * @return
 *   An array of Ajax commands.
 */
function uc_product_view_ajax_commands($form_state, $keys) {
  $commands = array();
  if (variable_get('uc_product_update_node_view', FALSE) &amp;&amp; !empty($form_state['storage']['variant'])) {
    $node_div = '.uc-product-' . $form_state['storage']['variant']-&gt;nid;
    $build = node_view($form_state['storage']['variant']);
    foreach ($keys as $key) {
      if (isset($build[$key])) {
         //Modify display price to take qantity into consideration
        if ($key === "display_price") {
          $quantity = (int)$form_state['storage']['quantity'];
          $totalPrice = (float)$build[$key]['#value'];
          $totalPrice *= $quantity;

          $build[$key]['#value'] = $totalPrice;
        }
        $id = $node_div . '.' . str_replace('_', '-', $key);
        $commands[] = ajax_command_replace($id, drupal_render($build[$key]));
      }
    }
  }
  return $commands;
}