Creating shipping and tax rules

The topic of shipping is so huge that you could write a book about it. The options related, for example, to width, length and height, breakable, edible, and so on, are endless.

After configuring these attributes for a product, we can start relating them to our shipping setup and shipping vendor. Magento has a huge selection of shipping vendors to choose from. It's important to choose the right vendor and the correct Magento extension. This could be challenging. Do not immediately pick the cheapest shipping vendor. Check the quality of their service, their specialty when it comes to shipping your products, and their Magento extension.

Creating the correct tax rules is not for the fainthearted. Are you in the USA, Europe, Asia, or somewhere else? Every country has its own tax rules. Always check with the local authorities to find out which rules to apply.

Getting ready

To step through this recipe, you will use a Droplet created in Chapter 2, Magento 2 System Tools at DigitalOcean https://www.digitalocean.com/. We will be using an NGINX, PHP-FPM, Composer-based setup including sample data. No other prerequisites are required.

How to do it…

For the purpose of this recipe, let's assume that we need to create shipping and tax rules for the European Union. The shipping rules apply to a Table Rates setup using a local shipping vendor. The following steps will guide you through them.

  1. First we start setting up the shipping rates. Go to Stores | Configuration | Sales. We have three menus to choose from. Let's start with the Shipping Settings first. Click on the Menu tab. You see two drop-down menus called Origin and Shipping Policy Parameters.

    Now complete the entire field set related to your company. This is the starting point. When using the Shipping Policy, just mark it Yes and commit your policy. Here is an example of how a policy could look:

    Note

    Please be assured that your items will ship out within two days of purchase. We determine the most efficient shipping carrier for your order. The carriers that may be used are: TNT, DHL, United Parcel Service (UPS), or FedEx. Sorry but we cannot ship to P.O. Boxes.

    How to do it…
  2. Now continue to the Multishipping Settings menu. By default, we stay with the Allow Shipping to Multiple Addresses option.
  3. Next, we click Shipping Methods. The default shipping options in Magento 2 are: Free Shipping, Flat Rate, Table Rates, UPS, USPS, FedEx, and DHL.

    Since the scope of this recipe is Table Rates, using Free Shipping and Flat Rate is pretty straightforward.

    Now click on the Table Rates drop-down arrow, and commit the following information:

    How to do it…

    In the Condition drop-down menu we use the Weight vs. Destination option. Beside this option we also can choose from Price vs. Destination or # (number) of items vs. Destination. Depending on your needs, pick one of them. Since we are using the Weight option, we need to make sure that our entire product set has the correct weight configured.

  4. For the purpose of this recipe, disable the Flat Rate option in the menu.
  5. Now click Save Config and update your cache.
  6. Next we need to switch to the correct website using the Store View switcher in the Stores | Configuration menu. Click the drop-down arrow in the top-left menu, and select Main Website (or the name of your website):
    How to do it…
  7. Confirm the pop-up window to continue and check the Table Rates options. Now we have two new options visible. The Export CSV gives us a comma-separated file called tablesrates.csv that we need to complete. Download the file and open up a spreadsheet editor, such as MS Excel, OpenOffice Calc, or Google Docs Spreadsheet.

    Since we are using the Weight vs. Destination option, the CSV schema looks as follows:

    Country

    Region/State

    Zip/Postal Code

    Weight (and above)

    Shipping Price

    NLD

    *

    *

    0

    6.95

    NLD

    *

    *

    50

    9.95

    NLD

    *

    *

    100

    14.50

    DEU

    *

    *

    0

    10.50

    DEU

    *

    *

    50

    17.50

    DEU

    *

    *

    100

    22.50

    FRA

    *

    *

    0

    10.50

    FRA

    *

    *

    50

    17.50

    FRA

    *

    *

    100

    22.50

    In this example, we use a wildcard for the Region/State and Zip/Postal Code. You can replace this wildcard with the appropriate value. Upload your saved tablesrates.csv file in the Import section and click Save Config, and clean the cache:

    How to do it…
  8. Before we can verify it is working, we need to update the weight of the product we want to sell. Go to Products | Catalog and update your grid using the weight attribute. Check out the Manage products in a catalog grid recipe of Chapter 4, Creating Catalogs and Categories for how to do this.
  9. Now let's edit Joust Duffle Bag from the sample data. Set the Weight to 50 and click Save & Close. Do the same for Strive Shoulder Pack (49) and Crown Summit Backpack (51). Your product grid should now look as follows:
    How to do it…
  10. Finally, we can test if the checkout and shipping fee are configured correctly. Open up a browser, add the Joust Duffle Bag to you basket, and check it out. Complete your personal data and check the shipping Table Rate at the bottom.

    We only used German, French, and Dutch codes in this example. If you want to have your country shipping fees in the Table Rate CSV file, update them accordingly:

    How to do it…
  11. Congratulations, you just finished configuring shipping rules in Magento 2.
  12. Next we continue to configure the appropriate tax rules. Since we cannot cover all the different tax rules worldwide, we will stick for now with the European Union. Import to the following tax_rates.csv file to System | Import/Export Tax Rates. The file can be downloaded from https://github.com/mage2cookbook/chapter5.
  13. To check if all tax rates are created, go to Stores | Tax Zone and Rates. You see a large list of all rates and countries.

    Note

    All rates apply to the current tax regulation of the European Union with effect from the 1st of January 2015. The calculated tax is based on the country of the seller.

  14. Now go to Stores | Tax Rules and click on Rule 1. For this example we change the Name to EU Customers. Now let's select all the EU countries with the (standard) tax Rate and click Save Rule:
    How to do it…

    In this example we set the default rule to the high tax rate. Create a new rule when you are selling services or products that have a lower tax rate. But don't forget to create a new Product Tax Class in the Additional Settings. This class can then be used in every product type where it applies.

  15. Next we need to configure the tax system setup. Go to Stores | Configuration | Sales | Tax. Depending on your production setup, using a multi domain with different shipping vendors and warehouse configuration may change. Always use the Store View switcher on the top to change the settings according to the domain or country you are selling in. The following examples will give you an overview of a basic setup created in Magento 2 Enterprise Edition. In the Magento 2 Community Edition some features, such as Gift Wrapping and Printed Card Prices, will not be shown:
    How to do it…
    How to do it…
    How to do it…
    How to do it…
    How to do it…
    How to do it…
    How to do it…
  16. Change the setting and click Save Config.
  17. Since we are using the Magento 2 sample data, we are ready to perform the test. Every product is configured with the Taxable Goods Tax Class.
  18. Finally, we can test if the checkout and tax rates are configured correctly. Open up a browser and add the Joust Duffle Bag to your basket and check it out. Complete your personal data and check the Review & Payments step on the right in the checkout. The Order Summary should now look like this:
    How to do it…
  19. Congratulations, you just finished configuring tax rules in Magento 2.

How it works…

Let's recap and find out what we did throughout the preceding recipe. In Steps 1 through 10, we configured a shipping method called Table Rates to handle all the shipping. We used the Weight vs. Destination option. Using this option we needed to update all our products with the correct weight attribute value.

In Steps 12 through 18, we configured tax rules for the European Union using a tax_rates.csv file from GitHub. By using this file, it was easy to configure the appropriate tax rule. In Step 15, we gave an example of how a system configuration for a store view could look.

There's more…

Depending on where you live or are sending products to, using the correct measuring units in Magento 2 is important. This new feature helps us to configure whether we calculate the weight in lbs (pounds) or kgs (kilograms). We can find this new option in Stores | Configuration | General | Locale Options. Here is an example showing the Weight Unit field:

There's more…
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.51.228