Magento Connect File Permissions

Downloading extensions using the web based Magento Connect manager requires the directories and files to be writable. SSH into the root directory of the Magento installation and execute the following.

find . -type d -exec chmod 777 {} ;

Once complete, reset by issuing the following via SSH when running php as a module.

find . -type f -exec chmod 644 {} ;
find . -type d -exec chmod 755 {} ;
chmod o+w var var/.htaccess includes includes/config.php app/etc
chmod 550 pear
chmod 550 mage #for magento 1.5+
chmod -R o+w media

Instructions are valid for version 1.5 upwards.

Less secure | More secure 

 

Editing the Magento local.xml

Rather than edit the layout xml files and risk problems during an upgrade, it’s best to use local.xml in your design package default directory. The first use of this file is to prevent blocks from appearing. Simply add the following code with the relevant block listed.

<?xml version="1.0" ?>
 <layout>
  <default>
   <remove name="left.permanent.callout" /> <!--the dog-->
   <remove name="right.permanent.callout" /> <!--back to school-->
   <remove name="catalog.compare.sidebar" /> <!--product compare-->
   <remove name="paypal.partner.right.logo" /> <!--paypal logo-->
   <remove name="cart_sidebar" /> <!--cart sidebar-->
   <remove name="left.reports.product.viewed" /> <!--recently viewed prod-->
   <remove name="right.reports.product.viewed" /> <!--recently viewed prod-->
   <remove name="right.reports.product.compared" /> <!--recently compared prod-->
  </default>
 </layout>

You can find the names of the blocks by viewing the appropriate xml file. To find the xml file, turn on the developer hints and look at the directory listed after the template directory. This is the xml file. Locate this in your base package and note the names of the blocks you want to prevent from appearing.

Here’s an example from classyllama.com:

<?xml version="1.0"?>
<layout version="0.1.0">

<default>

	<reference name="head">
		<!-- Magento looks in /skin/frontend/<INTERFACE>/<THEME>/js/buyprinting.js for this file -->
		<action method="addItem"><type>skin_js</type><name>js/buyprinting.js</name></action>

		<!-- This removes the item that was set in the page.xml file -->
		<action method="removeItem"><type>skin_js</type><name>js/iehover-fix.js</name></action>

		<!-- Magento looks in /js/prototype/element.storage.js for this file -->
		<action method="addJs"><name>prototype/element.storage.js</name></action>

		<action method="addCss">
<stylesheet>css/buyprinting.css</stylesheet></action>
	</reference>

	<reference name="header">
		<!-- This adds a CMS block that can be called from the template file
		associated with the header block. -->
		<block type="cms/block" name="cms_quick_help">
			<action method="setBlockId"><block_id>quick_help</block_id></action>
		</block>

		<!-- The remove tag removes the blocks with the specified name from the layout -->
		<remove name="top.menu"/>
		<remove name="store_language"/>
		<remove name="breadcrumbs"/>
	</reference>

	<reference name="top.nav">
		<remove name="catalog.topnav"/>
	</reference>

	<reference name="left">
		<remove name="left.newsletter"/>
		<remove name="left.permanent.callout"/>
		<remove name="catalogsearch.leftnav"/>

		<!-- When you use the remove tag, it removes any blocks with the specified name from
			the entire layout, regardless of the context. So, if I remove right.newsletter in
			the <default> context and that name is used in say the <catalog_product_view> context,
			then both blocks will be removed.  Because remove operates on the global context,
			you can only remove an element once.  Since <remove name="right.newsletter" /> is
			being called in catalogsearch.xml, we have to unset it, or else we'll get an error.

			The line below only unsets the block from the parent's context, not the global
			layout context -->
		<action method="unsetChild"><name>right.newsletter</name></action>
	</reference>

	<reference name="right">
		<!-- Some blocks have to be removed using remove, others via unsetChild.
			I've not spent the time digging into the code to figure out why -->
		<remove name="right.permanent.callout"/>
		<remove name="catalog.compare.sidebar"/>
		<remove name="left.reports.product.viewed"/>
		<action method="unsetChild"><name>sale.reorder.sidebar</name></action>
		<action method="unsetChild"><name>wishlist_sidebar</name></action>
		<action method="unsetChild"><name>right.reports.product.viewed</name></action>
		<remove name="cart_sidebar"/>
	</reference>

