Magento 2 Snippets

Published on 02 Jun 2016 , edited on 01 Apr 2019

In it’s complexity I find one can lose a lot of time in just looking for the right mark-up for the right situation. That’s why I decided to make this little ‘scrap-book’ of snippets.

Overwriting files

Overwriting files in Magento 2 isn’t as straightforward as was with Magento 1. There you just had to have the same path and you’re done. In Magento 2, this is a bit different.
Take a look at these examples and try to see the pattern:

Source
/vendor/magento/module-theme/view/frontend/templates/html/header.phtml
Goal
/app/design/frontend/${VENDORNAME}/${THEMENAME}/Magento_Theme/templates/html/header.phtml

Source
vendor/magento/module-theme/view/frontend/templates/html/topmenu.phtml
Goal
app/design/frontend/${VENDORNAME}/${THEMENAME}/Magento_Theme/templates/html/topmenu.phtml

Source
/vendor/magento/module-catalog/view/frontend/templates/category/image.phtml
Goal
app/design/frontend/${VENDORNAME}/${THEMENAME}/Magento_Catalog/templates/html/topmenu.phtml

Source
/vendor/magento/module-catalog/view/frontend/templates/category/image.phtml
Goal
app/design/frontend/${VENDORNAME}/${THEMENAME}/Magento_Catalog/templates/html/topmenu.phtml

User management

For some reason I forget my password every single f%&*@Q!ng time I try to login to my testenviorment, despite having a password manager and already 2 admin accounts because of this. This oneline adds a new admin user to login with and update the password for the ‘regular’ one. Ofcourse, delete this user afterwards.

magento admin:user:create --admin-user bert --admin-password bert01234 --admin-email bert@bert.nl --admin-firstname bert --admin-lastname bert

Module management

Install module via composer

composer require <component-name>:<version>
magento module:status
magento module:enable <modulename> --clear-static-content
magento setup:upgrade
magento setup:di:compile
magento cache:clean

Snippets

Short notes and snippets as reminders for myself and my work.

All categories

All tags

All posts