So I recently started looking in detail at Magento 2. I built 1 extension, that was fine. But then I wanted to migrate a much larger one. How to do this? I’ve learned a lot. Here are my 2 top tips.
Tip 1 – Throw away your Code
Accept you are going to throw away what you have if its a large extension.
Trying to migrate a large extension to Magento 2 is nigh on impossible. If you were a super programmer before and have a wonderful ‘separation of concerns’ then you may have some hope, but seriously once I decided that I couldn’t just port it life became a lot easier. Start again time.
What I’ve done is lifted out the MVP extn. Then focused on that.
Tip 2 – Copy Copy Copy
What is in 1.x is in 2.x but differently structured. Its all there. Clearly they have a tool to convert the code, this was not done manually (if it was no wonder it took 5 years!).
If you have an extension you need to go setup all your constructors, remove all the references to Mage::. Its daunting. What I’ve found is that reverting to the 2008 perspective of find and copy actually isn’t too bad an idea. Because the more you look at the Magento 2 core code the more you start to understand, and the more you code the more the various blogs make sense.
What I’ve done is got 2 PHPStorm windows open, one with 1.x and one with 2.x. I’m basically searching for similar functionality to what is going on in the extension in the core code. Then COPYING it.
That’s it. There is no greater act than doing IMO.
Now who was that annoying person that said copying was bad.