Documentation of Advanced Shipping 2.6.2 extension for Magento 1.x by Owebia

Introduction

Advanced Shipping is an extension for the e-commerce solution Magento.

Thanks to its syntax using JSON, this extension allows great flexibility in setting delivery charges.

This documentation explains how to create a configuration for one of the proposed shipping modes.

You want to do more with Advanced Shipping?

Discover our add-ons on Owebia Store.

Unlimited Carriers Add-on

Create as many carrier as you need with Advanced Shipping

Universal Setting Add-on

Hide or change price of methods regardless the shipping module

Use the index to find more easily something in the documentation.

Examples

Simple example: free shipping

{ "__auto__":{"label":"Free shipping","fees": 0} }

Fees related to the destination

{ "__auto__":{"label":"France, Germany, Switzerland, Spain, Italy","shipto":"FR,DE,CH,ES,IT","fees":10}, "__auto__":{"label":"France except Corsica","shipto":"FR-(2A,2B)","fees":10}, "__auto__":{"label":"Corsica","shipto":"FR(2A,2B)","fees":10}, "__auto__":{"label":"Worldwide except Germany and Corsica","shipto":"* - ( DE, FR(2A,2B) )","fees":10} }

Use the wildcard character * or regular expressions

{ "__auto__":{"label":"Wildcard character allowing postal codes beginning with 25","shipto":"FR(25*)","fees":10}, "__auto__":{"label":"Regular expressions allowing postal codes beginning with 'PO', 'po', 'Po' or 'pO'","shipto":"GB(/^PO.*$/i)","fees":10} }

Block delivery to France but with a postal code for DOM/TOM

With the following regular expression, you block the postal codes that starts with 97 or 98 (with or without interspersed zeros and spaces).

{ "__auto__":{"label":"Regular Expression refusing postal codes beginning with 97 and 98","shipto":"FR-(/^[0\\s]*9\\s*[78].*/)","fees":10} }

Using shortcuts address_filter

{ "__auto__":{"label":"Europe except France","shipto":"({address_filter.EU-27}) - (FR)","fees":10} }

Fees related to customer group

You can use the name or ID of the customer groups.

{ "__auto__":{"label":"NOT LOGGED IN and General groups","customer_groups":"NOT LOGGED IN,General","fees":10}, "__auto__":{"label":"NOT LOGGED IN and General groups by their ID","customer_groups":"0,1","fees":10}, "__auto__":{"label":"Retailer group","customer_groups":"Retailer","fees":10} }

Using formulas

Formulas can be used in properties conditions and fees.

{ "__auto__":{"label":"Shipping","fees":"0.1 * {cart.price-tax+discount} + 10.00"} }

Copying the property of another element

{ "standard":{"label":"Standard Shipping","conditions":"{cart.price-tax+discount} < 1000.00","fees":10}, "express":{"label":"Express Shipping","conditions":"( {standard.conditions} ) && ( {cart.weight} < 10 )","fees":12} }

Using the function min()

{ "__auto__":{"label":"Shipping","fees":"min({cart.weight}, {cart.price+tax+discount}, {cart.qty})"} }

Using the function range()

{ "__auto__":{"label":"Shipping","conditions":"range({cart.weight}, 1.0, 3.0)","fees":10} }

Using the function substr()

A variable of type string must be surrounded by single quotes unless the auto-quoting is used with the characters {{ and }}.

{ "__auto__":{"label":"Without auto-quoting","conditions":"substr('{cart.coupon_code}', 0, 5)=='free_'","fees":10}, "__auto__":{"label":"With auto-quoting","conditions":"substr({{cart.coupon_code}}, 0, 5)=='free_'","fees":10} }

Using special functions

Using the special function {table … in …}

{ "__auto__":{"label":"Shipping","fees":"{table {cart.weight} in 0.5:5.30, 1.0:6.50, 2.0:7.40, 3.0:8.30, 5.0:10.10}"} }

In a table, you can include or exclude a limit value with the characters [ and ]:

{ "__auto__":{"label":"Upper limit included","fees":"{table {cart.weight} in 1.0]:5.00}"}, "__auto__":{"label":"Upper limit excluded","fees":"{table {cart.weight} in 1.0[:5.00}"} }

In a table, you must specify the reference value. To do this, you can use one of the variables available.
You can also use a formula to define another reference value.

