Blog

RSS
A Product's Additional Shipping Charge is the only charge- Saturday, June 10, 2017


Let's say you've assigned Products their own "Additional shipping charge" and you want that charge to be the only charge for those products, and for any other prodcucts in the cart you want to calculate shipping using some 'standard' provider (like FedEx, or By Weight, etc.).    Shipping Director's Packing with Exclude Expression can handle it.  Here's the general idea:

EvalType

Name

Expression

Rate Expression

Description Expression
(Exclude)

Packing

Exclude Addl Charge items

Items.Any(Product.AdditionalShippingCharge > 0)

Packing.FirstFitSingleBox

Product.AdditionalShippingCharge > 0

Option

Shipping

true

Shipping.ByTotal

 

Using Packing's Exclude Expression removes those items from "the cart", so that the Shipping.ByWeight provider does not see them.

Note, that nopCommerce will always add Product.AdditionalShippingCharge AFTER the shipping providers return their methods/rates.  Also, be aware the the AdditionalShippingCharge is per quantity - E.g. if quantity of an item in cart is "3", then 3 times the addl charge is added.  (You can read more about that in this blog about "Product Additional Shipping Charges apply only once to the cart item regardless of the Quantity".

Comments (1)
Per Item Shipping by Zone and Category- Saturday, June 10, 2017
Calculation Per item shipping charges can be a bit tricky.  Consider that the complexity is that the cart can contain multiple items in different categories, and thus you need to have some kind of "per item" shipping calculation that group items by category.  There are two ways to do this with Shipping Director.

1) "Configure" in Shipping Director all the zone/rate calculations.  See this basic example about per item shipping


Here's some basic configuration using an "if then else" operator " ? :" to calculate Zone from Zip (postal code) - e.g.

Integer       Zone      Zip <= "1000" ? 1 : Zip < "2000" ? 2 : Zip < "3000" ? 3 : 4

then for each category either count the items, or sum the Quantity - e.g.

Decimal     Category1Count         Items.Where(Product.HasCategory("Category1")).Sum(Quantity)
Decimal     Category2Count         Items.Where(Product.HasCategory("Category2")).Sum(Quantity)
...

then calculate total rate by summing individual category rates by zone:

Decimal     Rate            0
Decimal     Rate            [Rate] + Category1Count * ([Zone] = 1 ? 5.00 : [Zone] = 2 ? 7.00 : [Zone] = 3 ? 9.00 : 10.00)
Decimal     Rate            [Rate] + Category2Count * ([Zone] = 1 ? 6.00 : [Zone] = 2 ? 8.00 : [Zone] = 3 ? 11.00 : 13.00)
...
Option       Shipping       true         [Rate]

The above example does not take into account any consideration for different rates for the first item vs. additional items.  For example, if the first item ships for $5.00 and each additional item ships for $2.00.   First, you need to consider if the calculation is specific for Product quantity or Category quantity (as per above example "counts").


2)  If you have so many Zones and Categories and you frequently need to change rates, then you may want to set up some tables in SQL Server, and a custom Stored Procedure can be written to do the calculation.  Here's a blog with an example using Zone/Weight, but note it's 'total cart weight' and doing individual categories would need different coding.  Note that Shipping Director does not have a GUI to maintain the lookup tables.  You (or your IT person) would need some time of tool (like SSMS) to maintain (insert or update) rates.  (In the future, we plan on adding a feature to SD to allow uploading such data into SQL tables.)

(Also, note: if your products have Product Attributes that need special shipping rate calculations / additional $, then it becomes more complex.  And, you may want to 'validate' the postal code, because it is just a free form text field.)

Tags :  RatePerItem
Comments (0)
Product Additional Shipping Charges apply only once to the cart item regardless of the Quantity- Saturday, May 6, 2017

nopCommerce always adds the Additional Shipping Charges after getting rates from the Shipping Providers.  I've blogged about how to use the Shipping Director to conditionally negate the Additional Shipping Charges.  It's easily done by using the Surcharge Expression as described here:

https://www.noptools.com/blog/11/remove-additional-shipping-charge-for-in-store-pickup

In this example, we’ll show how to have the Product Additional Shipping Charge apply only once to the cart item regardless of the Quantity entered by customer.

The ‘magic’ is to calculate the Product Additional Shipping Charges that would be added by nopCommerce and use the Surcharge Expression to negate them.  But in this case, to also calculate, and add back, those charges as if only one charge per item rather than one charge per Quantity.

Order

Type

Name

Expression

RateExpression

SurchargeExpression

10

Decimal

TotalAddlShippingCharge

