It’s valuable to pack items in separate boxes to calculate rates per box (package), and using the Package record type’s Sender Expression is one way to do it. The Sender Expression calculates a Sender Identifier on a package, and the real power of using Sender Expression when packing is to override the default sending location (ZipCode & Country). NopCommerce has defined Ship From fields in the shipping rate request, and Shipping Director supports them. In Shipping Director, the Ship From fields can be set up when packing by using the Sender Expression; when the special tags “ZipCode=” and “Country=” are seen in the string result of the Sender Expression, then when passing packages to other shipping plugins, the tag values are used to set the Ship From fields. The tags are of the form “tag=value;” – the value is everything between the “=” and the terminating “;”. For example, “ZipCode=10021;Country=US;”.
By default, when a Sender identifier is seen on the first package, then the Shipping Rate Request type is “One Request per Sender” - i.e. $ShippingRateRequest=OneRequestPerSender. This means that all the packages with the same sender identifier are sent in a single request to the other shipping plugin. If there are multiple sender identifiers, then multiple requests are made. Then, the rates for the same shipping option name (e.g. “FedEx Ground”) are summed together.
The above Sender Expression “ZipCode=10021;Country=US;” illustrates that the expression is of String type, but isn’t a very useful example. In the real world, you need some way of calculating the Ship From location based on some data in the system. In the below example, two “warehouse” Categories have been configured with Published not checked so that the Categories do not appear to the customer. The Names of the categories have in them the Ship From tags as described above:
Warehouse 1:ZipCode=48126;Country=US;
Warehouse 2: ZipCode=11735;Country=US;
Then, Products have been assigned to the Categories.
Here’s what the Shipping Director records look like – we use Reference types to reference the product’s categories that have “ZipCode” in the name. The ‘sender’ reference will evaluate using a condition (the ternary “ ? : “ operator) - If a product is not in a “warehouse” category, then the expression evaluates to “Main”, and since “Main” does not have the tags in it, the plugin’s own configured ship from information will be used. - If a product is in a “warehouse” category, then the expression evaluates to the Name of the Category which has the Ship From tags in it.
Order | Type | Name | Expression | Rate Expression | Name Expression |
100 | Reference | warehouseCategories | ProductVariant.Product.ProductCategories .FirstOrDefault(Category.Name.Contains("ZipCode=")) |
|
|
110 | Reference | sender | [@warehouseCategories] = null ? "Main" : [@warehouseCategories].Category.Name |
|
|
120 | Packing | Pack By Warehouse | true | Packing.FirstFitSingleBox | [@sender] |
130 | OptionExit | FedEx | true | Shipping.Fedex |
|
Final Note: Not all of the external shipping rate methods built into nopCommerce allow for dynamically changing the Ship From address; some shipping plugins only use the fields specified on their configuration screens. The only shipping plugins that currently support overriding the shipping location are UPS, USPS, and the modified FedEx available on this site. [Update 2012-Sept: nopC 2.50 Fedex added this capability]