{ "__auto__":{"label":"Table with cart weight","fees":"{table {cart.weight} in 0.5:5.30, 1.0:6.50}"}, "__auto__":{"label":"Table with items quantity","fees":"{table {cart.qty} in 10:5.30, 20:6.50}"}, "__auto__":{"label":"Table with price including tax","fees":"{table {cart.price+tax+discount} in 15.00:5.30, 30.00:6.50, *:10.00}"}, "__auto__":{"label":"Table with price excluding tax","fees":"{table {cart.price-tax+discount} in 15.00:5.30, 30.00:6.50, *:10.00}"}, "__auto__":{"label":"Table with custom value","fees":"{table ceil({cart.weight}/10) in 1:5.30, 2:6.50}"} }

Using the special function {switch … in …} (associative table)

In a switch, you must specify the reference value. To do this, you can use one of the variables available.
You can also use a formula to define another reference value.

{ "__auto__":{"label":"Switch with coupon code","fees":"{switch {{cart.coupon_code}} in 'coupon1':5.30, 'coupon2':6.50, null:10.00, *:7.50}"}, "__auto__":{"label":"Switch with delivery country","fees":"{switch {{shipto.country_id}} in 'FR':5.30, 'BE':6.50, 'DE':10.00, *:7.50}"} }

Using the special function {count …}

{ "__auto__":{"label":"If at least one product has the attribute 'color' equal to 'Bleu'","conditions":"{count items where product.attribute.color=='Bleu'} > 0","fees":10}, "__auto__":{"label":"If all items have the option 'size' greater or equal to '1'","conditions":"{count items where item.option.size>='1'} == {cart.qty}","fees":10} }

If the property is of type Yes/No, you must use the values true/false or 1/0 without quotes.

{ "__auto__":{"label":"Example of property of type Yes/No: 1","conditions":"{count items where product.attribute.colissimo_allowed==1}","fees":10}, "__auto__":{"label":"Example of property of type Yes/No: true","conditions":"{count items where product.attribute.colissimo_allowed==true}","fees":10} }

Using the special function {count distinct …}

{ "__auto__":{"label":"Count of different SKU","conditions":"{count distinct product.attribute.sku}","fees":10} }

Using the special function {sum …}

{ "__auto__":{"label":"Sum of all options 'size' is greater than 30","conditions":"{sum item.option.size} > 30","fees":10} }

Using the special function {min …}

{ "__auto__":{"label":"Minimum price excluding tax without discount is greater to 10","conditions":"{min item.price-tax-discount} > 10","fees":10} }

Using the special function {max …}

{ "__auto__":{"label":"Maximum value of the option 'size' is lower than 50","conditions":"{max item.option.size} < 50","fees":10} }

Using {foreach …} loops

{ "__auto__":{"label":"Grouping products by origin and process groups seperately","fees":"{foreach product.attribute.code_origin}{table {selection.weight} in 0.0:0.00, 1.0:11.00, 3.0:12.00, 5.0:13.00}{/foreach}"}, "__auto__":{"label":" Calculate shipping fees by product","fees":"{foreach product.attribute.sku}{product.attribute.shipping}*{item.qty}{/foreach}"} }

Manipulate arrays

Using the function in_array()

{ "__auto__":{"label":"Shipping","conditions":"in_array({cart.qty}, array(10, 20, 30))","fees":10} }

Using the function in_array() avec des chaînes de caractères *

{ "__auto__":{"label":"Shipping","conditions":"in_array({{cart.coupon_code}}, array('free1', 'free2'))","fees":10} }

Using the function array_match_any()

{ "__auto__":{"label":"Shipping","about":"5 x weight of products that are in category 2 or category 3","fees":"{sum product.weight where array_match_any(product.categories.id, array(2, 3))} * 5.0"} }

Using the function array_match_all()

{ "__auto__":{"label":"Shipping","about":"5 x weight of products that are in both category 2 and category 3","fees":"{sum product.weight where array_match_all(product.categories.id, array(2, 3))} * 5.0"} }

Other examples

Using product category

Warning: you must notice that in Magento, a product can be in multiple categories. So be particularly careful how you use this property.