Items.Where(Product.AdditionalShippingCharge > 0).Sum(Quantity * Product.AdditionalShippingCharge)

 

 

20

Decimal

PerItemAddlShippingCharge

Items.Where(Product.AdditionalShippingCharge > 0).Sum( Product.AdditionalShippingCharge)

 

 

100

Option

Shipping By Total

true

Shipping.ByTotal

-[TotalAddlShippingCharge] + [PerItemAddlShippingCharge]

You can download the configuration import file by clicking on this link ShippingDirector (By Total - Only One Product Addl Ship Charge per item).txt

Comments (0)
Option record's RateExpression supports SQL statement- Friday, November 27, 2015

In the Rate Expression of an Option (or OptionExit) type record, put in a SQL statement (or call a stored procedure).  It must return a table of Shipping Options - columns: Name VARCHAR, Description VARCHAR, Rate Decimal. 

For example, if you can set up Warehouses as locations for local Pickup:

SELECT w.Name,
       Address1
         + case when isnull(address2,'') = '' then '' else ' ' + Address2 end
         + ', ' + a.City + ', ' + s.Abbreviation + ' ' + ZipPostalCode  as Description,
       0.00 as Rate
  FROM Warehouse w
  JOIN Address a ON a.Id = w.AddressId
  JOIN StateProvince s on s.Id = a.StateProvinceId;

Type

Name

Expression

Rate Expression

Option

Warehouses for local pickup

true

SELECT w.Name, Address1 + case when isnull(address2,'') = '' then '' else ' ' + Address2 end + ', ' + a.City + ', ' + s.Abbreviation + ' ' + ZipPostalCode as Description, 0.00 as Rate FROM Warehouse w JOIN Address a ON a.Id = w.AddressId JOIN StateProvince s on s.Id = a.StateProvinceId;

The customer sees: 

3

Shipping method

  •  
    10 Main St, Farmingdale, NY 11735
  •  
  •  
    15 Park Ave, New York, NY 10021

Tags :  SQL
Comments (0)
"Saturday Delivery" method, but only show it on Friday- Sunday, October 11, 2015


You can use the day of week in your expressions.  For example, if you need to have Saturday Delivery, but only want to show that option on Friday, here's an example using Shipping By Weight. You can create another Shipping Method (e.g.  "Saturday Delivery"), and Shipping Director can exclude it conditionally (when not Fri) by using Name Expression.

The Name Expression would look like this (assuming your method name has the word "Saturday" in it - e.g.  "Saturday Delivery") :

    [$Name].Contains("Saturday") and DateTime.Today.ToString("ddd") <> "Fri" ? "" : [$Name]

Note, though, that you may also want to check the Time too (because if they place the order Fri at 11pm, you may not be able to get it there Sat ;)

Another example would be to show an additional set of shipping options with a surcharge.  For example, if you use Shipping By Weight, you can call it twice with the Option type. The 2nd call would check if the country is Belgium and the day of the week is Thu or Fri; it would have a Surcharge Expression, in this case just a fixed 2.50:

Order

Type

Name

Expression

Rate Expression

Surcharge Expression

110

Option

By Weight

true

Shipping.ByWeight

 

100

Boolean

AllowSaturday

Country = "BE" and "Thu,Fri".Contains(DateTime.Today.ToString("ddd"))

 

 

120

Option

By Weight Sat

[AllowSaturday]

Shipping.ByWeight

2.50

Tags :  Day-of-week
Comments (0)
Prevent checkout if the cart has products that don't all have the same vendor- Thursday, October 1, 2015

There are a few blogs that show how to use ErrorExit to prevent the customer from checking out; like this one.

Here's how to prevent checkout if the cart has products that don't all have the same vendor:


 ErrorExit        Items.Select(Product.VendorId).Distinct().Count() > 1                  "Your cart contains products that don't all have the same vendor"

Tags :  Vendor
Comments (0)
Payment Director - Charge a Fee for Rentals late in the day- Tuesday, September 22, 2015

Here's one way to charge a fee to "rentals made after 1pm of a rental starting today" 

Note that RentalStartDateUtc  has Utc suffix, but since current nopC only supports Date and not time for rentals, I don't know if it has any impact - my test shows that when I entered item in cart with today's date, that is what was stored in the database, even though I'm UTC - 5 which would have been UTC next day since I entered it at 9pm.   (There is no DateTime.UtcToday, but DateTime.UtcNow.Date should work in its place if you prefer to use  compare.)   Also, below I use DateTime.Now.Hour and not DateTime.UtcNow.Hour, because I'm comparing the current hour to see if it's later than 1pm my time (13:00) - but this time will also depend on the time of your server.

