2

I use Drupal Commerce with Commerce Shipping and Commerce Flat Rate.

I have a client who wants the shipping line item in the commerce summary cart to come before the tax line item. My problem lies in that Commerce Shipping doesn't expose the weight of each shipping service when it implements the hook_commerce_price_component_type_info as seen below.

I have tried to use the mentioned hook in one of my own modules and with a lower value for the weight. This produces an error in the Commerce Price module where it tries to do the addition array(20, -50) + 1. Somehow, the Commerce Price module creates an array of the values instead of overwriting.

The weight I'm trying to overwrite is the one in the foreach loop.

Once I have solved this, I'll need to subtract the tax component on the shipping line item, but that's another problem which I can probably figure out by myself.

Line 110 to 135 in commerce_shipping.module.

/**
 * Implements hook_commerce_price_component_type_info().
 */
function commerce_shipping_commerce_price_component_type_info() {
  $components = array();

  // Define a generic shipping price component type.
  $components['shipping'] = array(
    'title' => t('Shipping'),
    'weight' => 20,
  );

  // Add a price component type for each shipping service that specifies it.
  foreach (commerce_shipping_services() as $name => $shipping_service) {
    if ($shipping_service['price_component'] && empty($components[$shipping_service['price_component']])) {
      $components[$shipping_service['price_component']] = array(
        'title' => $shipping_service['title'],
        'display_title' => $shipping_service['display_title'],
        'shipping_service' => $name,
        'weight' => 20,
      );
    }
  }

  return $components;
}

PS. Tax rate on shipping price is not the same as my problem. DS.

2
  • Have you tried drupal.org/project/commerce_flat_rate ? You need shipping 2.x Commented Sep 11, 2012 at 14:18
  • Sorry, should have mentioned that. That's the module I'm using with Commerce Shipping. As far as I know, there isn't any way of setting the weight of the shipping line item's weight. I should emphasize that I don't need to change the weight of each shipping service (for the shipping pane/page), only in the review pane and the checkout pane.
    – hampusn
    Commented Sep 11, 2012 at 15:22

2 Answers 2

1

If I get you correctly, you want to alter the order in where this components are displayed in the checkout process.

What I've done for minor tweaks on this area is using a preprocess of the components theme function, for example:

function mymodule_preprocess_commerce_price_formatted_components(&$variables) {
}

There you've got $variables and all the components, including the shipping ones so you can tweak some things of the display.

0

Try the following Hook

hook_commerce_price_formatted_components_alter

For more details on this hook refer : http://api.drupalcommerce.org/api/Drupal%20Commerce/sites!all!modules!commerce!modules!price!commerce_price.api.php/function/hook_commerce_price_formatted_components_alter/DC

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.