{ "__auto__":{"label":"Foreach loop with an iteration on the category","fees":"{foreach product.categories}{selection.weight}{/foreach}"}, "__auto__":{"label":"Using the category inside a foreach loop","fees":"{foreach product.sku}({{product.category}}=='Test' ? 2.00 : 1.00)*{item.qty}{/foreach}"}, "__auto__":{"label":"Using the id of the category inside a foreach loop","fees":"{foreach product.sku}({product.category.id}==12 ? 2.00 : 1.00)*{item.qty}{/foreach}"}, "__auto__":{"about":"The function in_array() is used because product.categories returns an array","label":"Sum of weight attributes of products in category 'Test' ","fees":"{sum product.weight where in_array('Test', product.categories)}"}, "__auto__":{"about":"The function in_array() is used because product.categories.id returns an array","label":"Sum of weight attributes of products in category 12 ","fees":"{sum product.weight where in_array(12, product.categories.id)}"}, "__auto__":{"about":"The function array_match_any() is used because product.categories.id returns an array","label":"Sum of weight attributes of products that are in one of the categories #11 and #12","fees":"{sum product.weight where array_match_any(product.categories.id, array(11, 12))}"}, "__auto__":{"label":"Sum of weights of products having for first category 'Test'","fees":"{sum product.weight where product.category=='Test'}"}, "__auto__":{"label":"Sum of weights of products having for first category id 12","fees":"{sum product.weight where product.category.id==12}"} }

Adding and using a data element

An element of type data allow to define data that can be used in shipping methods.

{ "mydata":{"type":"data","var1":"12"}, "__auto__":{"label":"Shipping","shipto":"FR","fees": "{mydata.var1}"}, "__auto__":{"label":"Shipping","shipto":"DE","fees": "{mydata.var1}*1.5"} }

Adding a meta element

An element of type meta allow to specify informative data (author, date…).

{ "about":{"type":"meta","author":"Owebia","date":"15/07/2013","about":"2013 rates"} }

Definitions

The configuration of a shipping mode is a JSON object containing properties.
Each property has a unique name, wich will serve as unique identifier.
Each property will consiste on a configuration element (also a JSON object).

Elements

There are three different types of configuration element:

  • method: shipping method (default if not specified)
  • data: data that can be used in one or more shipping methods (examples)
  • meta: informative data (examples)

Properties

Each element has several properties:

  • about: comment about the element
  • type: element type (method, meta or data)

Properties specific to the element type method:

  • label: name of shipping method
  • description (visible only if the template displays it)
  • enabled: shipping method enabled or not
  • fees: shipping fees
  • conditions: activation conditions
  • shipto: countries (regions, postal codes) allowed for delivery
  • billto: countries (regions, postal codes) allowed for billing
  • origin: countries (regions, postal codes) allowed for origin
  • customer_groups: customer groups allowed
  • tracking_url (more informations)

See examples

Using properties of type address (shipto, billto and origin)

The country codes used are those of Magento (apparently they are the same as the ISO 3166-1 alpha-2 codes).
It is possible to specify region codes (only with shipto) or zip codes that you want to filter or exclude.

You can use the wildcard character * or regular expressions for postal codes.
A regular expression must start and end with the character /. If you want to use the characters (, ) or ., you must escape them with the character \ (ex: "FR(/^25\([0-9]{3}\)$/)").
You can use the insensitivity modifier (ex: "GB(/^PO.*$/i)").

See examples

Tip
To shorten the seizure of countries, you can use the following variables:

  • {address_filter.AF}: African countries
  • {address_filter.AS}: Asian countries
  • {address_filter.EU}: European countries
  • {address_filter.NA}: North American countries
  • {address_filter.SA}: South American countries
  • {address_filter.OC}: Oceanian countries
  • {address_filter.AN}: countries of Antarctica
  • {address_filter.EU-27}: countries of the European Union
  • {address_filter.DOM}: country codes of French Overseas "Départements"
  • {address_filter.COM}: country codes of French Overseas "Collectivités"

See examples

The unique identifier

Each configuration element has a unique identifier. This identifier can be used to refer to the element.

Example:

{ "europa":{"label":"Shipping to Europa","fees":10}, "us":{"label":"Shipping to US","fees":"{europa.fees}+20"} }

Warning: to avoid conflicts, use only the characters a-z, A-Z, 0-9, - and _ for the unique identifier.
You should also avoid identifiers that already correspond to variable names (cart, product, item…).

Formulas

The properties fees and conditions are defined using formulas.

A formula uses variables, functions, special functions and mathematical operators.

Available mathematical operators:

  • operators: *, /, + and -
  • modulo: %
  • parentheses: ( and )
  • boolean operators &&, and, ||, or, ==, <, >, <=, >=
  • binary operators & and |
  • the operator group C ? X : Y (ex: "{cart.price_exluding_tax}>100 ? 15*{cart.weight} : 20*{cart.weight}")

You can put spaces and line breaks in formulas (for lightening).

You can use the following advanced features: casting to interger (int) or floatting numbers (float), comparison with the null value or with boolean values true and false.

Variables

When you use variables of type string, you must escape them with single quotes or use the auto-quoting syntax {{ }}.

