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 BoxBut 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] : "" |