</default>

<!-- CATALOG PAGES -->
	<catalog_product_view><!-- 2columns-right -->
		<reference name="root">
			<action method="setTemplate"><template>page/2columns-left.phtml</template></action>
		</reference>
		<reference name="content">
			<reference name="product.info">
				<block type="cms/block" name="cms_product_info_tabs">
					<action method="setBlockId"><block_id>product_info_tabs</block_id></action>
				</block>
				<block type="catalog/product_view" name="product.clone_prices" as="prices" template="catalog/product/view/price_clone.phtml"/>
				<action method="unsetChild"><name>tierprices</name></action>
				<action method="unsetChild"><name>addto</name></action>
				<remove name="addto"/>
				<reference name="product.info.options.wrapper.bottom">
					<action method="unsetChild"><name>product.tierprices</name></action>
				</reference>
			</reference>
		</reference>
	</catalog_product_view>

</layout>

Relative URLs in Magento

Rather than hard code urls in static blocks whenever possible you should use the Magento code to generate relative urls. All you need to do is add the following into your anchor tag and change page to the name of the page you want to link to. Magento will do the rest.

<a href="{{store url="page"}}>Page</a>
<a href="{{store direct_url="page.html"}}>Page</a>
<a href="{{store url="page" _query="a=param_a&b=param_b"}}>Page</a>
For more on urls go to: http://magebase.com/magento-tutorials/quick-tip-using-the-store-template-directive-in-magento/.

Magento File Permissions

When installing a new version of Magento it’s necessary to reset the permissions on some directories and files. This explains which to reset for version 1.6.1.0.

The /media and /var directories should be writable at group level and so need to be reset to 755. The /media directory contains web accessible files such as images, while the /var directory is used for temporary files used by the cache and for sessions as well as import/export files. Note that it is only the directories that need to be writable, not the files. You’ll need to do a recursive edit to all directories within these.

Additionally, on doing the 1.6.1.0 installation specific files cropped up as requiring to be writable. Directories change from 755 to 775 and files change from 644 to 664. You need to return these to their original values after installation for security reasons.

/var/www/vhosts/domain/httpdocs/magento/media/
/var/www/vhosts/domain/httpdocs/magento/var/
/var/www/vhosts/domain/httpdocs/magento/media/xmlconnect/custom/ok.gif
/var/www/vhosts/domain/httpdocs/magento/media/xmlconnect/system/ok.gif
/var/www/vhosts/domain/httpdocs/magento/media/xmlconnect/original/ok.gif
/var/www/vhosts/domain/httpdocs/magento/var/package/Mage_Core_Modules-1.6.1.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Lib_Js_Ext-1.6.0.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Interface_Frontend_Base_Default-1.6.1.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Lib_Js_TinyMCE-3.3.7.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Interface_Install_Default-1.6.1.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Lib_ZF_Locale-1.11.1.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Lib_Js_Calendar-1.51.1.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Mage_Downloader-1.6.1.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Lib_Js_Prototype-1.7.0.0.2.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Interface_Frontend_Default-1.6.0.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Mage_All_Latest-1.6.1.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Magento_Mobile-1.6.0.0.22.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Mage_Locale_en_US-1.6.1.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Mage_Compiler-1.6.0.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Lib_LinLibertineFont-2.8.14.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Lib_ZF-1.11.1.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Lib_Mage-1.6.1.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Mage_Centinel-1.6.1.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Lib_Google_Checkout-1.5.0.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Phoenix_Moneybookers-1.3.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Lib_Varien-1.6.1.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Mage_Core_Adminhtml-1.6.1.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Interface_Adminhtml_Default-1.6.1.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Lib_Js_Mage-1.6.1.0.xml
/var/www/vhosts/domain/httpdocs/magento/var/package/Lib_Phpseclib-1.5.0.0.xml

