Chili Pepper Design

Web development relleno

Magento - Six Months In

| Comments

Yes, this basically amounts to a good old fashioned rant post. But there is a purpose behind it: to educate those thinking of using Magento to power their ecommerce store about potential concerns and pitfalls. Read on, and enjoy.

Magento is an ambitious, promising ecommerce platform.

Magento really is a neat piece of software. Varien has really outdone itself. It is one of the most feature rich ecommerce platforms out right now and =drumroll= it’s Open Source!

After comparing prices and features a year ago, Magento was chosen from amongst all of the other ecommerce solutions available for some upcoming projects. I have now helped setup, develop, maintain and run four Magento stores. I’ve been working with Magento almost exclusively for the past 6 months.

It’s pretty great!

But it is not perfect.

How to Edit Orders With Configurable Products in Magento

| Comments

Up to and including the current release of Magento (1.3.2.3), an admin cannot properly edit an order containing configurable products. Magento warns you of this when you click the “Edit” button, and if you proceed the order appears on the edit screen containing only the Simple and Virtual products. Configurable, Bundled, and other products are removed from the order.

I am finding this more and more with Magento: it is the most feature-rich and impressive of all Open Source commerce solutions, but it is still a young piece of software and the result is that all of these great features are only about 80% operational. But enough ranting about Magento (for now).

You need to be able to edit an orders containing configurable products! The code below allows you to do this by converting the Configurable products into their respective Simple products. This is not the same as actually being able to edit the Configurable products. This approach is the same one that Varien takes when allowing an admin to create new orders: you cannot add Configurable products, but you can add any of the Simple products that constitute the Configurable ones.

Changing Magento Order, Invoice and Shipping Number

| Comments

A client needed to change the default order numbering scheme in Magento 1.3. There is no simple administrative backend setting to do this, however. The order, invoice, shipping and credit memo numbers are fixed – 9 digits long prefixed with a 1. The client wanted all of their order numbers in the form “AZ-xxxxx” – two fixed letters, a dash, and then 5 digits. So… how go about changing this?

Looking around the Magento forums and a few other websites (listed at the bottom), combined with poking around the in Magento code and database (phpmyadmin was very helpful), I eventually figured out a way to do it fairly simply, and without modifying any code! All that is required is running a few SQL statements against the database.

Magento: How to Protect Pages So Only Logged in Users Can View Them

| Comments

There are times when you want all or part of your Magento online store to only be visible to customers who are logged in to the website. Once such example is a “wholesale” website where only approved wholesale users should be able to view products and checkout. This functionality is not built in to Magento, but it’s a just a few simple little code hacks away.

NOTE: On 8.25.09 I updated this post since I have improved the technique.

CSS Equal Height Columns With Bottom Border and Margin

| Comments

The saga of CSS “equal height columns” is long and frustrating. It’s a common and attractive design element, but ever since we stopped using HTML Tables for our 2 and 3 column web page layouts in favor of Divs containers, it’s been a real challenge to implement them using standards based CSS and markup.

My favorite of the many clever techniques so far devised to solve this problem is the Position Is Everything One True Layout method (although don’t try to use internal anchor links with this!). Another favorite is the Equal Height Columns with Cross-Browser CSS & No Hacks, but it actually seems a little more complicated and hack-ish to me (despite the name). And if you really want it to just work to no extra markup and don’t mind a little inelegance, the good old Faux Columns approach with a background image works well too.

How to Integrate (Import) WordPress Content Into Magento Blocks

| Comments

This is the technique I use to integrate WordPress content into Magento. This can be useful for bringing in posts related to a product, or having recent blog posts on the Magento home page… whatever you can dream up. No modules, plugins or extensions are needed for this technique – just a good grasp of PHP and the Magento and WordPress theming/templating systems. There are probably many other ways to do this, but this is an easy way that I figured out which works well for my purposes so far.

First, the WordPress side of the process.

Step #1 is to create a wordpress page which will have the content we want to show in Magento. The trick is that we don’t want the WordPress header or footer – we just want the content. To do this we will create a new page template. In your WordPress theme directory, copy a file with a Loop in it (index.php or page.php are a good ones to start with) and rename the new file something like MagentoContent.php. Edit this new file, and place at the top something like:

Magento: How to List All the Products in a Single Category in a Sidebar Block

| Comments

The website I’m currently developing wants to have all of the products in “CategoryX” displaying in the left sidebar on all pages. It’s a small category with their 5 core products, and they want to make sure no matter where the visitor is on the site, they are just a click away from viewing these products. The sidebar block only consists of a header with the Category name, and a simple list of the products with links to their product information page. It’s just links in this case – no images or prices or “Add to Cart” buttons – but you could add these easily.

