{"id":2497,"date":"2017-11-04T11:42:42","date_gmt":"2017-11-04T10:42:42","guid":{"rendered":"https:\/\/www.recolize.com\/?p=2497"},"modified":"2018-09-11T18:14:32","modified_gmt":"2018-09-11T16:14:32","slug":"how-to-migrate-your-magento-extension-to-magento-2","status":"publish","type":"post","link":"https:\/\/www.recolize.com\/en\/blog\/how-to-migrate-your-magento-extension-to-magento-2\/","title":{"rendered":"How to Migrate your Extension to Magento 2?"},"content":{"rendered":"<section class=\"section  text-normal section-text-no-shadow section-inner-no-shadow section-normal section-opaque\"  >\n    \n    <div class=\"background-overlay grid-overlay-0 \" style=\"background-color: rgba(0,0,0,0);\"><\/div>\n\n    <div class=\"container container-vertical-default\">\n        <div class=\"row vertical-default\">\n            <div class=\"col-md-12     text-default small-screen-default\"  ><div class=\"col-text-1 text-normal  element-top-20 element-bottom-20\" data-os-animation=\"none\" data-os-animation-delay=\"0s\">\n    <p>In this blog post I will show you a sample how to port your existing Magento 1 extension to the brand-new Magento 2 based on <a href=\"https:\/\/github.com\/Recolize\/recommendation-engine-magento2\">our Recolize Recommendation Engine extension for Magento 2<\/a>.<!--more--><\/p>\n<p>While Magento 2 was publically released in December 2015 more and more extension providers are migrating their extension to the new platform. As the whole architecture of Magento 2 is different than in the first version the steps required for making the extension compatible with the new Magento version differ a lot from extension to extension depending on the complexity and used parts of the Magento system.<\/p>\n<p>Most of the steps described here are taken from these sources:<\/p>\n<ul>\n<li><a href=\"http:\/\/devdocs.magento.com\/\">Official documentation<\/a><\/li>\n<li><a href=\"http:\/\/alanstorm.com\/category\/magento-2\" target=\"_blank\" rel=\"noopener\">Alan Storm&#8217;s Blog<\/a><\/li>\n<li><a href=\"https:\/\/maxyek.wordpress.com\/2015\/04\/03\/building-magento-2-extension-extendedconfig\/\" target=\"_blank\" rel=\"noopener\">Blog of Max Yekaterynenko<\/a><\/li>\n<\/ul>\n<p>(Generally for sources on the web it is important to look at the creation date as a lot has changed since the first official Magento 2 beta version.)<\/p>\n<h3>0. General hints<\/h3>\n<p>Magento 2 now has a nice command line tool <em>bin\/magento<\/em>\u00a0(comparable to the well-known\u00a0<em>n98-magerun<\/em> in Magento 1) which offers lots of cool commands.<\/p>\n<p>Assure to set the Magento 2 Developer mode as described <a href=\"http:\/\/devdocs.magento.com\/guides\/v2.0\/config-guide\/cli\/config-cli-subcommands-mode.html\">here\u00a0<\/a>with<\/p>\n<\/div>\n<div class=\" element-top-20 element-bottom-20\" data-os-animation=\"none\" data-os-animation-delay=\"0s\">\n    <pre>bin\/magento deploy:mode:set developer<\/pre>\n<\/div><div class=\"col-text-1 text-normal  element-top-20 element-bottom-20\" data-os-animation=\"none\" data-os-animation-delay=\"0s\">\n    <p>as well as to disable the Full Page Cache (FPC). This assures that e.g. static files are not cached which makes developing extensions a lot easier.<\/p>\n<p>Magento 2 now ships with XSD files to validate your XML files. This can be integrated directly into PHPStorm which is a very handy feature. Just execute the following command (see <a href=\"http:\/\/magento.stackexchange.com\/questions\/88242\/magento-2-xml-validation\">here<\/a>):<\/p>\n<\/div>\n<div class=\" element-top-20 element-bottom-20\" data-os-animation=\"none\" data-os-animation-delay=\"0s\">\n    <pre>bin\/magento dev:urn-catalog:generate .idea\/misc.xml<\/pre>\n<\/div><div class=\"col-text-1 text-normal  element-top-20 element-bottom-20\" data-os-animation=\"none\" data-os-animation-delay=\"0s\">\n    <p>Please note that there are also automatic converting solutions like the <a href=\"https:\/\/github.com\/unirgy\/convertm1m2\" target=\"_blank\" rel=\"noopener\">Unirgy Magento 2 Converter<\/a>\u00a0but we will do that manually for sample reasons.<\/p>\n<p>&nbsp;<\/p>\n<p>The required steps for migrating the extension are:<\/p>\n<ol>\n<li>Create a skeleton Magento 2 extension<\/li>\n<li>Migrate system settings, localizations<\/li>\n<li>Migrate extension template stuff<\/li>\n<li>Migrate extension product feed generation logic<\/li>\n<\/ol>\n<h3>1. Create the skeleton Magento 2 extension<\/h3>\n<p>As the whole architecture and therewith also the file structure is different from Magento 1 it is advisable to create a completely new extension package.<br \/>\nThe basic file structure looks like as follows:<\/p>\n<\/div>\n<div class=\"figure element-top-20 element-bottom-20  \" data-os-animation=\"none\" data-os-animation-delay=\"0s\">\n            <a href=\"https:\/\/www.recolize.com\/wp-content\/uploads\/2017\/11\/magento2_module_directory_structure.png\" class=\"figure-image magnific\" target=\"_self\">\n        <img width=\"291\" height=\"300\" src=\"https:\/\/www.recolize.com\/wp-content\/uploads\/2017\/11\/magento2_module_directory_structure-291x300.png\" class=\"attachment-medium size-medium\" alt=\"\" decoding=\"async\" loading=\"lazy\" srcset=\"https:\/\/www.recolize.com\/wp-content\/uploads\/2017\/11\/magento2_module_directory_structure-291x300.png 291w, https:\/\/www.recolize.com\/wp-content\/uploads\/2017\/11\/magento2_module_directory_structure.png 522w\" sizes=\"(max-width: 291px) 100vw, 291px\" \/>            <\/a>\n    <\/div>\n<div class=\"col-text-1 text-normal  element-top-20 element-bottom-20\" data-os-animation=\"none\" data-os-animation-delay=\"0s\">\n    <p>After creating the basic file structure you can execute<\/p>\n<\/div>\n<div class=\" element-top-20 element-bottom-20\" data-os-animation=\"none\" data-os-animation-delay=\"0s\">\n    <pre>bin\/magento module:enable &amp;amp;&amp;amp; bin\/magento setup:upgrade<\/pre>\n<\/div><div class=\"col-text-1 text-normal  element-top-20 element-bottom-20\" data-os-animation=\"none\" data-os-animation-delay=\"0s\">\n    <p>and the extension is now installed which you can easily verify by visiting the Admin panel <em>Stores &gt; Configuration &gt; Advanced &gt; Advanced<br \/>\n<\/em><strong>Yes!<\/strong><\/p>\n<h3>2. Migrating system settings<\/h3>\n<p>This task means mainly converting the old <em>system.xml<\/em> file into the new Magento 2 XSD format. As you can see from the picture below that shows the comparison between old and new format the changes can easily be understood:<\/p>\n<\/div>\n<div class=\"figure element-top-20 element-bottom-20  \" data-os-animation=\"none\" data-os-animation-delay=\"0s\">\n            <a href=\"https:\/\/www.recolize.com\/wp-content\/uploads\/2017\/11\/magento2_system_xml_differences.png\" class=\"figure-image magnific\" target=\"_self\">\n        <img width=\"150\" height=\"150\" src=\"https:\/\/www.recolize.com\/wp-content\/uploads\/2017\/11\/magento2_system_xml_differences-150x150.png\" class=\"attachment-thumbnail size-thumbnail\" alt=\"\" decoding=\"async\" loading=\"lazy\" srcset=\"https:\/\/www.recolize.com\/wp-content\/uploads\/2017\/11\/magento2_system_xml_differences-150x150.png 150w, https:\/\/www.recolize.com\/wp-content\/uploads\/2017\/11\/magento2_system_xml_differences-600x600.png 600w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/>            <\/a>\n    <\/div>\n<div class=\"col-text-1 text-normal  element-top-20 element-bottom-20\" data-os-animation=\"none\" data-os-animation-delay=\"0s\">\n    <p>For localization files it&#8217;s even easier as you only have to move them to the <em>i18n<\/em> folder.<\/p>\n<h3>3. Migrating extension logic<\/h3>\n<p>Next step is to migrate the existing logic from our Magento 1 extension.<br \/>\nBasically our Recolize Recommendation Engine extension does the following to major things:<\/p>\n<ol>\n<li>Add the layout handles for integrating our JavaScript snippet and the Recolize JavaScript parameters on special pages like cart, product detail page, etc.<\/li>\n<li>Update the user information in the cookie on login\/logout.<\/li>\n<li>Periodically generate the product feed (see chapter 4).<\/li>\n<\/ol>\n<p>As these migration tasks are very specific to <a href=\"https:\/\/marketplace.magento.com\/recolize-recolize-recommendation-engine.html\">our Recolize Magento extension<\/a>\u00a0it&#8217;s up to the reader to check out the necessary steps and differences with Magento 1.<\/p>\n<h3>4. Migrate extension product feed generation<\/h3>\n<p>In Magento 1 we relied on the Magento default Dataflow extension to generate our product export feed because there many flaws have already been implemented and made some customizations (see <a href=\"https:\/\/www.recolize.com\/en\/blog\/2015\/08\/04\/magento-tutorial-export-complete-image-urls-and-category-names-with-a-custom-dataflow-mapper\/\" target=\"_blank\" rel=\"noopener\">my earlier post about Dataflow customizations<\/a>).<\/p>\n<p>As Magento 2 only ships with the <em>ImportExport<\/em> module and that functionality is very limited we decided to implement our own feed generation methods. But that&#8217;s part of another blog post..<\/p>\n<p><strong>And basically that&#8217;s it!<\/strong> As you can see for simple extensions like ours that do not go deep into the Magento internals it is mostly re-writing some XML stuff into the new format and adapting to the new dependency injection logic.<\/p>\n<p>Now it&#8217;s time to try out yourself. See <a href=\"https:\/\/github.com\/Recolize\/recommendation-engine-magento2\">our Recolize Magento 2 extension<\/a> for a sample.<\/p>\n<\/div>\n<\/div>        <\/div>\n    <\/div>\n<\/section>\n\n","protected":false},"excerpt":{"rendered":"<p>In this blog post I will show you a sample how to port your existing Magento 1 extension to the brand-new Magento 2 based on our Recolize Recommendation Engine extension for Magento 2.<\/p>\n","protected":false},"author":3,"featured_media":2033,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[146,40],"tags":[],"_links":{"self":[{"href":"https:\/\/www.recolize.com\/en\/wp-json\/wp\/v2\/posts\/2497"}],"collection":[{"href":"https:\/\/www.recolize.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.recolize.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.recolize.com\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.recolize.com\/en\/wp-json\/wp\/v2\/comments?post=2497"}],"version-history":[{"count":14,"href":"https:\/\/www.recolize.com\/en\/wp-json\/wp\/v2\/posts\/2497\/revisions"}],"predecessor-version":[{"id":4206,"href":"https:\/\/www.recolize.com\/en\/wp-json\/wp\/v2\/posts\/2497\/revisions\/4206"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.recolize.com\/en\/wp-json\/wp\/v2\/media\/2033"}],"wp:attachment":[{"href":"https:\/\/www.recolize.com\/en\/wp-json\/wp\/v2\/media?parent=2497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.recolize.com\/en\/wp-json\/wp\/v2\/categories?post=2497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.recolize.com\/en\/wp-json\/wp\/v2\/tags?post=2497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}