Magento Allow Customers to Switch Between Mobile and Desktop Themes

In this post I’ll cover how to create a basic theme switcher for switching between mobile and desktop themes in Magento. The basic steps for the theme switcher are as follows: Customer clicks ‘switch to desktop site’ link Cookie is set saying the user has requested the desktop theme The cookie is detected and the correct user agent is set in index.php. By using a cookie we can make the selection persistent so customers don’t need to click this link each time they visit the site. Read On →

Doctrine Create New Entity From Legacy Database Shell Script

Here is a nice little script I have just written to help me with migration of a legacy application onto a Symfony based architecture, including Doctrine for entities. In this scenario I have created a new database and am importing tables across from the legacy database as I bring them into the application. The process is a little tricky and unfortunately I figured it out, then went on holiday and came back having totally forgotten how to do it. Read On →

Magento 2 SSH Library

One of the composer dependcies in Magento 2 is phpseclib. This means for integrations using ssh you can use this instad of needing the php ssh module for your integration you can use this module. To run a remote ssh command you can use the following snippet as an example for either the straight echo or the callback way of dealing with the result: use phpseclib\Net\SSH2; $ssh = new SSH2('my-ssh-server.com'); Read On →

Magento 2 Controller Output Types

Magento 2 now introduces the Framework result object for handing requests that will handling non page results such as JSON, redirects and other non html returns. So to use the result factory in your controller in your controller construct simply have the following code: $this->resultFactory = $context->getResultFactory(); Then in the run method simply write the following: $result = $resultRedirect = $this->resultFactory->create($type); So the type value has to be one of the following constants: \Magento\Framework\Controller\ResultFactory::TYPE_JSON \Magento\Framework\Controller\ResultFactory::TYPE_RAW \Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT \Magento\Framework\Controller\ResultFactory::TYPE_FORWARD \Magento\Framework\Controller\ResultFactory::TYPE_LAYOUT \Magento\Framework\Controller\ResultFactory::TYPE_PAGE JSON This is for returning a JSON object from a controller with the correct mime type in the response. Read On →

Ssh Copy Id As Another User in Bash

Here is a nice BASH one liner that will allow you as (presumably root) copy another users SSH keys up to a server. This is ideal for setting up multiple users on a machine as the root user in bulk as part of a batch process. Ideally you will have already added the server to your ssh_config file so that ports, users etc do not need to be specified and also you have run ssh-copy-id serverName as root so that you no longer have to set any passwords. Read On →

Fixing Logrotate Rotating Its Own Files

From time to time I come across a server that has had logRotate setup in such a way that it is rotating its own files creating hundreds of copies and increasing disk usage rather than controlling it This is caused by a misconfiguration of the logrotate config file. The file that is causing the problems can normally be found be running the following command user@host$ grep '*' /etc/logrotate.d/* /etc/logrotate.d/misconfiguredFile:/path/to/logs/* { Which should display all of the paths that include a wild card that are being checked and rotated. Read On →