Blog posts of '2014' 'June'

RSS
Evaluate customer's prior orders- Friday, June 20, 2014

The GetOrders() customer extension method has been around since Shipping Director 1.13 (for nopCommerce 3.10), but we've never blogged about it.  Here's a couple of possible scenarios  (you may need to put the expression in different configuration fields depending on your needs).

Example: Prior orders containing 2 or more products from a particular vendor:

  Customer.GetOrders().Count(OrderItems.Any(Product.VendorId = 1)) > 2

Example: 10% discount (by using Surcharge Expression) if any (paid) orders in the last 45 days

    Integer PaymentStatus_Paid 30
    Customer.GetOrders().Any(CreatedOnUtc > DateTime.UtcNow.AddDays(-45) and PaymentStatusId = [PaymentStatus_Paid]) ? -[$Rate]*0.10 : 0

Example: Free Shipping for Add On Order (i.e. there's a prior order that's not yet shipped)

    Integer ShippingStatus_NotYetShipped  20
    OptionExit   Free Shipping for Add On Order    Customer.GetOrders().Any(ShippingStatusId = [ShippingStatus_NotYetShipped])     0

Tags :  Expressions
Comments (1)
Example - Free ground shipping for Coupon Code, but want the customer to still have the option to pick the quicker options from Fedex at the regular price.- Monday, June 16, 2014

Update 2023 - see Check if the customer used a coupon code, to use Customer.HasDiscountCouponCode()

You can get the customer entered Coupon Code using:  Customer.GetAttribute("DiscountCouponCode").   In an Option record's surcharge expression, use the built-in [$Name] variable to get the carrier's shipping method name and the built in [$Rate] variable to get the method's rate.  In Surcharge Expression negate the rate if the shipping option name contains the word “Ground”.

Update 2017 - see below if using version 3.90 or later, and don't add this DiscountCouponCode variable!

Update 2017-12 - nopCommerce now supports multiple coupon codes applied to the cart.  So, they now store XML in the attribute. But, also, the attribute can be the null string, and you cannot call methods (like ToLower() ) on null strings.  This is how you can create the variable:

 (Customer.GetAttribute("DiscountCouponCode") + ".").ToLower()

Or just test the condition directly:

   (Customer.GetAttribute("DiscountCouponCode") + ".").ToLower().Contains("""couponcode""")

Note the extra quotes "" on both sides of string.  The XML attribute is quoted.  In the future, we'll create a collection property to make this easier.

Update 2018-07 - Smart tip - If using a unpublished category, you can create a new product template that shows the free shipping tag

---end of update---

Add new 'Shipping Director' record - a variable to get the customer entered coupon code.  Use ' + "." ' at the end because when the customer does not enter a code, then [DiscountCouponCode] will be null, so we need to check that before applying ToLower() below, or easier is just to append the ".". *

Type

String

Name

DiscountCouponCode

Expression

Customer.GetAttribute("DiscountCouponCode") + "."

Add new 'Shipping Director' record - a variable to calculate when free ground.  For example, if the Coupon Code is "freeground." (with "." at the end):

Type

Boolean

Name

FreeGround

Expression

[DiscountCouponCode].ToLower() = "freeground."



Add new 'Shipping Director' record - an Option record to get the rate.  Use a negative surcharge.

Type

Option

Name

FedEx Free ground shipping with Coupon

Expression

true

Rate Expression

Shipping.FedEx

Surcharge Expression

[FreeGround] and [$Name].Contains("Ground") ? -[$Rate] : 0

Name Expression

[FreeGround] and [$Name].Contains("Ground") ? "Free Ground Shipping" : [$Name]

Description Expression

 



If you have many different coupon codes, then give them something common so that you can easily detect them.   For example, if you have codes "ground1", "ground2", etc., then the variable's expression could be [DiscountCouponCode].ToLower().StartsWith("ground").  Or, you could use ... .Contains("ground").   

(*We could have used ' + "" ' (empty string) above rather than ".", but all strings contain and start with the empty string)

(update 7/26/2014:

For 2.65, replace    

   Customer.GetAttribute("DiscountCouponCode")

with just

      Customer.DiscountCouponCode 

(update - 3.90 allows "Multiple discount codes", so the above will The syntax error is due to the embedded quotes in the XML in the string variable.  So, don't use a variable.  use this:

Customer.GetAttribute("DiscountCouponCode").Contains("""freeship""")

 

The quoted quotes  ' "" ' replaces using the "." before to make sure the match is not a substring.  The XML has those embedded quotes to match exactly - i.e.  <CouponCode Code="freeground" /> ). 

Add new 'Shipping Director' record - a variable to calculate when free ground.  For example, if the Coupon Code is "freeground.":

Type

Boolean

Name

FreeGround

Expression

Customer.GetAttribute("DiscountCouponCode").Contains("""freeship""")

Tags :  FreeShipping
Comments (5)