Exclude Shipping Options from Carrier Plugins

(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
Leave your comment
:
thalia@myfootshop.com
Created on: 11/22/2013 3:21 PM
I am trying to exclude all but one of the 1st class options that are returned when I have 1st class enabled in my USPS carrier plugin settings.

I do not know how to reference each of the service options in order to include/exclude them. Where are their actual names defined, and an example of what the expression would look like if I didn't want to exclude any of the other returned service options associated with First Class?

For example, I only want the 2 Priority options, and the First Class PARCEL option to appear, but this is what I currently see:

USPS Priority Mail Express 1-Day™ ($25.25)
USPS Priority Mail 2-Day™ ($6.00)
USPS First-Class Mail® Parcel ($2.07)
USPS First-Class Mail® Letter ($0.66)
USPS First-Class Mail® Postcards ($0.33)
support@nopTools.com
Created on: 11/26/2013 11:18 PM
The USPS options are configured in the USPS plugin.  Admin > Configuration > Shipping > Shipping Rate Calculation Methods >> Configure (link on USPS line)
http://admin-demo.nopcommerce.com/Admin/Shipping/ConfigureProvider?systemName=Shipping.USPS

You can select the ones you want, and unselect the ones you don't want.  It does not appear that you are asking about how to conditionally have them appear or not.  If you do, then you can configure an expression as per the above blog based on setting the Name Expression - if the Name Expression evaluates to blank "", then the option is suppressed.
thalia@myfootshop.com
Created on: 11/27/2013 12:58 PM
I guess I didn't make myself clear.
Yes, you can select which services to offer, but you can't select which individual services WITHIN First Class service that you want to appear.

You can just enable/disable First Class. Period.

When I do, post cards and letters are included, and I do not want them to appear...which is what I'm asking.

In fact, in the product description of this plugin, it clearly says that this can be done:
-------------------------------
Use other shipping methods
...
Exclude shipping options (e.g. USPS First Class returns 3 options: Letter, Postcard, and Package.  Exclude Letter & Postcard)
-------------------------------

So, HOW do I exclude Letter and Postcard options?
support@nopTools.com
Created on: 11/27/2013 5:32 PM

[$Name].Contains("Letter") or [$Name].Contains("Postcards")  ? "" : [$Name]
brankel@hotmail.com
Created on: 4/28/2014 10:39 PM
I'm still testing your plugin before I purchase it.  I'm slowly learning how to use it but I am stuck.  I have my site configured with three UPS Shipping options, Ground, Air, and 3-day select. I want to write an expression that hides UPS 2nd Day Air and UPS 3 Day Select from showing in the options when any item comes from category ID 18.

The following works when I click "Test" but when trying this during checkout, it still shows both options from UPS when I only want "Ground" to show.  What am I doing wrong?

10  Boolean ProductsGround Items.Any(Product.HasCategory(18))

20  Option GroundShipping true Shipping.UPS  [$Name].Contains("UPS 2nd Day Air") or [$Name].Contains("UPS 3 Day Select") ? "" : [$Name]  
support@nopTools.com
Created on: 4/29/2014 12:01 AM
It's very odd that it would show differently for you when in Test vs public store.  Are you using the same customer/cart?

In any case, I note two things:
1) you are not referencing [ProductsGround] in your expression; the way you have it now, it would always exclude regardless of there being products with category 18.

2) Remove the "UPS " prefix.  It's possible that the value returned by their API could have some symbols (c) or (tm).

Use this expression to deal with both above (note the parens ( ) around the OR part):

[ProductsGround] and ([$Name].Contains("2nd Day Air") or [$Name].Contains("3 Day Select")) ? "" : [$Name]  
sgeier@pagetechnology.com
Created on: 1/27/2018 5:22 PM
When I am trying to implement this I get the error: Expression=([$Name].Contains("Express") or [$Name].Contains("Standard")) ? "" : [$Name]; Error=Cannot convert type 'string' to 'decimal'

Option  

Free Shipping Ammo - Clear Shipping Methods  

ShippingAddress.Country.Name = "United States" and ShippingAddress.StateProvince.Abbreviation <> "AK" and ShippingAddress.StateProvince.Abbreviation <> "HI" and Items.Where([@hasFreeGroundShipping]).count() > 0 and Items.Where([@markedAmmo]).count() > 0  

Shipping.Fedex  

([$Name].Contains("Express") or [$Name].Contains("Standard")) ? "" : [$Name]

Note: I know the expression works as I am using it in another rule successfully. We are still in version 2.65.
cindya@sancusdesign.com
Created on: 12/4/2018 10:14 PM
Hi, we are testing the plugin as a trial and I am a bit lost here.  We have two stores:
Store #1 is using shipping options by weight. We are adding one category of products that requires flat rate only, so all other options need to be excluded.  I am not following how to do that.

Store #2 is using all flat rate.  We want to 2 flat rates that are based on category, so product  A is $4.00, Product B is $13.00.   I set up the plugin for this, but don't know how to exclude everything else.  I understand we have to disable the UPS, USPS, plugins, but we still need them for Store #1 products that are shipped by weight.

Hopefully this all makes sense.

Can you please provide examples of how to set up Shipping Director under both these stores.  If it works, we will definitely purchase for two domains.

Thank you.
support@nopTools.com
Created on: 12/4/2018 11:19 PM
I'm going to paraphrase your requirements (and include some info you posted in the nopCommerce forums ;)
Store #1 is using shipping options by weight [UPS, USPS]
[but] one category of products [] requires flat rate only, so all other options need to be excluded.
[if multiple types of products are in cart, e.g. jewelry is by weight and a travel mug is flat rate, the by weight rate should be combined with the flat rate, for one total rate.]
  
Store #2 is using all flat rate.  [] 2 flat rates that are based on category, [exclude everything else / e.g. UPS]
so product A is $4.00, Product B is $13.00.   [if both are in cart, add the rates - i.e. together the shipping is $17.00]

Unlike what's described above in the blog, excluding certain methods from carrier, it seems that you want to exclude the carrier altogether for store #2.  And for store #1, you want to surcharge the carrier rates with an additional  flat rate if the cart also contains an item from a given category...

Here's a solution:

10
Integer
QtyTravelMugs
Items.Where(Product.HasParentCategory("Travel Mugs")).Sum(Quantity)

15
Decimal
RateTravelMugs
[QtyTravelMugs] * 13.00


20
Integer
QtyJewelry
Items.Where(Product.HasParentCategory("Jewelry")).Sum(Quantity)

25
Decimal
RateJewelry
[QtyJewelry] * 4.00

  
100
OptionExit
Shipping
CurrentStoreId = 1 and Items.All(Product.HasCategory("Travel Mugs"))
[RateTravelMugs]

110
OptionExit
Shipping
CurrentStoreId = 1
Shipping.UPS
[RateTravelMugs]     {this goes in Surcharge Expression field. i.e. the TravelMugs rate is added to UPS rates}

(if we got here, then it must be store # 2, so 'true' is OK for the condition expression)
200
Option
Shipping
true
[RateTravelMugs] + [RateJewelry]


If you need more info, contact us at support at noptools.com