Blog

RSS
Shipping Director Setting - Sort Expression- Friday, March 8, 2013

Shipping Director introduced a Sort Expression in version 1.07.  The sort expression should evaluate to a string that represents an 'ordering clause'.  The ordering clause is one or more (comma separated) shipping option fields: Rate, Name, Description.  Each field can optionally be followed by ASC or DESC (the default is ASC = Ascending).   

Examples (Don't forget, it's a string Expression, so it's typically enclosed in double quotes):
"Rate ASC" 
"Name DESC" 

Example using ternary if-then-else  - If the cart weight <= 150, then sort by Rate, otherwise use the default sort. (The default is used when the expression results in blank string):
[$TotalWeight] <= 150 ? "Rate ASC" : "" 

In this example, we'd like to sort by Rate, but we want the "Pick up ..." option at the end, so sort by Name "prefix" then Rate:

"Name.SubstringBefore("" ""), Rate" 

FedEx Ground ($15.23) 
FedEx Express Saver ($51.51) 
FedEx Standard Overnight ($88.95) 
FedEx Priority Overnight ($108.35) 
Pick up at our warehouse ($0.00) 

Tags :  1.07Sort
Comments (0)
Exclude Shipping Methods - choose best one- Monday, January 7, 2013

NOTE:  This is an old blog.  nopCOmmerce no longer has ProductVariant.  Just use Product.  E.g.  (Product.Height * Product.Length * Product.Width)

In a previous blog, I showed how in SD you can calculate the shipping method name to show the customer using the Name Expression field on an Option record.  If the expression evaluates to a blank string, then SD will suppress the method.  Here's another example of how, 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 - or only show a single option.

In this example we'll offer the following USPS methods

USPS Priority Mail® Large Flat Rate Box
USPS Priority Mail® Medium Flat Rate Box
USPS Priority Mail® Small Flat Rate Box
USPS Priority Mail®

But we only want to show one - the best match based on the volume of items in the cart:

Order

Type

Name

Expression

Rate Expression

Name Expression

10

Reference

ItemVolume

(ProductVariant.Height * ProductVariant.Length * ProductVariant.Width)

 

 

20

Reference

CartVolume

Items.Sum([@ItemVolume] * Quantity)

 

 

30

Option

US Mail

true

Shipping.USPS

[$Name].Contains("Small") and [@CartVolume] <= 75 ? [$Name] : [$Name].Contains("Medium") and [@CartVolume] > 75 and [@CartVolume] <= 546 ? [$Name] :

[$Name].Contains("Large") and [@CartVolume] > 546 and [@CartVolume] <= 792 ? [$Name] :

[$Name] = "Priority Mail" and [@CartVolume] > 792 ? [$Name] : ""

Tags :  ExcludeOption
Comments (0)
Query with Extension Methods- Friday, January 4, 2013

(Note!!  This blog has been updated. Due to changes in nopCommerce, use just "Product", not "ProductVariant.Product".)

A little while back we introduced some new functions that you can use to query your cart when creating complex shipping scenarios.  These are also available in Payment Director.  Here's some more details:

You can check if a product is in a particular category (or any category matching a pattern):

Product.HasCategory(categoryName)

Product.HasCategory(categoryId)

Product.HasCategoryMatch(regular_expression)

For example, you can check if there are any items in the cart that have a category that includes the word “Brushes”:

Items.Any(Product.HasCategoryMatch("Brushes"))

You can test if an item has a specific attribute/value (e.g. “Color”,”Blue”), or the specific attribute with any value (“Color”):

HasAttributeValue(attributeName, valueName)

HasAttributeValue(attributeName)

For example, you can get the quantity of items in cart that have the Vanilla scent:

Items.Where(HasAttribute("Scent","Vanilla")).Sum(Quantity)

 You can use the value id (integer) if you prefer (in case you change the name)

HasAttributeValue(valueId)

You can get a list of attribute values that the customer has applied to a cart item:

Item.GetAttributeValues(attributeName, valueSeparator)

Item.GetAttributeValues(attributeName)  // value separator defaults to “,”

Of course it does not need to be a list – for example, if you have a “Size” attribute, then you can just get the value the customer entered for the Size.  For example, if you have many products in the cart with a Size attribute, you can calculate a shipping rate based on the size values – let’s say you want the rate to be on a per item basis, for each ($3.33 * Size * Quantity)

Items.Where(HasAttributeValue("Size")) .Sum(3.33 * Decimal.Parse(GetAttributeValues("Size")) * Quantity)

(You can do date/time calculations too – e.g. … .Min(DateTime.Parse(GetAttributeValues("DeliveryDate")) )

Here’s an example of how the new methods make your expressions shorter and more readable:

We’ve blogged before about “Free Shipping over $X - unless there are any excluded items”.  We used a Reference type variable to shorten the query:

Order

Type

Name

Expression

Rate Expression

10

Reference

categories

Product.ProductCategories

 

20

Reference

hasExcludeFromFreeOverX

[@categories].Any(Category.Name = "Exclude from Free Over X")

 

30

OptionExit

Free Shipping

[$SubTotalWithDiscounts] > 50 and !Items.Any([@hasExcludeFromFreeOverX])

0

40

Option

Standard

true

10

Here the same scenario as above with new HasCategory method -

Order

Type

Name

Expression

RateExpression

30

OptionExit

Free Shipping

[$SubTotalWithDiscounts] > 50 and !Items.Any(Product.HasCategory("Exclude from Free Over X"))

0

40

Option

Standard

true

10

Tags :  Functions
Comments (0)
Payment Director - Conditional payment methods- Friday, January 4, 2013

Payment Director allows a store owner to conditionally determine which payment methods to show the customer and to calculate additional payment fees.  Let’s start with the basics…

By default, all Payment Methods that are marked Active in admin > Configuration > Payment Methods are available to your customers.   Then, you set up Payment Director Option records as needed to hide options and calculate fees.   Each option’s Expression field is evaluated, and if ‘true’ (or ‘Show’) then the option will be presented to the customer.  If ‘false’ (or ‘Hide’), then the payment option is removed.  You can include an Option record for all your active payment methods, but if only some are conditional, then it’s easiest to just have Option records for those;  if an active payment method is not included in payment director, then it will automatically be shown to the customer.

Here are some example scenarios for offering payment methods, and their Option records/expressions:

Offer 'payment in store' method only when "In-Store Pickup" shipping method selected:

  Option  Payments.PayInStore         ShippingOptionName = "In-Store Pickup"

Local Deliveries can include CashOnDelivery:

  Option  Payments.CashOnDelivery Customer.ShippingAddress.ZipPostalCode.StartsWith("100")

Customers in role "Members" can include PurchaseOrder  (use the role's System Name):

  Option  Payments.PurchaseOrder      Customer.IsInCustomerRole("Members")

If an admin is impersonating a Customer, then use Manual Credit Card, otherwise the customer enters a credit card that Authorize.Net will process:

  Option  Payments.Manual             OriginalCustomerIfImpersonated != null

  Option  Payments.AuthorizeNet       OriginalCustomerIfImpersonated = null

Only offer Paypal if a FedEx shipping method was selected (a method that has tracking :)

  Option  Payments.PayPalStandard     ShippingOptionName.StartsWith("FedEx")

When entering records in the Add new 'Payment Director' record dialog, select Option in the Type  field drop down, and then the Payment Name field will present a drop down with only active payment methods.    


Then, enter an expression that evaluates to a Boolean (true or false) using one or more or more of the following operands:

  • Customer  (also has function IsInRole("systemname") )
  • ShippingAddress
  • ShippingOption  (.ShippingRateComputationMethodSystemName, .Rate, .Name, .Description)
  • ShippingOptionName
  • Items  (shopping cart items collection)
  • OriginalCustomerIfImpersonated (if != null then you are impersonating)
  • WorkingLanguage  (.Name, and .LanguageCulture)
  • WorkingCurrency (.Name, .CurrencyCode, .Rate, and .DisplayLocale)
  • TaxDisplayType  (IncludingTax = 0, ExcludingTax = 10)
  • CreditCardType  (e.g. for Authorize.NET :  "Visa", "MasterCard", "Discover", "Amex")
  • PurchaseOrderNumber
  • OrderTotalWithoutPaymentFee
  • FriendlyName

   (UPDATE: Here are more operands added added from 3.60 and on)

  • CurrentStoreId
  • CurrentStoreName
  • IsImpersonating (Boolean)
  • CustomValues  
    • (The nopC PaymentInfoCustomValues is a Dictionary of Key/Values set by other payment plugins.  This variable converts that dictionary to a string of "key:value|key:value|...".  You can use CustomValues.StringBetween("key:","|") to get a value.

Here are some examples:

WorkingLanguage.Name = "English"

WorkingLanguage.LanguageCulture = "en-US"

We'll introduce more features in the next blog :)


Comments (4)
Simple Free Shipping based on Role- Tuesday, December 18, 2012

Here's a very simple free shipping scenario with fixed rates.  Customers in the "Free Shipping" role get an option for free shipping ($0).  If not in that role, they see regular shipping.  (The leading "!" is the NOT operator.)   Everybody sees an option for "Fast Shipping".  

Order

Type

Name

Expression

Rate Expression

10

Option

Free Shipping

Customer.CustomerRoles.Any(Name = "Free Shipping")

0

20

Option

Regular Shipping

!Customer.CustomerRoles.Any(Name = "Free Shipping")

5

30

Option

Fast Shipping

true

10

 

So, if the customer is in the Free Shipping role, then she sees

Select shipping method
 Free Shipping ($0.00)
 Fast Shipping ($10.00)

And if she's not in that role she sees

Select shipping method
 Regular Shipping ($5.00)
 Fast Shipping ($10.00)

 

You can always add additional criteria.   If there are a lot of criteria, then create a variable to make it easier to read and maintain.  For example, let's also have additional criteria that the cart subtotal must be greater than $250

Order

Type

Name

Expression

Rate Expression

5

Boolean

HasFreeShipping

Customer.CustomerRoles.Any(Name = "Free Shipping") and [$SubTotalWithDiscounts] > 250

 

10

Option

Free Shipping

[HasFreeShipping]

0

20

Option

Regular Shipping

![HasFreeShipping]

5

30

Option

Fast Shipping

true

10

 


Tags :  FreeShipping
Comments (0)
Shipping Discount - use a negative surcharge- Friday, December 14, 2012

Similar to adding an insurance surchargeto the shipping rate, one can provide a discount just by making the surcharge a negative amount.

In this example, we’ll use the “Shipping by weight” calculator for shipping, and set a discount of $2.99 if the cart’s total is $20 or more.

Order

Type

Name

Expression

Rate Expression

Surcharge Expression

10

Option

Shipping

true

Shipping.ByWeight

([$SubTotalWithDiscounts] > 20) ? -2.99 : 0

As mentioned in prior blogs, the " ? : " is the ternary if-then-else operator.  These can be chained together if needed - for example to have discounts based on amount like this:

Subtotal greater than

Discount

100

7.99

50

5.99

20

2.99


Then the expression would look like

  ([$SubTotalWithDiscounts] > 100) ? -7.99 :  ([$SubTotalWithDiscounts] > 50) ? -5.99 :  ([$SubTotalWithDiscounts] > 20) ? -2.99 : 0

Tags :  Discount
Comments (0)
$5 Ground for orders over $50 except Alaska & Hawaii- Sunday, December 9, 2012

Another simple example of having a reduced Ground shipping rate

Basically, you use the Surcharge to negate the Ground Rate and then add $5.   In this example, we do it for USPS.  (Read more about using Surcharge to adjust the rate here)

Order

Type

Name

Expression

Rate Expression

Surcharge Expression

100

Packing

Pack

true

Packing.FirstFitSingleBox

 

110

Option

USPS

true

Shipping.USPS

([$SubTotalWithDiscounts] > 50) AND !("AK,HI".Contains([State]) AND [$Name].Contains("Ground")) ? -[$Rate] + 5 : 0

For the most accurate carrier rates, set your package size - see this blog about packing 

Tags :  FreeShipping
Comments (0)
Free Shipping over ‘X’ but still charge “Additional Shipping Charges”- Friday, December 7, 2012

If you want to use Free Shipping over ‘X’ but still charge “Additional Shipping Charges”, you can't use nopC’s built-in Admin > Configuration > Settings > Shipping >> "Free Shipping over 'X'" because it will ignore Additional Shipping Charges set on product variants.  The built-in Free Shipping over ‘X’ is always calculated last after shipping plugins return their options.   You can make this work with Shipping Director.  First, be sure to turn off "Free Shipping over 'X' " in admin.  (And as always when using SD, be sure that SD is the only Active rate calc method.)

This is really easy to do in SD – just calculate a 0 rate when the subtotal is over X!  Then, NopC will always add the additional shipping charges.  For example, here’s free shipping ($0) if the subtotal is more than $50:

Order

Type

Name

Expression

Rate Expression

10

OptionExit

Shipping

[$SubTotalWithDiscounts] >= 50

0

 

Of course, to make this complete, we'll add the second Option record to provide the rate if the cart does not meet the minimum amount.  And, to get a little fancy, we’ll use the Name Expression to show the customer “Free Shipping” if none of the items have any additional shipping charges, otherwise show “Shipping”:

Order

Type

Name

Expression

Rate Expression

Name Expression

10

OptionExit

Shipping

[$SubTotalWithDiscounts] >= 50

0

Items.Any(Product.AdditionalShippingCharge > 0) ? "Shipping" : "Free Shipping"

20

Option

Shipping

true

5

 

The second record above is a flat $5 rate, but you can of course use any type and number of additional methods/rates instead.

(P.S.  updated on July 2014 - ProductVariant -> Product)

Tags :  FreeShipping
Comments (0)
Shipping Director 1.07 available for NopCommerce 2.70 and 2.65- Wednesday, December 5, 2012
Here are the new features (I'll blog about them in more detail soon :)

SortExpression setting
  An optional sort of the options after all records have been processed.
  You can sort the options by any expression involving the shipping option fields: Rate, Name, Description

Query Expression support for First(), FirstOrDefault() and Select()
  e.g. Instead of saying Items.Where(...).First(), you can just say Items.First(...)

More Extension functions:
  String
    Split(separator)
    IsNumeric()
    IsInteger()
  ShoppingCartItem
    GetAttributeValues(attributeName, valueSeparator)
    GetAttributeValues(attributeName)
    HasAttributeValue(attributeName, valueName)
    HasAttributeValue(attributeName)
    HasAttributeValue(valueId)
  Product
    HasCategory(categoryName) 
    HasCategory(categoryId) 
    HasCategoryMatch(categoryNameRegex)
  
Test
  A store owner or developer can test their shipping calculations in the configuration page.  Testing here is not limited to the 5 transaction limit in trial/evaluation mode.
  You can select a customer to use test cart/address. (You must take that test customer through checkout process to the point of shipping address selection for that address to be stored with customer.)

Export tab delimited
Import tab delimited 
  Export/Import is not only great for backup and migrations, but also allows store owner to use different shipping scenarios with ease.
  Additionally, you can work in Excel where data entry can be easier for advanced users - just save as "Text (tab delimited)".

Tags :  1.07
Comments (0)
More about Packing- Friday, October 12, 2012

As per the blog that discusses Shipping Director built-in variables:

Rate Request Type - When Packaging, can be set by user to indicate the way that rate requests are made to other rate calculation methods when Packaging

Note that the Rate Request Types pertain when rate requests are made to other rate calculation methods (i.e. external methods like FedEx, UPS, etc.)

An external method like FedEx does its own "packing" - it will take the items in the cart, and "approximate" the number of packages based on dimensions/weight.   I've posted nopCommerce forum topics about how poor the algorithm is, and that's why I provide here at nopTools.com a modified version of the FedEx plugin(which was adopted by nopCommerce in version 2.50), and also created SD’s First Fit Single Box packing.

“OneRequestForAllPackages” is the default setting - it calls the external shipping plugin just once, and that plugin will do its own approximation of the number of packages.  That's when it's useful to use the new FedEx plugin which supports "PackByOneItemPerPackage" - then, the packing done by SD is respected by the FedEx plugin (no additional "approximate packing" is done).

With “OneRequestPerPackage”, SD will make multiple requests (one per package) to the external plugin, and aggregate the like named carrier options.   Liked named aggregation means that when FedEx returns a "Ground" rate for each separate request, they are added together, and the customer sees a single "Ground" option/rate.

“OneRequestPerSender” is used when using the Packing record type’s Sender Expression.  Here too, SD will make multiple requests (one per sender) to the external plugin, and again does liked named aggregation.  This blog about Packing by Warehouseprovides a good explanation.

Tags :  Packing
Comments (0)
 First ... Previous 2 3 4 5 6 Next ... Last