Blog

RSS
"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 (2)
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 :  VendorErrorExit
Comments (2)
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 (6)
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

(See this blog for additional information: Payment Director - checking the selected shipping method)

Comments (1)
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 (1)
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 (1)
Product Specific Fixed Rate for Quantity 1 plus Additional Shipping Charge for Quantity > 1- Wednesday, September 10, 2014
This example will allow you to maintain fixed rates at the product level using Admin Comment and also use the Product's Additional Shipping Charge.

Here's the magic formula :)

Items.Where(!String.IsNullOrWhiteSpace(Product.AdminComment)).Sum(Decimal.Parse(Product.AdminComment.SubstringBetween("Shipping:",";")) - Product.AdditionalShippingCharge)

It will parse out a Quantity 1 rate from Admin Comment, but be sure to use the format "Shipping" + ":" + rate + ";" :
      Shipping:nn.nn;
e.g.
       Shipping:12.99;
You can still use the rest of the Admin Comment as needed, either before, or after the Shipping:nn.nn;
You can change the format if you want - e.g.  livraison:nn.nn|   
But then be sure that you adjust the SubstringBetween expression.   (You can also use  Product.AdminComment.ToLower(), if you want to be safer :)

Caveat...

nopCommerce always adds the products' Additional Shipping Charges AFTER it gets the rate from a shipping plugin.  And, thus when you use the TEST button in Shipping Director, it will NOT show any additional charges.  If you use the Estimate Shipping in the public cart, then you will see the added charges.  Note the " - Product.AdditionalShippingCharge"  (minus) in the above expression.  That ensures that the Product.AdditionalShippingCharge does not apply to the first quantity of the product.  However, if you need also do some type of free shipping (e.g. free for domestic, and above per-item rates only for international), then you can't use the Product's Additional Shipping Charge, and must adjust the above scenario to also include the per-one rate as another element in the Admin Comment, and parse it out.

You can download the above configuration that you can then import into Shipping Director.
Tags :  RatePerItem
Comments (1)
Surcharge for Multiple Manufacturers- Sunday, August 31, 2014

A simple concept, with a tricky Count expression :)   We count distinct manufacturers for all the products in the cart.  The base shipping rate is 10.00 (includes up to one manufacturer), and then 3.00 extra surcharge for each manufacturer beyond the first.

Order

Type

Name

Expression

Rate Expression

Surcharge Expression

10

Integer

ManufacturerCount

Items.Select(Product.ProductManufacturers.Any() ? Product.ProductManufacturers.First().Manufacturer.Name : "").Distinct().Count() -1

 

 

20

Decimal

Surcharge

[ManufacturerCount] <= 1 ? 0 : [ManufacturerCount] * 3.00

 

 

100

Option

Shipping

true

10.00

[Surcharge]

Note, that in nopCommerce, Products can have more than one manufacturer, so we only get its first one.  The " -1 " compensates for those products that don't have any manufacturer.  (You can remove that if you want to also count for "the store").  If you want to surcharge even for the first manufacturer, then  change the Surcharge expression to just  [ManufacturerCount] * 3.00

You can download the above configuration that you can then import into Shipping Director.

Tags :  Manufacturer Fee
Comments (5)
Vendor can only ship to certain cities- Sunday, August 17, 2014

In this scenario, our requirement is to prevent shipping certain products to cities that a vendor does not ship to.  In SD, we check if both the shipping address city is not a permitted city and the cart contains an item for Vendor 1.  If this condition occurs, the ErrorExit line will cause the message like "Sorry, vendor1 does not deliver in your city" to appear to the customer, and prevent them from checking out. (The double quotes are required because Description Expression is an expression) 

Order

Type

Name

Expression

Description Expression

10

String

Vendor1 Cities

"Boston, Seattle, Las Vegas"

 

20

Boolean

Not a Vendor1 City

![Vendor1 Cities].Contains(ShippingAddress.City)

 

50

ErrorExit

Vendor1 Restriction

Items.Any(Product.VendorId = 1) and [Not a Vendor1 City]

"Sorry, vendor " + Items.First(Product.VendorId = 1).GetVendor().Name + " does not deliver in your city"

60

Option

 

 

 

  Order Line 60 would be whatever Option(s) you would want to offer.  However, if there are multiple items in the cart, the customer may wonder which product is sold by Vendor1 -so, we can let them know with a message like:  "Sorry, HP Pavilion Artist Edition DV2890NR 14.1-inch Laptop is sold by vendor1, whom does not deliver in your city" .  Use this expression instead:

"Sorry, " + Items.First(Product.VendorId = 1).Product.Name + " is sold by " + Items.First(Product.VendorId = 1).GetVendor().Name + ", whom does not deliver in your city"

You can download the above configuration that you can then import into Shipping Director.

Tags :  VendorRestricted
Comments (2)
Payment Director - Pay In Store available only for In-Store Pickup- Wednesday, July 23, 2014

Prior to nopCommerce 3.40,  "In-Store Pickup" was Shipping Method and the customer had to select or enter a shipping address just to be able to get to the Shipping Methods page (or tab in One-Page Checkout).   "In-Store Pickup" has now moved to the Shipping Address page.  You can enable this by checking the '"Pick Up in Store" enabled:' option on the Configuration > Settings > Shipping Settings page.

If you have several payment options including "Pay In Store", you may want to only show "Pay In Store" if the customer selected "In Store Pickup".  Payment Director can handle this:

Order

Type

Name

Expression

Fee Expression

20

Option

Payments.PayInStore

ShippingOptionName = "In-Store Pickup"

 

Be sure to activate all the Payment Methods you want to offer, and then you only need to enter the one conditional Option above.   Any Options not indicated in the Payment Director configuration page will always show unconditionaly.

If you have multiple languages, you can access the Locale Resource String for the In-Store Pickup Shipping Method Name.  (This is also the shipping name you see on the Order).  Use Payment Director's GetLocaleString method:

Order

Type

Name

Expression

Fee Expression

10

String

In-Store Pickup

GetLocaleString("Checkout.PickUpInStore.MethodName")

 

20

Option

Payments.PayInStore

ShippingOptionName = [In-Store Pickup]

 

Additionally, if you want to show a payment method, but have it disabled so that the customer can't select it, Payment Director includes replacements for the Checkout Views that allow you to do that.  They also will let you show replacement text for the Friendly Name.  For example, if you want to still show the "Pay In Store" option, but don't want to the customer to be able to select it, and also for the description, show "(Pay In Store available only for In-Store Pickup)" rather than just "Pay In Store", you can set up a localized resource string for the text, and set up a Condition in the Friendly Name Expression:










  

Order

Type

Name

Expression

Friendly Name Expression

10

String

In-Store Pickup

GetLocaleString("Checkout.PickUpInStore.MethodName")

 

20

String

In-Store Pickup Hint

GetLocaleString("Checkout.InStorePickupHint")

 

30

Boolean

In-Store Pickup Selected

ShippingOptionName = [In-Store Pickup]

 

20

Option

Payments.PayInStore

[In-Store Pickup Selected] ? Show : Disabled

[In-Store Pickup Selected] ? "" : [In-Store Pickup Hint]

You can download the above configuration that you can then import into Payment Director.  You will find the replacement Views in the \Views subfolder in the download .zip file.  (Read the Readme.txt file in the .zip file.)

Tags :  PD-Restrict
Comments (1)
Previous 1 2 3 4 5 Next ... Last