To use MagentoConnect for an install write permissions need to be applied to all magento files including the root Magento directory. All files and folders need to be reset to 655 after installation.

Installing from shell is advisable. For instructions go to http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/magento_filesystem_permissions.

Switching Broadband

This is a minefield. There are many companies offering many deals, many of which require considerable analysis to understand how much they cost. While not as impenetrable as the average gas/electricity provider, they do come a close second.

I hadn’t really bothered going through the data since signing up to an 18-month contract with Virgin Media. However, that came to an end last month and being on a 30-day notice rolling contract it makes sense to start seeing what benefit changing provider may bring.

Additionally, a fter having horrendous problems with VirginMedia over the last 8 weeks getting 0.28Mbps on the worst day, and spending well over 6 hours on the phone to them, I managed to get an engineer out who switched the router/modem. All’s well so far but the experience

Being of limited time, I’m not about to wade through price comparison sites and individual providers given. The former rarely tells me all the information I want and also normally servers to confuse, particularly when you don’t know if they have got all providers in there and whether any data is being presented in a less than fair way.

Provider’s sites would help but having spent 2 hours going through one it’s too much effort to go through many more in the same way, when generally the two main providers, BT and Virgin Media pretty much provide the best deals … for what I’m after anyway.

The requirements are simply:

  • 10-20Mbps
  • 40GB minimum usage
  • phone line
  • Standard TV or Freeview

So, I went through BT’s packages and worked out what the deals are. It looks like BT is £5 a month cheaper and with BT Infinity soon to be available in my area the 20Mbps+ speeds will soon be available.

This is taking advantage of the BT TV Essential and Evening & Weekend Calls package (£22/mo plus calls for first 4 months plus setup fee £36) and then moving to More Broadband and Calls with BT Infinity in January 2012 (£27/mo plus calls plus activation fee £25). This does require paying the phone line for the full 12 months (£120 instead of £166.90).

When I put this to Virgin Media their only response was essentially you’ll have to pay more to get the same level. Time to seriously consider jumping ship, unless of course BT horror stories put me off …

Create WordPress Short Code

To create a shortcode for html add the function into functions.php. Then add the style to style.css. Here’s an example:

For functions.php

function codetext_shortcode( $atts, $content = null ) {
   return '<div class="codetext">' . $content . '</div>';
}
add_shortcode('codetext', 'codetext_shortcode');[/codetext]

For style.css

.codetext {
 font-family: "courier new";
 font-size: 0.8em;
 color: #333;
 padding: 10px 0 20px 0;
 }

Magento Category Page Image Resize

You may want to increase the size of the images shown on the category pages of your Magento theme. To do so open list.phtml in

app/design/frontend/yourpackage/yourtheme/template/catalog/product/
. Search for the code below and edit the sizes listed.

<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(225, 225); ?>” width="225" height="225" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>” title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>” />

In praise of The Walking Dead

Back in about 1981 I went round to my neighbour’s house to watch a video. We didn’t have a video player at ours – just the standard four push-button TV, and yes, that means the four channels – and watching a video felt somewhat exotic. So, around I go. Excitedly, my next-door neighbour slots a video into the player and we settle back to watch Dawn of the Dead.

Now, being 9-10 years old and unused to watching anything scarier than Scooby-Doo the film imprinted a marked impression on me. One that remained every night for about 4 weeks, truth be told. The one scene that I can never shake from my memory is when the pilot is trapped in the lift and a zombie takes a chunk out of his neck as if biting into a large over-ripened apple. The whole film scared the hell out of me but I watched it through. I really thought zombies were real for the next month or so.

