hi, how do i add a price component to every order based on the total.

That should happens:

- User has an emty cart
- User adds a product
- User clicks on the checkout and now he see in his shopping cart the subtotal, the tax, "Special Costs", and the total

"Special Costs" is an amount witch should be added to the total!!!

What i can do with rules or coupon is to add a discount, but it shouldn't be a disount, i should costs more! And that on every order, always the same price.

Do i have to add another price component like the tax component (but not based on the line item price)? But how?

Hope you know what i mean.

Comments

rszrama’s picture

Status: Active » Fixed

There's a default "Fee" component type you could take advantage of, or you can define a custom price component type in a module like so:

/**
 * Implements hook_commerce_price_component_type_info().
 */
function [your_module_name]_commerce_price_component_type_info() {
  return array(
    'special_costs' => array(
      'title' => t('Special costs'),
      'weight' => -40,
    ),
  );
}

Then you just need to add a product pricing rule that uses the Commerce Line Item action "Add an amount to the unit price" and specifies your custom price component type. The only hitch here is to remember that this is being added to the line item's unit price, so it will be multiplied out for each quantity of the line item.

forward-media’s picture

That is exactly the problem i could not solve at the moment,... i need something like: "Add an amount to the order total" not "Add an amount to the unit price"
It should work like the shipping line item, but not after entering a shipping adress, independent from the address!

rszrama’s picture

Right, I'm saying that capability already exists. Add a product pricing rule from your Store configuration menu using the action I pointed out above.

ryan.ryan’s picture

I'm trying to figure out if you are saying that adding an amount to the order exists or adding an amount to each item exists. I need to do the same thing - add a "special fee" to the overall order regardless of total or quantity. For instance, this "special fee" needs to always be $15.00, regardless of whether the total is $1, $1000, 1 item, or 15 items.

forward-media’s picture

@ryanissamson: and did you find the right way? maybe we can do it together, ...

rszrama’s picture

Status: Fixed » Closed (duplicate)

I apologize. I've been responding during Do It With Drupal and didn't realize you were saying things the other way around. ; )

To add a separate fee to the entire order, you need to create a custom line item type at this point and add the fee in through there... no quick example, though I know several people have demonstrated that in the queue in the past and may have examples for you.

On the 2.x battle plans is the idea to allow additional calculation steps beyond just the unit price, but I'm still not sure where those steps will be accounted. They'll likely entail extra line items anyways. I got tripped up by the title. I'm going to mark this duplicate and recommend you use a separate line item type with the code I posted above to define the price component type you can use in the line item type. The full implementation of this is more than I can quickly type out in an issue.

Macronomicus’s picture

Thanks Ryan #1 is exactly what I needed, I thought for sure I'd have to bend over backwards to get my custom calculated component bit to show in the cart and all, to the contrary it was simple!
Commerce is awesome!