Blog posts tagged with 'Surcharge'

RSS
Add a handling charge for a Category- Wednesday, April 2, 2014

If you want to charge a fee when the cart contains any items from a given Category...

Order

Type

Name

Expression

Rate Expression

Surcharge Expression

100

Decimal

SurchargeForX

Items.Any(Product.HasCategory("CategoryX")) ? 20 : 0

 

 

110

Option

Shipping

true

Shipping.Fedex

[SurchargeForX]

The variable for surcharge is calculated using the ternary if-then-else operator “ ? : “.  The Option record’s rate expression can be a fixed amount, or can refer to any shipping rate calculation plugin.

Additionally, you can show the customer a description explaining that a fee has been added (it appears to customerunder the shipping option name).  Just include a Description Expression on the Optionline:

[SurchargeForX] = 0 ? "" : "A $" + [SurchargeForX].ToString() + " has been added because your cart contains a product formCategory X"

If you only want to charge the fee if the total amount of merchandise from that particular Category is under $250, then we need to calculate the total $ amount of the items for that Category, then the expression for SurchargeForX would need to check if that total is less than $250:

Make these changes to the above:  add line 10 for the total $ calculation and change line 100 to use the total:

Order

Type

Name

Expression

Rate Expression

Surcharge Expression

10

Decimal

TotalForX

Items.Where(Product.HasCategory("CategoryX")) .Sum(GetSubTotalWithDiscounts())

 

 

100

Decimal

SurchargeForX

[TotalForX] < 250 ? 20 : 0

 

 

(There is also GetSubTotalWithoutDiscounts() if you do not want to include any discounts in the total calculation.

Tags :  Surcharge
Comments (0)