Order

Type

Name

Expression

Fee Expression

105

Boolean

ChargeAFee

DateTime.Now.Hour > 13 and Items.Any(Product.IsRental and RentalStartDateUtc = DateTime.Today)

 

110

Option

Payments.AuthorizeNet

Show

[ChargeAFee] ? 2 : 0

 

Adjust 13 to the hour of the day you need.  Adjust the "2" in [ChargeFee] ? 2 : 0 to be the fee you want to charge.

You need to enter a similar  line & fee expression for each payment method you've enabled.

 

Tags :  PD-FeeDay-of-week
Comments (0)
Payment Director and PayPal Express- Tuesday, September 22, 2015

PayPal Express is a "button" payment method, which means it appears as a button on the shopping cart page.  That said, your Payment Director expression won't be able to make use of ShippingAddress attributes, because a shipping address does not get selected by the customer until later in the checkout flow.  

So, for example, if you wanted to only allow PayPal Express for US customers, you can't use ShippingAddress.Country.TwoLetterIsoCode .  Instead, one workaround is to require a Country be entered during customer registration.   "CountryId" is an attribute stored with the Customer. 

Here's what it should look like in Payment Director grid: 

Option

Payments.PayPalExpressCheckout

Customer.GetAttribute("CountryId") = "1"

Note the "1".  That's the CountryId.  You'll need to verify (or change) the "1" for country of your choice. "US" is typically "1", but it could vary depending on your nopCommerce configuration.  To verify/get the Id, Edit your country in Admin > Configuration > Countries, and check the browser's address bar.  Check the # on the end of the url  - e.g.  /Admin/Country/Edit/1

Comments (0)
USPS made a change : "Origin ZIP Code required for Priority Mail International to Canada"- Monday, June 8, 2015

It was reported in the nopCommerce forums that USPS International Shipping stopped working

In fact, only international shipping to Canada broke, because...

USPS made a change : "Origin ZIP Code required for Priority Mail International to Canada"
May 31, 2015 USPS Web Tools will be implementing modifications and additional features to the U.S. Postal Service APIs. The following changes may especially impact shipping systems:

- Origin ZIP Code required for Priority Mail International to Canada
- Modified special services
- Modified service IDs
- Modified available mail classes for Merchandise Return Services

This link is a .zip file containing the fixed USPS plugins for nopCommerce versions 3.30, 3.40, and 3.50

You really only need to replace the file Nop.Plugin.Shipping.USPS.dll but I've included everything - source code, and no source versions.   Copy .dll from the zip file's \USPS Shipping\nopCommerce 3.xx\Shipping.USPS folder to your \Plugins\Shipping.USPS folder.  After you copy it to your plugin folder, be sure to "Reload list of plugins", or restart your web app.

Comments (0)
If customer enters an invalid zip code, they only see "In-Store Pickup"- Thursday, October 16, 2014

I was asked ...

Today, I had a customer who had a customer call saying that the only shipping option they were seeing was In-Store pickup. After a little debugging, they figured out that she was inputting an invalid Zip code and so it was just showing in-store pickup.

My question is this:
Can an expression be written that will catch the invalid zip code error returned from USPS and print a message to the screen saying "Sorry,  it appears you've input an invalid zip code, so USPS was unable to calculate rates for their services. Please go back and correct the error."

NopCommerce has the option such that it will "return valid options if there are any".  So, first, set that option to False

Admin > Configuration > Settings > All Settings >> column filter the Name column for

shippingsettings.returnvalidoptionsifthereareany

Edit, set to False, and Update

The customer will then get this error message when an invalid zip code is entered.
  • USPS Error returned: Error Desc: Please enter a valid ZIP Code for the recipient. USPS Help Context: .

(Note, that the USPS plugin only sends 5 digit zip to USPS)

However, if you want to do some up front validations (and return friendlier error messages), then you can use ErrorExit in Shipping Director:  Read these other blogs about validations



You can download sample validations that you can then import into Shipping Director (do NOT select Delete option).  They have large order line numbers, so they will append to the end of your config.  You should renumber the ones you like with low order line numbers, so that they appear before any Option lines, and delete the ones you don't need.

The zip validations just check the formats.  They don't ensure that they are actual zip codes.  Only the USPS would do that.
I've been considering writing a plugin for full address validation using smartystreets, but there does not appear to be a demand (at least I don't see any forum posts asking for it).  If interested, let me know :)
Tags :  Validate
Comments (0)
1 2 3 4 5 Next ... Last