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

Transferring your Magento 1 database to Magento 2

Moving your Magento 1 to Magento 2 may be one of the most challenging things out there. Luckily, Magento supported us with a database migration option.

The Magento 2 Data Migration Tool is here to help you convert your products, customers, order/sales data, store configuration, promotions/sales rules, and more to move to a clean Magento 2 setup.

Custom code, Extensions, and Themes are out of the current scope of the Data Migration Tool.

The currently supported migrations are the Community Edition (CE) versions 1.6.x, 1.7.x, 1.8.x, and 1.9.x and Enterprise Edition (EE) versions 1.11.x, 1.12.x, 1.14.x, and 1.14.x.

Tip

Check with your third-party extension developer for a Data Migration Tool to move the database code base to Magento 2.

Getting ready

Before we can start migrating our system, we need to check the following:

  • Have a clean Magento 2 system running.
  • Disable your cron jobs.
  • Always back up your databases and old and new Magento versions.
  • Check whether there is a network connection from the current Magento 1 to Magento 2 server. Check the firewall for database access if needed (port 3306).
  • Only use the exact version number, so that the data-migration-tool 2.0.0 corresponds with Magento 2.0.0.

Tip

You may copy your current production database to the new Magento 2 server and run it there.

A migration of Magento 1 to Magento 2 has the following five phases that are important to follow in the correct order:

  1. Settings: Migration of the settings is step 1. This will transfer all information from the stores, website, and system configuration.

    The command is php bin/magento migrate:settings.

  2. Data: Migration of the data is step 2. This will transfer all categories, products, customers, orders, wishlists, ratings, and so on

    The command is php bin/magento migrate:data.

  3. Delta: Migration of the delta is step 3. This is an important step and is used to transfer Magento 1 data to Magento 2 where new updates occur. It will update the most recent data of customers, orders, or other customer-related data. It is common to use this command before going live.

    The command is php bin/magento migrate:delta.

  4. Media: Migration of the media files is easy; just copy all files from /media to /pub/media.
  5. Custom modules/themes: Migration of your modules or themes is out of the scope of the migration tool. Contact your solutions provider to check whether they have a new version available. This also applies to any custom-made themes of theme packages bought online.

How to do it...