The following variables can be used in formulas.

  • The cart:
    • {cart.weight}: weight of goods
    • {cart.qty}: the quantity of items
    • {cart.price-tax+discount}: price excluding tax with discount
    • {cart.price+tax+discount}: price including tax with discount
    • {cart.price-tax-discount}: price excluding tax without discount
    • {cart.price+tax-discount}: price including tax without discount
    • {cart.coupon_code}: coupon code
    • {cart.free_shipping}: delivery offered (by rules in Magento) [true/false]
    • {cart.weight_unit}
    • {cart.weight_for_charge}: weight of goods whose delivery is not offered (by cart pricing rules in Magento)
  • The quote:
    • {quote.subtotal}: subtotal (excluding tax)
    • {quote.subtotal_with_discount}: subtotal (excluding tax) with discount
    • {quote.grand_total}: total (including tax) with discount
    • {quote.base_subtotal}: subtotal (excluding tax) in base currency
    • {quote.base_subtotal_with_discount}: subtotal (excluding tax) with discount in base currency
    • {quote.base_grand_total}: total (including tax) with discount in base currency
  • The customer group:
    • {customer_group.id}: id of customer group
    • {customer_group.code}: name of customer group
    • {customer_group.*}: property of the customer group (ex: {customer_group.tax_class_id})
  • The customer:
    • {customer.id}: id of customer
    • {customer.attribute.*}: attribute of the customer (ex: lastname, firstname, group_id…)
    • {customer.attribute.*.value}: in case of an attribute of type selection list, {customer.attribute.*} returns the id, to get the value, you have to use {customer.attribute.*.value}
    • {customer.*}: same as {customer.attribute.*}, unless the variable is already defined (ex: {customer.id} is already defined)
  • Custom Variables (since Magento 1.4.0.1):
    • {customvar.*}: custome variable defined in Magento (ex: {customvar.my_var})
  • The delivery address:
    • {shipto.country_name}
    • {shipto.country_id}: the country code
    • {shipto.region_id}
    • {shipto.region_code}
    • {shipto.street}
    • {shipto.city}
    • {shipto.postcode}
  • The billing address:
    • {billto.country_name}
    • {billto.country_id}: the country code
    • {billto.postcode}
    • {billto.*}: property of the billing address (ex: {billto.city})
  • The origin address:
    • {origin.country_name}
    • {origin.country_id}: the country code
    • {origin.region_id}
    • {origin.city}
    • {origin.postcode}
  • The store:
    • {store.id} {store.code} {store.name} {store.address} {store.phone}
  • The current date:
    • {date.timestamp}: UNIX timestamp of the current date
    • {date.year} {date.month} {date.day} {date.hour} {date.minute} {date.second}
    • {date.weekday}: day of the week for the current date from 0 (Sunday) to 6 (Saturday)
  • The request object:
    • {request.*}: property of the request object (Mage_Shipping_Model_Rate_Request) given by Magento (ex: {request.package_qty}). Use "Debug" option to get more details on available properties.

Variables that can be used in special functions

The following variables can be used in special functions.

Unlike elsewhere, the following variables should not be surrounded by the characters { and }.

An item is a variation of a product to which some options have been added. Each item has a quantity.

  • The item:
    • item.qty: quantity in the cart
    • item.price-tax+discount: price excluding tax with discount
    • item.price-tax-discount: price excluding tax without discount
    • item.price+tax+discount: price including tax with discount
    • item.price+tax-discount: price including tax without discount
    • item.option.*: option (the available options depend on the product)
  • The product:
    • product.attribute.*
      Interesting attributes:
      • sku
      • name
      • weight
      • price (as defined in Magento backoffice)
      • special_price: (as defined in Magento backoffice)
    • product.attribute.*.value: value of the attribute
      In case of an attribute of type selection list, product.attribute.* returns the id. To get the value, you have to use product.attribute.*.value
    • product.*: same as product.attribute.* unless the variable is already defined (ex: product.category)
    • First category of the product:
      • product.category: name of the category
      • product.category.id
      • product.category.*: attribute of the category (ex: product.category.is_active)
        Interesting attributes:
        • is_active
        • name
    • All product categories (returns an array, examples):
      • product.categories: array of name of the categories
      • product.categories.id: array of id of the categories
    • The attribute set:
      • product.attribute_set: name of the attribute set
      • product.attribute_set.id
      • product.attribute_set.*: attribute of the attribute set (ex: product.attribute_set.attribute_set_name)
    • product.stock.*: attribute of the product stock
      Interesting attributes:
      • is_in_stock
      • qty: quantity in stock

