2
Answers
Vote up!
0
Vote down!

Shipping - Adding variable handling charges based on product

I wonder if anyone knows how to add product specific handling charges during shipping calculation.

Example:
Product A - might need an additional $5 handling fee (per qty) added to all shipping services
Product B - might need an additional $10 handling fee (per qty) added to all shipping services

etc.

I've created a field in the Product type: field_product_handling_fee

I cannot get the field to be available during rules calculation. I see references to how to do this, but nothing that is clear and reproducible. I'm new to complicated rules, and I don't fully understand the programming logic behind lines items, order items etc. So, if someone has a really straight forward way of explaining this, I would be grateful.

FYI - I am using UPS module, and Shipping 2.

Thank you!

Asked by: scottedmonds
on April 22, 2013

Comments

This is what I'm looking for. Commerce Fee module is ok but it only applicable to total amount on cart. I wanted to add handling fee to each product on checkout.

- mark.thehub on September 3, 2013

2 Answers

Vote up!
0
Vote down!

I was able to successfully solve this problem.

I did so by using the thorough answer provided by @mengi here: http://groups.drupal.org/node/160249

Scrolling down to "Finally Figured it out"

He walks through the process pretty thoroughly, however, I made some changes which I will note here. Primarily, he has a Boolean field for handling fee, whereas I have a per product decimal field so that I can tailor the handling fee to each product. (My store has some complicated items that need special handling). So, in

Add boolean field to product type
Machine Name: field_fee

Mark a product with the field_fee checkbox (or add decimal field to hold a specific value. Note, values are in cents, so 500 is $5)

Goto >Shipping>Calculation Rules
Add Calculation Rule
Name: Fee for Product (or whatever you want)
Add Loop
data selector: commerce-line-item:order:commerce-line-items
Variable Label: Line Item
Variable Name: line_item

Goto >Rules>Components
Add Component
Component Plugin: Rule
Name: Adding Fee Action (or whatever you want)

Add 2 Variables:
Variable 1
Data Type: Commerce Line Item
Label: Line Item
Machine Name: line_item
Usage: Parameter
Variable 2
Data Type: Commerce Line Item
Label: Shipping Line
Machine Name: shipping_line
Usage: Parameter
Add 3 Conditions (or 2 depending on which solution, as noted below, I only needed two conditions)
Condition 1
Entity has field
Data Selector: line-item
Value: commerce-product
Condition 2
Entity has field
Data Selector: line-item:commerce-product
Value: field_fee
Condition 3 In the case of a value for handling, this condition is not necessary
Data Comparison
Data Selector: line-item:commerce-product:field-fee
Operator: equals
Data Value: (Mark the checkbox)
Add 2 Actions
Action 1
Calculate a Value
Data Selector: line-item:quantity
Operator: *
Input Value 2: 500 (for $5.00)(Change to whatever fee you want to charge) Here is where my solution differs, I used the following to get the value from the data field: line-item:commerce-product:field-fee
Label: Fee Result
Name: fee_result
Action 2
Add an amount to the unit price
Data Selector: shipping-line
Amount: (switch to data selection): fee-result
Value: Shipping Note: if you want this to appear as a separate "Fee" line on the invoice, you can select Fee as the value for this field.

Go back to original shipping calculation rule
Add action to the loop (MAKE SURE IT'S TO THE LOOP, NOT 'add action' to actions...it is to the right, under 'operations')
Rule: Adding Fee Action (The Rule Component we just made)
Data Selector 1(Line Item): line-item
Data Selector 2(Shipping Line): commerce-line-item

Answer by: scottedmonds
Posted: Apr 23, 2013
Vote up!
0
Vote down!

This seems to be a common use. I would like to see the drop down include items such as SKU then you would be able to apply if the SKU = xxx

Answer by: dupls
Posted: Nov 26, 2013