For the purpose of this recipe, let's assume that we need to manage a Magento 1 to Magento 2 migration setup. The following steps will guide you through this:

  1. First, we need to run the following command to add data-migration-tool to your current Composer setup:
    composer config repositories.data-migration-tool git https://github.com/magento/data-migration-tool-ce
    composer require magento/data-migration-tool:dev-master
    

    Wait while all dependencies are updated.

  2. Now check whether the migration tools are available in the bin/magento shell tool:

    Commands

    Description

    migrate

     

    migrate:data

    Main migration of data

    migrate:delta

    Migration of the data that is added to Magento after the main migration

    migrate:settings

    Migration of the system configuration

  3. For this recipe, we will be using a Magento 1 database installation on our DigitalOcean Droplet. You may pick any of your production or Magento 1 sample data SQL dumps. We will be using a Magento 1.9.2.2 sample data SQL dump. Our database is called magento1.
  4. Now, we need to map the database configuration files from the Magento 1 database to the Magento 2 database. Always make sure that you are using a clean database; otherwise, you can run the following command:
    php bin/magento setup:uninstall
    

    Go to /var/www/html/vendor/magento/data-migration-tool/etc/ce-to-ce and pick the correct database version mentioned in the directory. If correct, you will see two files called config.xml.dist and map.xml.dist.

  5. Copy config.xml.dist to config.xml using the cp command:
    cp config.xml.dist config.xml
    
  6. Open your config.xml and look for the <source> tag (line 94). Change it accurately with the database username and password:
    <source>
      <database host="localhost" name="magento1" user="root" password="mypassword"/>
    </source>
    <destination>
      <database host="localhost" name="magento2" user="root" password="mypassword"/>
    </destination>
    <options>
      <source_prefix>myprefix-from-magento1</source_prefix>
      <crypt_key>mycrypt-key-from-magento1</crypt_key>
    </options>

    If you are using a custom prefix in your database or you wish to use your encryption key on your Magento 2 setup, you can add this to the <options> section, as shown in the previous code.

  7. Now we can start step 1 of the settings migration using the following command:
    php bin/magento migrate:settings /var/www/magento2/vendor/magento/data-migration-tool/etc/ce-to-ce/1.9.2.2/config.xml
    

    As you can see, here we are using the 1.9.2.2 version. Depending on your version, you may change this before running the command.

    The output result looks like this:

    [2015-12-02 20:28:56][INFO][mode: settings][stage: integrity check][step: Settings Step]: started
    100% [============================] Remaining Time: 1 sec
    [2015-12-02 20:28:56][INFO][mode: settings][stage: integrity check][step: Stores Step]: started
    100% [============================] Remaining Time: 1 sec
    [2015-12-02 20:28:56][INFO][mode: settings][stage: data migration][step: Settings Step]: started
    100% [============================] Remaining Time: 1 sec
    [2015-12-02 20:28:59][INFO][mode: settings][stage: data migration][step: Stores Step]: started
    100% [============================] Remaining Time: 1 sec
    [2015-12-02 20:28:59][INFO][mode: settings][stage: volume check][step: Stores Step]: started
    100% [============================] Remaining Time: 1 sec
    [2015-12-02 20:28:59][INFO][mode: settings][stage: volume check][step: Stores Step]: Migration completed
    
  8. You can check your Magento 2 system configuration backend if all updated settings are available. If so, you can continue.
  9. If step 1 is correct, we continue to migrate our data to Magento 2 using the following command:
    php bin/magento migrate:data /var/www/magento2/vendor/magento/data-migration-tool/etc/ce-to-ce/1.9.2.2/config.xml
    

    The output result looks like this:

    How to do it...
  10. You can check your Magento 2 catalogs, products, orders, and customers if they are all updated. If so, you can continue.
  11. Before you continue, make sure to reindex and flush your caches at once:
    php bin/magento indexer:reindex
    php bin/magento cache:clean
    php bin/magento cache:flush
    
  12. Now check the frontend and backend whether your data is available in Magento 2. If not, check the migration.log file located in /var.
  13. In this recipe, we used a default Magento 1.9.2.2 setup. After the settings and data migration, we created a sales order in Magento 1. Now, using the delta option, we push the data to Magento 2 using the following command:
    php bin/magento migrate:delta /var/www/magento2/vendor/magento/data-migration-tool/etc/ce-to-ce/1.9.2.2/config.xml
    

    The output result looks like this:

    How to do it...
  14. Now check your sales and customer data. Congratulations, you successfully migrated your database from Magento 1 to Magento 2.

How it works…

Let's recap and find out what we did throughout this recipe. In steps 1 through 14, you learned how to use the Magento 2 migration tool.

In step 1, we used Composer to add an additional repository for data migration. After installing all of the packages, they are available in the bin/magento tool. In this setup example, we used a clean Magento 1.9.x database.

In step 4, we made sure to run on a clean Magento 2 setup. Depending on your setup, go to vendor/magento/data-migration-tool/etc and select the correct version. Magento 2 supports the migration option for CE and EE. Once we configured the config.xml file with the Magento 1 database information in step 6, we were ready to go.

In step 7, we used the bin/magento migration setting to start the whole process. We started with the setting parameter and continued with the data and delta parameters in steps 7 through 13. We must not forget the reindexing and updating of our caches before using them. The delta parameter option can be run multiple times as it only updates the latest information, which is helpful before going live and switching to production.

There's more…

As every Magento setup is unique, migrating from Magento 1 to Magento 2 can be hard sometimes. In some situations, you may need to change your tables in the mapping configuration located in vendor/magento/data-migration-tool/etc/ce-to-ce/<version>map.xml.dist.

Resetting your setting, data, and delta migration is easy using the [-r|--reset] parameter in your command. This allows you to rerun all migration scripts from the beginning.

Always check for the currently supported versions on the Magento GitHub Data Migration Tool page at the following link:

https://github.com/magento/data-migration-tool-ce

Tip

There is also an alternative Data Migration Tool available by UberTheme at https://github.com/ubertheme/magento2_data_migration.