Variables that can be used in foreach loops

The following variables can be used in foreach loops.

  • {selection.weight}
  • {selection.qty}: items count in the selection

When the selection is made on the sku, each selection consists of a single article. We can therefore use the item and product variables.

  • {item.*}: item property
  • {product.*}: product property

Item and product variables are identical to variables that can be used in special functions with the only difference that they must be surrounded by the characters { and }.

Functions

Numerical functions

  • abs(x): absolute value
  • ceil(x): round up
  • exp(x): exponent
  • floor(x): round down
  • log(x): logarithm
  • log(x, base): natural logarithm
  • max(x, y, …): maximum, null values ignored
  • min(x, y, …): minimum, null values ignored
  • pi(): PI number
  • pow(x, puissance): pow
  • rand(min, max): random integer
  • round(x)
  • sqrt(x): square root

Functions to manipulate strings

  • substr(string, start, length): returns a string segment.

Functions to manipulate arrays

  • in_array(value, array(value1, value2, …)): returns true if the value is found in the array.
  • array_match_any(array(value1, value2, …), array(value1, value2, …)): returns true if at least one value is found in both arrays.
  • array_match_all(array(value1, value2, …), array(value1, value2, …)): returns true if both arrays are identical.

More functions

  • range(value, min, max, include_min, include_max): returns true if value is greater than min and lower than max. By default, include_min and include_max are equal to true.

Special functions

  • {table … in …}: defining values based on thresholds (examples)
  • {switch … in …}: defining an associative table (examples)

The first parameter of table and switch functions is the reference value, it can be either a variable or a formula.

  • {count items[ where …]}: counts eligible items (examples)
  • {count distinct …[ where …]}: counts all different values of a property for eligible items (examples)
  • {sum …[ where …]}: calculates the sum of the values of a property for eligible items (examples)
  • {min …[ where …]}: returns the minimum value of a property for eligible items (examples)
  • {max …[ where …]}: returns the maximum value of a property for eligible items (examples)

The first parameter of count distinct, sum, min and max functions must be a property (ex: product.attribute.weight).

The condition where is optional. If specified, it will be in the form of a formula.

Using foreach loops

foreach loops can perform a calculation on groups of products rather than consider all the products in the cart.
The overall result of a foreach loop is the sum of the results of each pass through the loop.

Inside a foreach loop, you can use new variables.

Examples

Miscellaneous

The tracking URL

The use of tracking_url property is reserved for experienced users. If you don't understand the instructions below, it is recommended that you avoid using this feature.

The tracking_url property overrides the field "Tracking URL" of an Advanced Shipping shipping mode. So you can specify a tracking URL foreach shipping method rather than one for all shipping mode.

To automatically insert the tracking number in the tracking URL, you must use {tracking_number}.

{ "__auto__":{"label":"Example of tracking URL for the carrier Colissimo","fees":10,"tracking_url":"http://www.coliposte.net/particulier/suivi_particulier.jsp?colispart={tracking_number}"} }

Magento does not support tracking links but tracking statuses. The extension Advanced Shipping provides an HTML link instead of the status, link allowing you to go on the carrier's website and follow the progress of the parcel.

When the tracking URL is built by the extension, the only information available is the tracking number and there was nowhere an access to the shipping method selected. In order to find the tracking URL in the configuration, you must specify the shipping method inside the tracking number, for example: colissimo:8Lxxxxxxxxxxx where colissimo is the code of the shipping method selected.
If no code is specified (if you enter only the tracking number), the URL used will be the one of the shipping mode.

To answer a recurrent question, Magento displays the tracking status from the back office or front office. If you want to insert the tracking URL in shipping mails, you need to develop yourself the retrieval of tracking URL and its incorporation in the mail, in fact, the Advanced Shipping extension simply provides customizable shipping methods without making big changes to Magento core to reduce incompatibility and update problems.

If you get a blank popup when you click on the tracking link, your problem is most likely related to the fact that you did not specify the code of the shipping method in the tracking number (see instructions above) and your global field "Tracking URL" is empty.

There are currently no plans to change this feature.

Index

A

  • about: property
  • activation: see enabled
  • address of origin: see origin
  • address of billing: see billto
  • address of delivery: see shipto
  • address_filter: shortcuts, examples
  • associative table: see switch
  • attribute of product: see product.attribute.*

B

C

D

E

F

I

L

M

O

P

Q

R

  • regular expression: see property shipto
  • request: variables

S

T

V