I tried to simply use the “Catalog/Product_List” controller with a modified view based off of “catalog/product/list.phtml”. The problem I ran into is that “Catalog/Product_List” uses the session’s current Category/Layer to populate the list, so I couldn’t show the products in CategoryX in the sidebar when I was viewing CategoryY. I read that you can specify which category it uses, but this only seems to work on pages without a Category/Layer, like the Home/Front page and similar CMS pages.

Fortunately I found a nice snippet of code on exploremagento.com, which gave me a clue about how to do this. I’ve modified this code to better suit my needs, and make it a little more general at the same time. You will need to know how to create a simple Magento module to implement this, and there is a good guide here.

Anyway, here it is the code:

How to Add Dynamic Content to Magento Static Blocks and Pages

| Comments

Magento provides an easy way to create blocks of static content which, with a little Layout-XML-Fu, can be added to any page in Magento. Even better, these blocks can be added to any category page with no programming at all. This is great if you want to have a banner image with monthly specials and deals, or if you want to add a header image or descriptive text to a category.

Magento also makes it really easy to create static SEO landing pages. In just a few clicks you have a new static page, ready to lace with images and tasty keyword laden text, and to link to any product or category in the Store proper.

But you can’t put PHP code in these blocks or pages.

Not directly at least…

Retrofitting Content Management Systems (CMS) on Existing Websites

| Comments

This past week I retrofit the Montana Seed Trade Association website with CMS Made Simple. Previously, it was a “flat” website that consisted of some basic HTML and a couple of simple dynamic PHP pages populated from a mySQL database. Every time they wanted to update the site with new events or meeting dates, they had to call up the original web developer and pay them the standard (not cheap) hourly rate to make the changes.

Now that I have put a CMS administrative back-end behind the website, they can just log in at any time and make the changes themselves, without any HTML programming. Even though they only need to update their website a couple of times a year, using the CMS to do it themselves will pay off the cost of the retrofit in just two years. Imagine if they had to update the site weekly, or even daily!

Htaccess 301 Redirects From One URL Query String to Another

| Comments

The other day I was trying to set up a 301 Moved Permanently redirect that took one dynamic url and redirected to another dynamic url.

Searching around I found plenty of tips on how to redirect from older “ugly” style dynamic urls like “test.php?id=999” to new “clean” dynamic urls like “test/999”, but that wasn’t exactly what I needed. I needed to go from something like “page.php?id=999” to something like"page.php?id=111". Basically just a parameter substitution.

There are two ways to do 301s in an .htaccess file. One is to do a standard “redirect 301”, and the other is to use the Apache mod_rewrite module. For reference, this is what a standard “redirect 301” looks like:

redirect 301 /testpage.htm http://www.example.com/testpage2.php

This won’t work with a dynamic URL like “/testpage.htm?id=blah” though. To handle query strings properly you need to use mod_rewrite. Here is the code that ended up working:

# redirect testpage.php?id=string1 to testpage.php?id=string2
RewriteCond %{QUERY_STRING} ^id=string1$ [NC]
RewriteRule testpage http://www.example.com/testpage.php\?id=string2 [L,R=301]

The trick is that the second part of the RewriteRule – the URL to redirect to – is evaluated as a Regular Expression but has a “?” in it. This is a RegEx operator, and will break the command unless it is escaped with a “\”.

Look close at our destination URL "http://www.example.com/testpage.php\?id=string2". The URL we actually want to redirect to is "http://www.example.com/testpage.php?id=string2". Forgetting this one tiny little escape character will blow the whole thing up. :)

The dirty details:

There are plenty of good resources on mod_rewrite conditionals if you want to learn more, but it basically works like this: Apache looks at the RewriteRule, which is a pair of two Regular Expressions (RegEx): the URL we want to change, and what we want to change it to. If mod_rewrite matches the first RegEx expression then it looks at the RewriteCond to see if it should apply the RewriteRule. In this case we are just looking at the QUERY_STRING (everything after the “?”), and doing a case-insensitive [NC] match for “id=string1”. If the RewriteCond is true, then the RewriteRule goes in to effect and “testpage” is redirected to “http://www.example.com/testpage.php\?id=string2”. Just don’t forget to escape that pesky “?” in the query string!

301 Redirects are an important part of SEO and maintaining search engine rankings, so it’s nice to have another trick up your sleeve like this.

Here are some very helpful additional resources to improve your htaccess mod_rewrite-fu: