Hi there,

I have just read this thread: http://drupal.org/node/1352916 "(Provide the ability to include VAT (or other components) in the Subtotal display of price components)".
I almost solved the VAT related stuff. VAT is calculated from Subtotal PLUS Shipping (That´s correct).

Only one thing is left:

How can I make the display of VAT switch it´s position with Shipping?

The order should be

  1. Subtotal
  2. Shipping
  3. VAT
  4. Order Total

instead of

  1. Subtotal
  2. VAT
  3. Shipping
  4. Order Total

Thanks a lot
Wiegand

Comments

rszrama’s picture

Status: Active » Fixed

You should get by with hook_commerce_price_formatted_components_alter(). These components can be reordered through there or through the weights of the price component types themselves (alterable through hook_commerce_price_component_type_info_alter()). There is no UI for this.

4kant’s picture

Thanks Ryan,

wouldn´t it be worth called a "feature request" then?
Either as a UI or at least a more lightweight solution than coding?

rszrama’s picture

I wouldn't mind a contrib providing the UI at this point, but I'm not sure we need to have (or have a place for) a core UI at the moment. There are many elements of Drupal Commerce that are intended to be customized through code still, and we need to get a good consensus on just how much needs to be UI configurable in the core project. See for example defining / reordering order states and statuses.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

_paul_meta’s picture

I agree there should be a UI means to rename and order price components

JemBijoux’s picture

Just FYI - While working through some similar issues, I found Commerce Price Extra.
Looks like it does exactly what you (and I) need:

Allow ordering of price components in checkout cart pane

amillionmonkeys’s picture

Hi there,

Drupal newbie here. I'm sure for you developer types this is all pretty easy, but for us mere mortals, all this hook stuff is pretty tricky. Any chance anyone could show me an example of how to use hook_commerce_price_component_type_info_alter(). I am desperate to acheive exactly what Wiegand describes here. Or Wiegand could you let me know if you managed this?

4kant’s picture

Hi Phil,

how come you´re a drupal newbie being a member for more than 4 years? ;-)
I´m sorry I can´t tell you anything of having succeeded in this. I think I found a way in my project the display wasn´t necessary any more.
But what about the solution being mentioned by #6?

If you you should follow this advice could you please post what you achieved there in this issue?

Thanks in advance!

amillionmonkeys’s picture

LOL! I dabbled four years ago, but was recently made redundant so now I'm trying to make a living.

Unfortunately the solution in #6 doesn't work for me... Long story. I'm sure if I was a decent developer I'd have it done in a jiffy using the hook Ryan mentioned above, unfortuantely I am not :-(

meecect’s picture

Issue summary: View changes

I did something like this. Here is my code:

/**
 * Implements commerce_price_formatted_components_alter()
 * Used to reorder the total price components for credit type coupons
 * to appear last, before the order total
 */
function t_checkout_mods_commerce_price_formatted_components_alter(&$components, $price, $entity) {
  // drupal_set_message(print_r($components, TRUE));
  // find the biggest weight, only if there is a credit coupon
  if(isset($components['commerce_coupon|credit'])) {
    // Start with the first weight value
    $weight = $components['commerce_coupon|credit']['weight'];
    $new_key = 'commerce_coupon|credit';
    foreach ($components as $key => $component) {
      if($component['weight'] > $weight) {
        $weight =  $component['weight'];
        $new_key = $key;
      }
    }
    $components['commerce_coupon|credit']['weight'] = $weight;
    // Make the previous heavy item (should be order total) appear below credits
    $components[$key]['weight'] = $weight+1;
  }
}

It's part of a custom module of ours called t_checkout_mods. It looks for a particular price component, and if it finds it, it moves it to the bottom of the list, right above the order total. It could be simpler, but I was trying to code it in a very generic way, like not assuming what the 'order total' component is named, and not assuming the total has a specific weight, etc.

kenorb’s picture

Some simpler example:

/**
 * Allows modules to alter the price component types defined by other modules.
 */
function hook_commerce_price_component_type_info_alter(&$component_types) {
  $component_types['base_price']['weight'] = -100; // Move Base Price at the beginning.
  $component_types['discount']['weight'] = $component_types['base_price']['weight'] - 1; // Move Discount just before the Base Price.
}

If you're using view for checkout, then you've to use hook_commerce_price_formatted_components_alter(), so e.g.:

function hook_commerce_price_formatted_components_alter(&$components, $price, $entity) {
  if (isset($components['tax|uk'])) {
    $components['tax|uk']['weight'] = 1;
  }
  $components['commerce_price_formatted_amount']['weight'] = 2;
}
tj99ay’s picture

For those in Australia what worked for me was adding this to your template.php file:

function THEME_NAME_commerce_price_formatted_components_alter(&$components, $price, $entity) {
  if (isset($components['tax|my_gst'])) {
    $components['tax|my_gst']['weight'] = 25;
  }
  $components['commerce_price_formatted_amount']['weight'] = 26;
}

That then gave me everything displaying as:

Subtotal $105.00
Express Shipping $18.18
GST $12.32
Order total $135.50

My machine name was "my_gst" for the tax type and you can get this machine name from:

Store > Configuration > Tax Types

under the "Name" column in little letters eg. "GST (Machine name: my_gst)"

Hope that helps someone else out there.

RAWDESK’s picture

If you want re-ordering fixed both in commerce front office as backoffice, you need respectively both #12 and #11 to solve it.
Worked for me.

uschi_glas’s picture

#12 works like a charm. Thank you!

maxplus’s picture

Thanks,

#12 solved this issue for me!

BITANUBE’s picture

Thanks,

+100 points to #11

nikolino’s picture

I'm using Commerce VAT, do you know where I can find the Machine name?
Thank you!

pierre-nono’s picture

joerch’s picture

Thanks tj99ay!

#12 works for me!