Strategic Growth and Marketing Blog
Magento’s Core JSON Encoding and Decoding Functions
To JSON encode an array [php] $jsonData = Mage::helper(‘core’)->jsonEncode($array); [/php] To JSON decode an array [php] $array = Mage::helper(‘core’)->jsonDecode($jsonData); [/php]
Magento – How to Check if a Module is Installed and is Active
While developing Magento websites, you might wish to check to find out if a module is installed before proceeding to use that module’s functions. You can do so by using…
Magento – Product Attributes of Products in the Cart
The following piece of code can pull any attribute of the products in the shopping basket. This code can be used anywhere on the website. [php] /* Get all the…
Magento – Setting Robots (Index Follow) Using XML Layout Updates
[xml] <reference name=”head”> <action method=”setRobots”><value>NOINDEX,NOFOLLOW</value></action> </reference> [/xml]
Magento – Programmatically Subscribe and Unsubscribe Newsletter Subscribers
The following can be a handy snippet. Its usage and placement is totally up to your imagination and requirements. [php] /* To Subscribe */ Mage::getModel(‘newsletter/subscriber’)->subscribe(‘[email protected]’); /* To Unsubscribe */ Mage::getModel(‘newsletter/subscriber’)->loadByEmail(‘[email protected]’)->unsubscribe();…
Adding an Image Upload Field to the Magento System.xml Configuration
[xml] Logo Allowed file types: jpeg, gif, png. image adminhtml/system_config_backend_image theme theme 1 1 1 1 [/xml] The element represents the location where the image will be uploaded to. In…
Magento – Get the Chosen Configuration / Options of the Products in the Cart
A Magento client of mine wanted to be able to change the calls to action on the cart and checkout pages based on the product configuration that the customers have…
Magento – Inject Body Class via Layout XML
This is an XML piece that has helped me many times. I might wish to style a page or product using a global body level class. In such a case,…
Magento – Set Breadcrumbs via Layout XML
I have used this XML in custom modules and custom pages. It comes handy to pass the Breadcrumb information to Google. [xml] <reference name=”breadcrumbs”> <action method=”addCrumb”><crumbName>Home</crumbName><crumbInfo><label>Home</label><title>Home</title><link>/home</link></crumbInfo></action> <action method=”addCrumb”><crumbName>Sample Form</crumbName><crumbInfo><label>Sample Form</label><title>Sample…
Magento – Set Meta Title, Description, Keywords and Canonical URL via Layout XML
This handy XML can be used anywhere – your custom modules, CMS pages, product pages, etc. [xml] <reference name=”head”> <action method=”setTitle” translate=”title” module=”forms”><title>Title</title></action> <action method=”setDescription” translate=”title” module=”forms”><title>Description</title></action> <action method=”setKeywords” translate=”title”…
Add a Layout Select Field to the Admin Form of Magento Custom Modules
I am coding a bespoke CMS feature for a Magento project. I wanted the client to be able to change the template / layout of each page. This is similar…
Magento – Adding Canonical URL for CMS Pages via Layout XML
Magento does not automatically add canonical URLs for CMS pages. Maybe they will add this feature in the future. However, if you are setting up pages and wish to add…