Blog posts of '2012' 'May'

RSS
Exclude Shipping Options from Carrier Plugins- Monday, May 21, 2012

(Updated 11/29/2013 for Shipping Director versions for nopCommerce 3.x) 

For external shipping rate methods (carrier plugins like FedEx, USPS, etc.), which can return many options, it may be desirable to conditionally eliminate some options.

In this example, we only offer USPS Media Mail if all items in the cart are books:

Order

Type

Name

Expression

Rate Expression

Name Expression

10

Boolean

CategoriesAllBooks

Items.All(Product.HasCategory("Books"))

 

 

100

Option

USPS

true

Shipping.USPS

[$Name].Contains("Media Mail") and ![CategoriesAllBooks] ? "" : [$Name]

Of course you're not limited to checking Categories.  For example, you could also eliminate an option based on there being any item in the cart with the Product Name Length greater than X.  E.g.

Items.Any(ProductVariant.Product.Name.Length > 12)

_________________________________________________________________________________________________  

Here's the old version for nopC 2.x having Product Variants, and prior to SD having HasCategory() function:

Order

Type

Name

Expression

Rate Expression

Name Expression

10

Reference

categories

ProductVariant.Product.ProductCategories

 

 

20

Boolean

categoriesAllBooks

Items.All([@categories].Any(Category.Name = "Books"))

 

 

100

Option

USPS

true

Shipping.USPS

[$Name].Contains("Media Mail") and ![categoriesAllBooks] ? "" : [$Name]


Tags :  ExcludeOption
Comments (6)
Shipping Rates with a Minimum Charge- Sunday, May 20, 2012

As previously mentioned, I'll be posting some more simple shipping examples...

The first shipping computation example we'll configure is:

Charge a fixed rate of 6% of the shopping cart sub total; however there should be a minumum of $10.

Here are some Shopping Cart Properties that are pre-defined variables in Shipping Director:

$TotalWeightDecimaluses ShippingService.GetShoppingCartTotalWeight()
$SubTotalWithoutDiscountsDecimaluses PriceCalculationService.GetSubTotal()
$SubTotalWithDiscountsDecimaluses PriceCalculationService.GetSubTotal()
$IsFreeShippingDecimaluses OrderTotalCalcService.IsFreeShipping()

(All pre-defined variables start with "$".  Also, when referenced, don't forget to enclose variable names in square brackets [ ] .)

So, 6% of  our "shopping cart sub total" would look like   [$SubTotalWithoutDiscounts] * 0.06

We want to calculate:  If 6% of subtotal is greater than $10, then use it, else use $10.  The If-Then-Else is achieved using the "? : " ternary operator -  condition ? if-true : if-false.

Here's the final record entry:

Above you can see how easy it is to have fixed rates with a minimum charge.   You can have a minimum shipping fee even when using actual rates from an external shipping method (like UPS, Fedex, USPS);  it's easily achieved using the Surcharge Expression - if the Rate returned by the shipper is more than $10, then no surcharge ($0), else the surcharge is the difference between $10 and the Rate returned.


Of course, you'd probably want to change the Name to something like "Shipping Rate".  Or, leave the name for your benefit, and use the Name Expression to override it when displayed to customer.  The Name Expression expects a string expression, so be sure to enclose any text in double quotes.

Tags :  MinimumCharge
Comments (0)
Only Allow Shipping to a Certain Country- Wednesday, May 16, 2012

Only allow shipping if the destination country is Mexico:

Create this record with a low "Order" (e.g. 10) , so that it gets evaluated before any shipping Options.

Tags :  Country
Comments (0)
Fixed Rate when less than X kg, otherwise per kg rate- Wednesday, May 16, 2012

The last few posts have been fairly complex scenarios.  I'll be posting some more simple shipping examples...

The shipping computation we'll configure is:

If the total weight is less than 5 kg, then the shipping will be a flat rate of $20.00, 

and if the total weight is 5 kg or more, then there will be a shipping rate of $4.00 per kilo.



Note the Name Expression on the above option.  This is optional.  In this case, it allows you to show the actual weight in the Shipping Rate Name shown to the customer.  E.g.

    Shipping for 9.1 kg ($36.40)

You can also choose to use a Ceiling math function in the Rate Expression so that fractions of weight roll up to the next whole integer:

   Math.Ceiling([$TotalWeight]) * 4.00

Shipping for 9.1 kg ($40.00)

Comments (0)