Blog posts tagged with 'Expressions'

RSS
Evaluate customer's prior orders- Friday, June 20, 2014

The GetOrders() customer extension method has been around since Shipping Director 1.13 (for nopCommerce 3.10), but we've never blogged about it.  Here's a couple of possible scenarios  (you may need to put the expression in different configuration fields depending on your needs).

Example: Prior orders containing 2 or more products from a particular vendor:

  Customer.GetOrders().Count(OrderItems.Any(Product.VendorId = 1)) > 2

Example: 10% discount (by using Surcharge Expression) if any (paid) orders in the last 45 days

    Integer PaymentStatus_Paid 30
    Customer.GetOrders().Any(CreatedOnUtc > DateTime.UtcNow.AddDays(-45) and PaymentStatusId = [PaymentStatus_Paid]) ? -[$Rate]*0.10 : 0

Example: Free Shipping for Add On Order (i.e. there's a prior order that's not yet shipped)

    Integer ShippingStatus_NotYetShipped  20
    OptionExit   Free Shipping for Add On Order    Customer.GetOrders().Any(ShippingStatusId = [ShippingStatus_NotYetShipped])     0

Tags :  Expressions
Comments (0)
Shipping Director - Variable and Expression Data Types- Monday, September 3, 2012

Be sure your expression is of the correct type whether assigned to a variable, or used in one of the Expression fields of a record.  Here are the types for the various Expression Fields:

Record/ExpressionName

Data Type

Description

Option and OptionExit

 

 

Expression

Boolean

When evaluates to true, the Option is presented to customer

Rate Expression

Decimal

The calculated Rate + Surcharge appears to customer as the rate

Surcharge Expression

Decimal

 

Name Expression

String

If present, will override the record Name displayed to customer

Description Expression

String

If present, the description appears under the Name/Rate line

 

Error and ErrorExit

 

 

Expression

Boolean

When evaluates to true, the Error message is presented to customer

Description Expression

String

Required.  The description appears under the Name/Rate line

 

Packing

 

See the Packing blogs

Expression

Boolean

When evaluates to true, the packing is performed

Packing Method

literal

E.g. Packing.FirstFitSingleBox  .

Requires Own Package Expression

Boolean

Evaluated for each item

Sender Expression

Boolean

Evaluated for each item

Exclude Item Expression

Boolean

Evaluated for each item

 

Reference

 

See the Reference Type blog

Expression

literal

A reference is a type of variable that is really just a shortcut.

 

 

Notes

 

Booleans

You can use literals 'true' and 'false'.   (lowercase, no quotes)

Strings

Be sure to put literals in double quotes.
To put a double quote in your literal, use two double quotes.
If using String.Format(), beware of localization.

Decimals, Doubles, Singles

Literals must include a decimal point "." regardless of localization
If using e.g. Decimal.Parse(), beware of localization.

DateTimes

Construct literals using DateTime() - e.g. DateTime(2010,8,9).  If using DateTime.Parse(dateString), beware of localization parsing.

Rate and Surcharge Expression

Numeric only.  Do not include any leading currency symbol.

Comments (0)
Shipping Director - Sample Expressions- Saturday, December 3, 2011

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")

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

IsOverweight2

[$TotalWeight] > 150

ZipCode3
ZoneRate

ShippingAddress.ZipPostalCode.Substring(0,3)
EXECUTE ShippingZone_LookupRate @p1, @p2; [ZipCode3], [$TotalWeight]

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

Comments (2)