So, fast-forward 30 years and I’m back watching zombies for grown-ups. There are backstories to the characters. There’s a Lost like strangeness with characters dreaming the future (admittedly I only watched three episodes of Lost before I gave up). There are characters with flaws; characters with a backbone so rigid you could strap any number of poles to it and sail it down a river; rednecks spoiling for a fight; distant philosophical types who perch on caravans staring into the sky, or perhaps looking for zombies; and, of course, characters who get chunks bitten out of their necks, and arms, and legs. Hooray!!

I caught myself comparing this to the recent BBC sci-fi drama that was Outcasts, you remember, the one you watched right to the bitter end in the vain hope that it might at some point lift itself out of a scene from Doctor Who circa 1973 but left you feeling like you had asked for a piece of Black Forest Gateaux but got packet blancmange instead. I was left wondering why the BBC, for all its great taste and free money, isn’t able to spot the turkeys and then lets the gold dust slip through its fingers (think Mad Men series 5. Grrr! Some of us are still Sky-less.)

More zombies and daftness please. And don’t make it too serious. I might start having nightmares again.

Original comic books
TV Show
AMC

Magento Trials and Tribulations

I’ve just exited from a rather scary period trying to upgrade Magento 1.2.0.1 to Magento 1.4.0.1. After getting scripts so that I could migrate customers, orders and products, I set up 1.4.0.1 locally. After a few hours of trying I managed to get all the data into the database.

However, it was then I realised the amount of work that was required to redo the template files and the CSS.

Nevertheless, I went to set up a test version remotely. This is where things fell apart. I decided to attempt an incremental upgrade from 1.2.0.1 through to 1.4.0.1 using Magento Connect. My reasons were clear: to avoid the need to do a clean installation.

However, don’t try to do this, especially if you have another version of Magento on the same server and you’re using the data from that version. The upgrade won’t deal with the jump between versions – something I should have anticipated. The other issue was that despite my attempts at removing all urls to the live site from the test site’s database, I must have missed some as after running the magento upgrade suddenly the live database had 255 tables rather than the original 212!

Woe is me! My upgrade ignored the test and upgraded the live database …

So, I quickly switched the live version with a backup I’d taken and restored the database to this. However, the products wouldn’t show and the neither would the admin. I told the client, who was very understanding, and promised to make good quickly. But, to my surprise a little while later the whole site was back up and running. I can only think there was a cache issue on the server.

I will do the upgrade but it’s going to be done with far more research and analysis than I had done. Magento is great software but it’s still immature, especially the open source version. You can’t play with it expecting it to be lenient with you preventing you from doing something you shouldn’t. Also, documentation is informal so you do have to piece things together to work out how to do something.

That said, I’d rather use the open source version than pay £8k – £15k for a team to manage the installation and upkeep.

Transferring files between host servers

If you’ve ever moved websites between hosts or wanted to set up a development version of a client site then you’ll have copied files from one and made them available to the other. The basic method for doing this is to ftp into the source server, download the files to your computer, ftp to the new server and upload the files there. The problem with this is that it takes ages to do when you’ve got large websites.

Despite having been doing web development for a number of years I’ve never thought about this before as I would always follow this process. However, given that I run a number of Magento sites for clients now and that there are a lot of pressure on my time I need a quick way to do this. So, after about 20 minutes research I realised there is a really easy way.

First on the source system compress the file into a .zip or .tar.gz file. Most hosts provide tools to do this. I know CPanel and DirectAdmin do. Next, download this. As long as you’ve a fast broadband connection this won’t take long. Next upload to the new host server. This took about 45 minutes for me. However, I set it up and just left it running. Last, after checking I have shell access with my user on the new host server, I use Putty to do a SSH session and then just run the following command: tar -zxvf yourfile.tar.gz. This unzips everything into the folder you leave the file.

All done in under an hour with about 10 minutes of my actual time.