Peter V. Shark
Peter V. Shark

Reputation: 21

Drupal commerce - Calculate tax on custom line-item

I need to add an extra fee to the shipping price for delivery on holidays and sat/sunday

So i created a custom commerce-line-item which would be added to the order on those days.

But it won't calculate tax for that extra fee-item.

Here is an example order:

Subtotal              1.351,35 DKK
Express-delivery      810,00 DKK
Delivery fee          750,00 DKK
Tax                   540,34 DKK
Order total           3.451,69 DKK

The tax is 25% As you can see it only calculates tax for 'subtotal' and 'Express-delivery'

How do i make commerce calculate tax for my custom line item?

I see the shipping module does it though some rules, but i cant grasp how to convert that code for use in my line-item-module.

Anyone got a solution?

Thanks.

Upvotes: 1

Views: 2006

Answers (1)

Peter V. Shark
Peter V. Shark

Reputation: 21

I finally figured it out myself,

I implemented the hook hook_rules_event_info()

And called rules_invoke_all('my_rule', $line_item); on my line item before adding it to the order. and it worked :)

Hope this helps someone else in the future.

Result:

Subtotal            1.351,35 DKK
Express-delivery    810,00 DKK
Delivery fee        750,00 DKK
Tax                 727,84 DKK
Order Total         3.639,19 DKK

Upvotes: 1

Related Questions