I have never used a programming framework seemingly designed to frustrate the development process as much as Magento 2. You have to constantly clear caches and static files to see your modifications, even when in developer mode.
Having recently started work on learning the ropes with Magento 2, and finding all sorts of oddities, incongruities and banging-head-on-desk-ities, I decided to take a look at the blog of Alan Storm at alanstorm.com.
After renaming a custom Magneto 2 theme folder, to correct a capitalisation mistake, I ran into all sorts of issues, starting with this error:
Required parameter ‘theme_dir’ was not passed
After reading around I removed the entry from the database table “themes” and tried to set any pages or stores set to use that theme to use something else. Then I endlessly got this:
Error – Exception #0 (LogicException): Unable to load theme by specified key: ‘4’
M2 utilises CLI (command line interface) commands heavily from using composer to install modules and keep things updated to clearing the cache, switching in and out of production mode and that sort of thing. This is very new for a Magento 1 developer like myself so it is time to start documenting all of this. Here is a list of the all the standard bin/magento commands, plus a few extra bits and pieces that have proved useful.
So, one day, I noticed one of my servers was sending a ton of emails out to dodgy looking ….@mail.ru or ….@list.ru addresses. UH OH!
At first I thought the mail server on my webserver had been compromised. On further investigation I managed to see to that the contents of these mails were account registration validation emails. Looking in the Magento admin (Customers>Manage Customers) I saw them…thousands of new customer registrations – with Russian copy in the name fields and, on the whole [something]@mail.ru or [something]@list.ru addresses but also some with [something]@gmail.com.
To write information to your own custom log file, say to trace errors in a custom module, track odd behaviour or record that a certain event has happened, you use Mage::log()
Mage::log(‘<WHAT TO WRITE IN THE LOG>’, null, ‘FILENAME.log’, true);
If you want to log the output of an array, use print_r but with the second parameter set to true – this converts the output to a string.
e.g. Mage::log(print_r($myArray,true), null, ‘FILENAME.log’, true);
I hope this is helpful. If it has and has saved you some time, feel free to buy me a beer.
I think custom variables were originally designed to be used in emails but I use them within the main site for little bits of information whose value needs to change on a per store/language basis.
This is how you get a custom variable inside a phtml file:
You may well have certain pages that you do not want Google, et al, to index in the SERPS. Examples include log in pages, thank you pages, and perhaps content of little search value such as legal blurb. This can let you control a little more, albeit very slightly, the pages you want Google to show and those that you don’t.
You can use the Custom Layout Update control (in the Custom Design tab) to set the robots control on a per-page basis. Simply add the following code into the Custom Layout Update textarea in the Magento admin:
Some useful bits and bobs to do with ordering, size-limiting and getting data out of collections that I tend to often need to look up.
Limiting the Size of a Collection
Adding isActiveFilter
Loading Friendly URLs/Rewrites
Filter Collection by Attribute and Conditionals List
Get First Item From Collection
This website uses cookies to improve your experience and so I can see what articles you like best. I assume you're ok with this, but you can opt-out if you wish.AcceptRead More