Shipping Director - Sample Expressions

Expressions are created by referencing variables that you define, or the underlying attributes of the Shopping Cart.  Expressions are built using variables and properties of the shipping request (e.g. Customer, Items collection, etc.).   Simple expressions just use typical operators like "+", "-", "and", "or", etc.  Queries use a variant of Linq syntax (no lambda symbol "=>" required).  Queries are applied to collections to "extract" the items in the collection that meet the query criteria.

When variable names are used in expressions, they must be enclosed in square brackets - e.g. [ZipCode3].  Variables can be boolean, string, decimal, integer, etc.  Query expressions and Attributes are referenced without enclosing brackets.  Most attributes are "objects" that themselves contain other attributes.  Some attributes are collections (lists), that can contain 0 or more other objects.  Developers having a familiarity with the nopCommerce shopping cart object and linq syntax certainly have an advantage when creating expressions, but the syntax is not that hard to grasp given some examples, and future blogs will discuss the cart,, and provide more examples.  Here are some examples that may commonly be used:

Only 2 free items allowed

Items.Where(ProductVariant.Price = 0).Sum(Quantity) > 2

Has Role with Free Shipping

Customer.CustomerRoles.Any(Name = "FreeShipping")  (* see below update)

Affiliated to XYZ

Customer.AffiliateId = 1

Placed 2 or more orders in past 30 days

Customer.Orders.Where((DateTime.Now - CreatedOnUtc).TotalDays <= 30).Count() >= 2


[$TotalWeight] > 150


EXECUTE ShippingZone_LookupRate @p1, @p2; [ZipCode3], [$TotalWeight]

(Update: 12/12/2012 - see this for more about Variable and Expression Data Types )

(Update: 12/20/2021 - Customer.CustomerRoles won't work in 4.x and above.   Use Customer.GetCustomerRoles() to get the full collection, or to check a specific role, use helper property  Customer.IsInRole("role system name") )

Leave your comment
Created on: 12/14/2012 7:00 PM
Do you have any helping manual like nopCommerce.
It would be really helpful.

I am using [Shipping by weight] calculator for shipping  and I want to set a discount (i.e 2.99$) on sipping if customer  order worth 20$.
Is that possible.

Created on: 12/15/2012 12:00 AM
We are working on a user manual.  We've been using the blogs as an instructional tool.  It's been well received because there are an infinite number of possible shipping scenarios - everybody's are a bit different.

As for setting a shipping discount based on cart amount, we've just blogged about it here