Archive for the ‘Coding’ Category

Magento – url functions

Friday, August 14th, 2009

Current magento version – 1.3.2.4

Magento had some very handy functions that easily allow you to find some fundamental urls of your site from your phtml files so you can avoid hardcoding them. These are:

  • $this->getBaseUrl() – returns the base url of your store (funnily enough)
  • $this->getSkinUrl() – returns the url of the folder containing your css, images and local js files (eg skin/frontend/default/your_theme, will vary depending on what package and theme the page is using).
    So to find the image logo.gif in the images folder you would call $this->getSkinUrl('images/logo.gif');. It should be noted that if getSkinUrl does not find the file that you have specified (like images/logo.gif) then it will default to looking in the default theme folders rather than your custom theme folders.
  • $this->getJsUrl() – returns the url of the main js folder. So if you want to include a new js library from a template you can use this.

There are probably a few other functions like this, and some variations including some that use the Mage_Core_Model_Store, but there are the ones that I use most often.

Share

Introduction to Magento

Wednesday, August 12th, 2009

Current magento version – 1.3.2.4

Magento Logo

This is a very brief introduction to Magento, a powerful php based open-source e-commerce platform.

I am currently working on my first ever Magento project, and given the flexibilty and complexity of Magento and it’s code base, it seems a good idea to write a series of Magento hints and tips so that the next time that I come to use it I’ll be able to spend less time searching out the solutions to little niggly problems or requirements.

As an e-commerce solution, Magento is extremely powerful and flexible and may well be the answer for many peoples e-commerce needs. However because of this power and flexibility the code base is extremely large and the processing can be a little on the slow side, so if all your looking for is a really small and basic shop then this might prove to be overkill.

Overall though, now that I’ve almost got my head round the basics, I really like Magento as a tool and it can be fairly straightforward to work with if you know what you’re doing. If you’re not sure what you’re doing or you’re trying something a bit new then it can prove to be very frustrating and mentally draining, as the documentation isn’t always great and the forums can prove frustrating. But if you keep at it and in turn share what you’ve learned yourself then you’ll find yourself with a site that does exactly what you want, while at the same time improving the amount of information out there and possibly giving a lifeline to other magento users. If you learn something, share it! It might help someone who could provide you with invaluable help later on!
(more…)

Share

Creating title images on the fly

Monday, August 10th, 2009

I was recently working on a site where the main page headings where required to display in fluxfont (to match some images / icons, plus it looks prettier too). Now this is not a regular font that everyone has installed on their machines, so I needed to come up with some way to display the text in the right font without requiring anyone to download the font themselves.

There are font replacement options out there, such as sIFR and cufon, but these are not guaranteed 100% browser compatible and there is a bit of a grey area regarding the licensing of these fonts (Jon Tan talks a bit about this in his article about font-face). So rightly or wrongly I decided to stay clear of these methods for now and go for an alternative option.

Creating images on the fly using a text string

This method requires the gd and free type libraries to be installed. You can see whether they are or not by looking at phpinfo(), and if you can’t see them referenced then you’ll need to download and install them.

The idea here is to use a php file to manipulate a text string into an image which will then be output to the page.

So first I need to create the php file that will create my image:
(more…)

Share

Virtual Hosts in Apache on Windows

Monday, June 8th, 2009

This is more of a reminder for me but this might also help somebody else.

I’ve had to set up virtual servers for apache on windows a couple of times (using php5.2.6 and apache 2.2 on XP and Vista) and can never quite remember exactly what it is that I have to put where, so here is my way of doing it:

  • Open up the windows hosts file (for me found in windows\windows32\drivers\etc\)
  • Under 127.0.0.1 localhost, add in the new virtual host and save eg.

    127.0.0.1 localhost
    127.0.0.1 newhost // set the name of your new virtual host
  • Open up the apache httpd.conf file (found in your apache conf folder, for me its Program Files\Apache Software Foundation\Apache2.2\conf\)
  • (more…)

Share

Jquery .live and .livequery

Tuesday, June 2nd, 2009

I recently had a problem where I was trying to insert some product information into a page, with the information shown changed depending on which product was selected from a drop down list.

Here is the select list and the div that I wanted the extra information to be displayed into:

<select name="product" id="product">
<option value="">Select product...</option>
<option value="Product 1">Product 1</option>
<option value="Product 2">Product 2</option>
<option value="Product 3">Product 3</option>
<option value="Product 4">Product 4</option>
</select>

<div id=”product_info”>
</div>

(more…)

Share

CSS firefox margins

Wednesday, May 20th, 2009

I recently spent quite a while creating a template for a new site, so was not happy to find that sometimes a large chunk of white space would appear at the top, pushing down my background image and basically distorting the whole look of the page. And it only appeared to be happening in firefox!

Delving into it a little more, I realised it was in some way related to the borders that I would place around div elements during development so that I could easily see their exact positioning (I’m still not quite the CSS whizz, and this really helps me). When I thought I was finished with the layout I removed the borders and lo, the random white space appears!
(more…)

Share