Magento 1.4 Themes Design Book Review

Magento 1.4 Themes Design was written by Richard Carter and published by Packt Publishing. It was published in January of this year (2011). I read the eBook copy, so I have not yet been able to look at the paper copy, but if it is like every other book published by Packt, there’s not much to complain about.

This book is geared towards beginners looking to get their hands dirty with theming Magento, and understanding how it works. If you are only used to theming applications like WordPress or ZenCart, you will find Magento very difficult. Magento doesn’t just use template files. Magento is much more like a framework, and should be considered as such. They have implemented a powerful system of blocks, layout xml, and template files. The concept can be difficult to wrap your head around, and that’s where this book can really help you get started.

You’ll find the book very well organized, and the author does an amazing job explaining concepts without rambling on forever. There are many occasions where a link to a article (mostly wiki articles on Magento’s site) that better explains the concept in detail, which is nice as it doesn’t clog up the book, and allows you to choose to explore the concept further or not.

Some of the things about things about this book that I appreciate:

  • Suggests when upgrading from 1.3 to 1.4 to start the theme over from scratch. While this seems crazy, from my experience, it has been the best option.
  • In chapter 1, the author goes through 6 differently themed Magento sites (3 themes that come with a fresh Magento installation, and 3 established websites using Magento) and explains the design elements in Magento terminology. It was great to see so many examples to see how Magento themes can be used differently.
  • Defined the challenges of theming with Magento.
  • Did a nice job of explaining theme hierarchy.
  • Suggests only using a single xml layout file for your custom themes. I had already learned that this is a great practice to have, and the fact that the author suggested this and gave good reason for it was appreciated.
  • Walk you through how to create a theme from scratch (though still basically based off of the base/default theme).

As you walk through the chapters in this book, it does a nice job easing you into the concepts, and keeps the flow going, building further upon what you are learning. Overall, for a beginner, I would highly recommend this book.

The only cons of this book: If you are hoping for a detailed and in-depth explanation of how layout xml works (like I was), this book won’t quite do it, though does a great job explaining the basics, which is the purpose of the book. The only other complaint I have is that the author suggests that you FTP all of the unpacked files to the server. I wouldn’t ever suggest that, but, if you are a beginner and are unfamiliar with using the command line, I guess it gets the job done (though very slowly!).

Posted in Book Reviews, Magento | Leave a comment

Magento: Module Development Tip – External Files

When creating a module (extension) in Magento, if you are doing anything at all with design or skin files, you know that there’s no way to put those files within your main module directory. If you are like me, you don’t like that fact. I wish my module could all be housed inside one directory, but at this point it can’t. To help with this, I typically create a text file withing the root of my module’s directory like this: app/code/local/Prattski/MyModule/externalfiles.txt

Here I list out every file and it’s path that does not reside in my module directory. This not only helps you not forget what files belong to the module, but also make it easy to remove everything should you need to fully uninstall it. Here is an example:

### Module Files Outside this Directory
 
# Module XML File
app/etc/modules/Prattski_MyModule.xml
 
# Frontend Templates
app/design/frontend/base/default/layout/mymodule.xml
app/design/frontend/base/default/template/mymodule/file1.phtml
app/design/frontend/base/default/template/mymodule/file2.phtml
 
# Skin Files
skin/frontend/base/default/css/mymodule.css

I would encourage everyone who writes modules to get in this habit. It is not only very useful for yourself, it is also really helpful for any of you creating community extensions to include this so that whoever is installing the files can easily see all that belongs to the module if any modifications need to happen.

Posted in Magento | 5 Comments

Magento: Potential Date Field Product Import Bug

Note: Only tested so far with 1.4.1.1.

A client that I am working on has a custom product attribute, which is a date field. They recently ran an import to update that field and noticed something strange. It seems that some of the dates worked fine, and others had the day and the month swapped, creating a wrong date.

They had probably 50+ products with the following value for the date: “2011-05-10 00:00:00″. Some of them worked properly and the date ’5/10/11′ displays when editing the product in the admin. But, some of them switched the day and month and the date in the field is ’10/5/11′.

I tried reversing the day and month in the csv and imported again, and again, it switched the date around. So, now that the value in the admin was ’5/10/11′, I ran an export of just that product, and the date was correct! I took that exact spreadsheet and imported it, and it switched the day and month again.

At this point, I don’t have time to really dig into trying to figure out the issue. If you have encountered this, or even better if you have figured out the issue, please comment! Please be sure to inclue your Magento version as well, as it may not just be 1.4.1.1.

Posted in Magento | 4 Comments

Currently Reviewing: Magento 1.4 Themes Design

I am currently reviewing another book by Packt Publishing called Magento 1.4 Themes Design. Unlike the last book I reviewed, I am quite impressed so far with this book. Much of the work that I do with Magento requires no or very little theming (or, I have others do it). So, this is a great experience for me to read this book.

I hope to have the review done in the next week or two. At this point, I am definitely anticipating a very positive review.

Posted in Magento | Leave a comment

Magento: Mass Exclude/Unexclude Images

By default, Magento will check the ‘Exclude’ box for you on all imported images, making them not show up as a thumbnail under the main product image on the product view. Should you ever want to mass unexclude them (or mass exclude your images), you can simply run one of the following sql commands in your database:

# Mass Unexclude
UPDATE`catalog_product_entity_media_gallery_value` SET `disabled` = '0' WHERE `disabled` = '1';
 
# Mass Exclude
UPDATE`catalog_product_entity_media_gallery_value` SET `disabled` = '1' WHERE `disabled` = '0';
Posted in Magento, MySQL | 3 Comments

Prattski Magento Extension Store Now Live!

It has been a long time coming, but I am excited to announce that the Prattski Magento Extension Store is now live. At this time, we only have 2 extensions listed, but we hope to add more in the near future.

Dependent Filters: This extension adds on option on the attribute edit view that allows you to select dependencies from a list of existing filters. When dependencies have been set, the filter will not show up on the front end until one of the selected dependencies have been selected. This extension currently does not support the price filter or category filter.

Import/Export URL Rewrites: This extension gives you an easy interface to import/export Custom URL rewrites. As of this current version, please note that it does not yet import/export System rewrites.

Posted in Magento | Leave a comment

Magento 1.4 Development Cookbook Book Review

Magento 1.4 Development Cookbook

I was asked by Packt Publishing to review a new book entitled Magento 1.4 Development Cookbook. I was excited for the opportunity to review a recent development book, hoping I might get some new fresh perspectives.

Before I get into the details, I highly recommend avoiding this book. Unless you want a reference of how NOT to develop properly with Magento, do not buy it. Save your money and time and just spend a few hours looking through Magento’s core modules and learn by example. That to me has been the best reference in learning how to develop with Magento.

Why avoid this book

  • In the first chapter, the author lists some reasons as to why Magento’s coding conventions are good and make sense, but then go on to say “We are not compelled to follow Magento conventions.” Why would you not!? No reason was given.
  • In all their examples having to do with modifying theme files, they only very briefly (a couple paragraphs) suggest making your own theme. Not nearly enough to stress any importance in it. Then, they specifically say they are modifying base/default theme files for all the examples.
  • They suggest modifying the existing layout xml files. It is a much better practice to create your own local.xml file (in app/design/frontend/your-package/your-theme/layout/local.xml) and have all of your modifications in there. That way, you have quick and easy access to every change you made without having to wonder what you changed over the course of a project.
  • Adding custom CMS templates (which you can select when creating/editing a CMS page): Their suggestion is to modify app/etc/modules/Mage_All.xml and change the codepool for the Mage_Page module from ‘core’ to ‘local’, then move the Mage_Page config.xml file from app/code/core/… to app/code/local/… This, without question, is an amazingly awful idea. To accomplish this functionality, it can easily be done by creating your own module, and not touching any core files.
  • Add RSS feed of the last 5 tweets to your site: They failed to suggest writing a module for this. Instead, they have you putting business logic code right within template files. Bad idea.
  • Adding an image rotator: Their example basically makes it very difficult for any clients (if you are developing a website for a client) to manage it. I would never go this route for any of my clients.
  • Adding jQuery and Lightbox: Their implementations where completely template-based. A module should have been written for both these implementations.
  • Adding a Twitter handle to the customer registration: This was one of the worst examples in the book. They have you put all the php to create the custom customer attribute in template files, and then have you edit core files directly.
  • Installing Magento without mcrypt: Another one of the worst examples in the book. They have you directly modifying lib/Varien and core files.
  • When you finally get to the chapter about creating modules, they have you use a module creator instead of just making one from scratch.
  • They suggest putting xml that should be in app/etc/modules in your modules config.xml file.

Summary

There are potentially a couple of chapters in this book that could be good (performance optimization and unit testing), but I don’t know enough on those topics to review them well. I’d hesitate to think the authors have you do it properly given the rest of the book, but to be fair I can’t say for sure. Perhaps they are much better with those subjects than actual Magento development.

As a whole though, this book should be avoided. Like the authors said upfront, they had no interest in following Magento’s coding conventions, and it very clearly shows throughout this book. By not following Magento’s conventions, the authors walk you through terrible implementations and concepts, many of which would break if you ever decided to upgrade Magento (because of overriding the base templates and overriding core files). Without question, it is best to follow Magento’s coding conventions, think modular, and never touch core files.

Posted in Book Reviews, Magento | 2 Comments

Magento: Bug Found – “Invalid option ID specified …” on Export

Version Tested: 1.4.1.1 Not sure if this bug exists yet in any other versions.

I was doing a product export today with Magento’s built-in export profile “Export All Products”. I noticed that there were hundreds of errors like this:

"Invalid option ID specified for region_code (59), skipping the record. (Line 134, SKU: AV71146)"

So, I checked everything I could to make sure it was setup properly: I checked the product, and a value was assigned (it’s a dropdown in my case), I checked the attribute itself to make sure that “59″ was a valid option id, I checked the database to make sure nothing looked out of whack both on the product, and the option and values. Everything seemed fine.

I then decided to search the code for “skipping the record”, and I came across this file: app/code/core/Mage/Catalog/Model/Convert/Parser/Product.php. Lines 434-440 are displayed below:

if ($attribute->usesSource()) {
  $option = $attribute->getSource()->getOptionText($value);
  if ($value && empty($option)) {
    $message = Mage::helper('catalog')->__("Invalid option ID specified for %s (%s), skipping the record.", $field, $value);
    $this->addException($message, Mage_Dataflow_Model_Convert_Exception::ERROR);
    continue;
  }

I did some logging and found out that the getOptionText() method was indeed returning the proper values. The kicker is this: One of the values for this particular attribute is the number zero ’0′. So, the second line sets $option to 0. Then, when it runs if ($value && empty($option)), it then assumes $option is actually empty because it’s 0, thus throwing the error on the export results.

The Problem: You cannot use the number 0 as an option for a dropdown or multiselect attribute option.
The Fix: Rename the option, or better yet, Magento should fix the code to allow for 0 as an option.

Posted in Magento | 8 Comments

Very Frustrated With Magento Today

I am trying to get my Magento extension store up and running, and yesterday I thought I was ready to launch it. I was using 1.4.2.0, Downloadable Products, and Paypal Express Checkout. I had a friend of mine run an order through to test it out. Everything worked, except Magento failed to create the customer account during checkout, so he wasn’t able to download the extension! I searched around, and it seems like that has been a known bug for some time now, and still has yet to be fixed.

So, yesterday afternoon 1.5.0.0 stable was released, and I figured they would have fixed the Paypal issue. So, I upgraded. Did a fresh file install on top of my 1.4.2.0 database. I go to test it out and add a product to my cart, and then I get errors on the cart! It says “Some of the products below do not have all the required options. Please edit them and configure all the required options.”. Down on the product itself, it says “Please specify product link(s).” Here’s a screenshot:

1.5 Downloadable Product Errors

I even tried a completely fresh 1.5.0.0 install, created a downloadable product, and still the same issue. I know it has nothing to do with any customization I would have done. So, Magento is completely useless for my needs right now, which shouldn’t be the case…

What is the best thing to do then when you find a bug? Report it on Magento’s bug tracker! Well, as of right now, when you go to report an issue, there aren’t any options in the drop-downs for the Magento version or priority! Yet another problem!

So, while everyone is at the Magento Imagine conference having a good time, I’m at home with a fresh copy of Magento 1.5.0.0 that’s defective and will not even run my store. Definitely frustrating how new versions of Magento just continue to introduce bugs on already existing and working functionality. As far as I’m aware, I may have to go back to 1.3.3.0, as I believe all versions of 1.4.x and 1.5.0.0 will not function properly for wanting downloadable products and Paypal express checkout. Can we say, “Unit Test” maybe?

Posted in Magento | 3 Comments

Javascript: Don’t Use ‘length’ and ‘width’ as Variables

I have been working on a Magento customization that calculates rug pricing by square foot. I’ve had to write a good amount of javascript to help with this, and I had everything working just fine in Firefox, Safari, and Chrome. But (surprise, surprise) IE was throwing errors. After some console logging and debugging, I finally figured out that if I changed my variable names in a function I had from ‘length’ and ‘width’ to ‘rugLengh’ and ‘rugWidth’, then IE stopped complaining and everything worked just fine.

I’m not much of a javascript programmer, though I can get by. This particular issue is still a mystery to me. If any of you know why this was happening, I’d love to know!

Posted in Javascript | 2 Comments