tero.co.uk

Shopable - Shipping

Below the language settings in settings.html is the shipping and tax information. The shipping and tax policies are loosely based around the UK, but can be easily amended for other countries.

In summary, Shopable computes tax for every order, on a per item basis (as different items can have different tax rates). The country table specifies to which countries this tax should be charged (based on tax regions). The shipping function computes shipping based on the country, weight and subtotal.

Shipping and Handling
Below is a description of what each of the variables in this section does:

  • showTotals: whether the shipping, tax, and handling are shown in the View Basket screen (otherwise they are only shown in the Confirmation screen)
  • showHandling: show the handling charge even when it is zero
  • handlingCharge: the handling charge, a set fee added to each order
  • shippingTax: the type of tax to charge on the shipping (tax types are explained below)
  • showTax: whether or not to show tax in the shopping basket, if set to true then all the tax rules below apply

Tax
The next few variables define tax types. These correspond to the tax code argument in the order function, and allow different products to be taxed at different percentages. In the UK there are 4 tax bands, with most items being taxed at the standard rate. If tax is already included in some or all of the items you are selling, it might be useful to create an included tax code (like this: s.tax.included = 0;), and use this tax code for those items, then no additional tax will be charged on those items.

As a quick example, if you sell all your products with 5% tax, you could include the line s.tax.standard = 5. If you do not charge tax on shipping then include the line s.tax.exempt = 0 and in the above section set s.shippingTax = "exempt".

The next section declares in which regions of the world tax is charged. This ties in with the country table. The line s.chargetax.eu = true; charges the taxes set above to Europe. Note that this only turns taxing on or off for individual regions, if there was no tax to begin with, this won't add any.

Shipping Function
The shipping function computeShipping returns the shipping cost based on the shipping region (as defined in the country table), the weight and the subtotal. These values can be used to implement several different types of shipping policies. Returning a shipping value less than zero will cause the shopping basket to display a "too heavy" message.

For example, the following function implements free shipping, but with a limit of 10 kilograms.

function computeShipping (shippingregion, weight, subtotal) {
  if (weight > 10) {return -1;} //if this order is just too heavy, return -1
  return 0; //return 0 for free
}

The next example charges £5 if the subtotal is less than £50, and free if not.

function computeShipping (shippingregion, weight, subtotal) {
  if (weight > 10) {return -1;} //if this order is just too heavy, return -1
  if (subtotal < 50) {return 5;} else {return 0;}
}

This one uses the shipping region and charges by the kilogram. The shipping region comes from the country table.

function computeShipping (shippingregion, weight, subtotal) {
  if (weight > 10) {return -1;} //if this order is just too heavy, return -1
  if (shippingregion == "uk") {return weight * 3;} //£3 per kilogram in the uk
  if (shippingregion == "eu") {return weight * 10;} //£10 per kilogram in europe
  return weight * 20; //£20 per kilogram everywhere else
}

This one is free to Europe, with a maximum weight of 10kg, and 15% of the subtotal to everywhere else, with a maximum weight of 5kg.

function computeShipping (shippingregion, weight, subtotal) {
  if (shippingregion == "eu") { //for Europe
    if (weight > 10) {return -1;} //too heavy for Europe
	else {return 0;} //or else shipping is free
  }
  else { //for anywhere else 
    if (weight > 5) {return -1;} //too heavy for anywhere
	else {return subtotal * 0.15;} //or else 15% of the subtotal
  }
}

Country Table
The country table defines all the countries, used in the billing and shipping country lists on the customer details page. Each country defines a name, tax region, and shipping region. For example createCountry ("Andorra", 0, "eu"); puts Andorra in the tax region 0 (for outside Europe), but the shipping region "eu". So it is outside Europe for tax purposes, but inside for shipping. Note that countries can appear more than once. I would like one day to develop a similar system for American and Canadian states (so that for shops based in America, the shipping and tax can differ between both states and countries, perhaps by just listing each state in the country table).

Example
Imagine that you lived in California, and you wanted to charge sales tax only on Californian orders. Furthermore, you only want to ship within North America (and it's not as expensive within the United States), and charge shipping only on large orders.

Your basic settings might look like this.

s.showTotals = true;
s.showHandling = true;
s.handlingCharge = 2;
s.shippingTax = "standard"; //the type of tax to charge on the shipping
s.showTax = true; //charge tax and show it in the basket

Then you would need to define the tax bands. This will charge 8.25% sales tax within California.

s.tax.standard = 8.25;

The next line says that any order from a "country" with a tax region of california will be charged tax. All others won't.

s.chargetax.california = true;

Our shipping function charges based on the subtotal and shipping region.

function computeShipping (shippingregion, weight, subtotal) {
  if (weight > 10) {return -1;} //if this order is just too heavy, return -1
  if (subtotal < 200) { //for orders with a subtotal less than $200
    if (shippingregion == "us") {return 5;} //$5 within the US
    else {return 10;} //$10 elsewhere
  } 
  else {return 0;} //free shipping on large orders
}

Finally we set up the country listings. Here we will use the country table to differentiate states as well. Note how the tax and shipping regions correspond to chargeTax and computeShipping above.

cC ("Canada", 0, 0); //cC is short for createCountry
cC ("Mexico", 0, 0); //no special tax or shipping region
cC ("United States (California only)", "california", "us"); //california tax region
cC ("United States (except California)", 0, "us"); //us shipping region