Development How Tos

PHP Array Delete

Nov 25, 2011

Can PHP really be missing a way of deleting items from an array based on the key? Seems so, so here am am just sharing a snippet of code that lets you do just that. This function will work with any number of array keys and does some clever shunting around with the array_flip and array_slice functions. // utility to remove array items from the key function array_remove_key() { $args = func_get_args(); return array_diff_key($args[0],array_flip(array_slice($args,1))); } // usage...

Custom Contact Form In Magento

Aug 30, 2011

The standard Magento contact form is built into the Magento framework and doesn’t allow for admins to manage the content, this article describes your options for managing content on the contact page as well as maintaining multiple contact forms and customising their fields. The normal contact form is a core piece of functionality within Magento and there are several options for customizing it. Adding a static block to the contact form The simplest requirement to fulfil is being able to add content above or below the form containing an introduction, title and alternative contact options such as address and email information.

Set “ship to this Address” the default in your Magento checkout

Aug 26, 2011

For some reason the Magento checkout sets the “Ship to different address” as the default option even though far more people actually want items delivered to their billing address. This quick tutorial explains how to change this default. The first stage in making this change is to override the default Magento class that handles the checkout. You do his by simply copying the class file from the core folder into the local code folder.

SSL Warning on Magento with Facebook Like

Aug 18, 2011

The standard Facebook like button uses HTTP as the protocol for loading the Facebook JavaScript. This means you may receive SSL warnings to do with insecure items being on the page when viewing the SSL parts of your Magento site such as the checkout and the user account pages. To solve this problem you simply need to include the Facebook script using HTTPS – since Facebook also support the SSL version.

Guernsey & Jersey GST/VAT Rates in Magento

Aug 17, 2011

Guernsey and Jersey in the Channel Islands have independent tax rules from the UK and require some special processing in a Magento eCommerce website – here is how to go about it. First of all lets look at the sales tax rules in these three jurisdictions. UK sales tax or VAT (value added tax) is currently charged at 20% and needs to be applied to all orders payed for/delivered to the UK.

Setting new orders to Complete (or any other status) in Magento

Aug 4, 2011

Magento brilliantly provides a configuration option for each of the built-in payment methods to allow you to set the orders status – unfortunately by default the only option you can pick is pending. Each of Magento’s payment methods are created by the core payment module or as their own modules such as paypal – you can find the core methods in the folder app/code/core/Mage/Payment. If you take a look in the system.xml configuration file – inside the etc folder then you will find some way down the field definition for the new order status field that you see in the admin.

Setting Up Tax In Magento

Jul 19, 2011

As with most things in Magento the configuration of tax is extremely thorough and flexible – but you do have to think a little bit to set it all up, here is a quick guide to doing just that. Configuration First take a look at the System->Configuration options for VAT under the sales section. Here we have loads of options for how the tax should be applied to order and defaults to use before we actually know where the customer is ordering from or delivering to.

Using Layout Update XML in Magento

Jun 19, 2011

The Magento Designer’s Guide has the following short intro about layout XML and I think it explains it quite well, although I will go through some more detail with examples afterwards. Layout is a virtual component of the Magento application. By modifying the components of layout, you can build your store page in an upgrade-compatible way. Layout is comprised of default layout and layout updates that are made up of easy-to-learn XML tags.

Don’t Make Your Ruby App a Gem as an Afterthought – Do it Now!

Jun 9, 2011

I have been working with Ruby and independently with Ruby on Rails for a few years now and although I am really familiar with Gems I have managed to avoid ever creating one myself – recently I had to convert an existing project to a gem and I realise how foolish I was not to “gemify” it from day one. I’m going to talk through the process I went through to help anyone in a similar situation out, but mostly to persuade you to create things as Gems from the start of the project.

Display your Magento store address (from the configuration)

Jun 6, 2011

Magento lets you enter your store address directly into the configuration settings – here is the code snippet to display that in one of your Magento Templates. First of all the setting is found in the system-Configuration page under General – Shop Information. Obviously you can vary this for different Store Views etc. Here is a quick screenshot to make sure you are in the right place… Configuration General-Shop->Information” src=“/wp-content/uploads/2011/06/Mageno-System-Configuration-General-Shop-Information-575x212.png” alt=“Magento System->Configuration General-Shop->Information” width=“575” height=“212” /> the code to then display this in one of your templates is then a one line snippet of PHP… echo Mage::getStoreConfig('general/store_information/address'); You probably want to display on multiple lines – by default this will just include line breaks that will then be ignored in HTML.