Table of Contents for
Magento 2 - Build World-Class online stores

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition Magento 2 - Build World-Class online stores by Jonathan Bownds Published by Packt Publishing, 2017
  1. Cover
  2. Table of Contents
  3. Magento 2 - Build World-Class online stores
  4. Magento 2 - Build World-Class online stores
  5. Credits
  6. Preface
  7. 1. Module 1
  8. 1. Magento Fundamentals
  9. XAMPP installation
  10. Magento
  11. Summary
  12. 2. Magento 2.0 Features
  13. An introduction to the Magento order management system
  14. Magento 2.0 command-line configuration
  15. The command-line utility
  16. Summary
  17. 3. Working with Search Engine Optimization
  18. Store configuration
  19. SEO and searching
  20. SEO catalog configuration
  21. Google Analytics tracking code
  22. Optimizing Magento pages
  23. Summary
  24. 4. Magento 2.0 Theme Development – the Developers' Holy Grail
  25. Magento 2.0 theme structure
  26. The Magento Luma theme
  27. Magento theme inheritance
  28. CMS blocks and pages
  29. Custom variables
  30. Creating a basic Magento 2.0 theme
  31. Summary
  32. 5. Creating a Responsive Magento 2.0 Theme
  33. Composer – the PHP dependency manager
  34. Building the CompStore theme
  35. CSS preprocessing with LESS
  36. Applying new CSS to the CompStore theme
  37. Creating the CompStore logo
  38. Applying the theme
  39. Creating CompStore content
  40. Customizing Magento 2.0 templates
  41. Summary
  42. 6. Write Magento 2.0 Extensions – a Great Place to Go
  43. Using the Zend framework
  44. Magento 2.0 extension structure
  45. Developing your first Magento extension
  46. The Twitter REST API
  47. The TweetsAbout module structure
  48. Using TwitterOAuth to authenticate our extension
  49. Developing the module
  50. Summary
  51. 7. Go Mobile with Magento 2.0!
  52. Adjusting the CompStore theme for mobile devices
  53. The Magento 2.0 responsive design
  54. The Magento UI
  55. Implementing a new CSS mixin media query
  56. Adjusting tweets about extensions for mobile devices
  57. Summary
  58. 8. Speeding up Your Magento 2.0
  59. Indexing and caching Magento
  60. Indexing and re-indexing data
  61. The Magento cron job
  62. Caching
  63. Fine-tuning the Magento hosting server
  64. Selecting the right Magento hosting service
  65. Apache web server deflation
  66. Enabling the expires header
  67. Minifying scripts
  68. Summary
  69. 9. Improving Your Magento Skills
  70. Magento knowledge center
  71. Improving your Magento skills
  72. Summary
  73. 2. Module 2
  74. 1. Magento 2 System Tools
  75. Installing Magento 2 sample data via GUI
  76. Installing Magento 2 sample data via the command line
  77. Managing Magento 2 indexes via the command line
  78. Managing Magento 2 cache via the command line
  79. Managing Magento 2 backup via the command line
  80. Managing Magento 2 set mode (MAGE_MODE)
  81. Transferring your Magento 1 database to Magento 2
  82. 2. Enabling Performance in Magento 2
  83. Configuring Redis for backend cache
  84. Configuring Memcached for session caching
  85. Configuring Varnish as the Full Page Cache
  86. Configuring Magento 2 with CloudFlare
  87. Configuring optimized images in Magento 2
  88. Configuring Magento 2 with HTTP/2
  89. Configuring Magento 2 performance testing
  90. 3. Creating Catalogs and Categories
  91. Create a Root Catalog
  92. Create subcategories
  93. Manage attribute sets
  94. Create products
  95. Manage products in a catalog grid
  96. 4. Managing Your Store
  97. Creating shipping and tax rules
  98. Managing customer groups
  99. Configuring inventories
  100. Configuring currency rates
  101. Managing advanced pricing
  102. 5. Creating Magento 2 Extensions – the Basics
  103. Initializing extension basics
  104. Working with database models
  105. Creating tables using setup scripts
  106. Creating a web route and controller to display data
  107. Creating system configuration fields
  108. Creating a backend data grid
  109. Creating a backend form to add/edit data
  110. 6. Creating Magento 2 Extensions – Advanced
  111. Using dependency injection to pass classes to your own class
  112. Modifying functions with the use of plugins – Interception
  113. Creating your own XML module configuration file
  114. Creating your own product type
  115. Working with service layers/contracts
  116. Creating a Magento CLI command option
  117. 3. Module 3
  118. 1. Planning for Magento
  119. Technical considerations
  120. Global-Website-Store methodology
  121. Planning for multiple stores
  122. Summary
  123. 2. Managing Products
  124. Managing products the customer focused way
  125. Creating products
  126. Managing inventory
  127. Pricing tools
  128. Autosettings
  129. Related products, up-sells, and cross-sells
  130. Importing products
  131. Summary
  132. 3. Designs and Themes
  133. The concept of theme inheritance
  134. Default installation of design packages and themes
  135. Installing third-party themes
  136. Inline translations
  137. Working with theme variants
  138. Customizing themes
  139. Customizing layouts
  140. Summary
  141. 4. Configuring to Sell
  142. Payment methods
  143. Shipping methods
  144. Managing taxes
  145. Transactional e-mails
  146. Summary
  147. 5. Managing Non-Product Content
  148. Summary
  149. 6. Marketing Tools
  150. Promotions
  151. Newsletters
  152. Using sitemaps
  153. Optimizing for search engines
  154. Summary
  155. 7. Extending Magento
  156. The new Magento module architecture
  157. Extending Magento functionality with Magento plugins
  158. Building your own extensions
  159. Summary
  160. 8. Optimizing Magento
  161. Indexing and caching
  162. Caching in Magento 2 – not just FPC
  163. Tuning your server for speed
  164. Summary
  165. 9. Advanced Techniques
  166. Version control
  167. Magento cron
  168. Backing up your database
  169. Upgrading Magento
  170. Summary
  171. 10. Pre-Launch Checklist
  172. System configurations
  173. Design configurations
  174. Search engine optimization
  175. Sales configurations
  176. Product configurations
  177. Maintenance configurations
  178. Summary
  179. Index

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 1, 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 3, 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…