Magento: PHP Fatal error Undefined class constant ‘TYPE_CONDITION’ Abstract.php on line 296

This is what happens when you don’t pay attention. I was working on a project that started out when Magento was the latest stable version. There is a bit of development left, but I decided to upgrade the install to 1.4.2 via subversion. I go get some coffee, come back, and assume the upgrade is done.

Then I try to load the homepage, and I get a blank screen. Eh, ok. Time to display errors by commenting the following line in index.php.

[code]ini_set(‘display_errors’, 1);[/code]

Lets see what the logs say:[code]PHP Fatal error: Undefined class constant ‘TYPE_CONDITION’ in /home/dev/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php on line 296[/code]

Well, what exactly is the code throwing this error? In Abstract.php:

[code] if (!empty($conditionSql)) { $this->getSelect()->where($conditionSql, null, Varien_Db_Select::TYPE_CONDITION); } else { Mage::throwException(‘Invalid attribute identifier for filter (‘.get_class($attribute).’)’); }

return $this; }[/code]

How can Varien_Db_Select::TYPE_CONDITION not exist? I looked at my Varien/DB/Select.php and there was no TYPE_CONDITION. Then I looked at Varien_Db_Select in the Magento docs, and it was there. Weird.

Then I looked back at the terminal which was doing Subversion update, and noticed that there was an error. Apparently my Internet connection had died and the update didn’t complete. Ugh.

After restarting the Subversion update, I look at Varien_Db_Select:

[code]class Varien_Db_Select extends Zend_Db_Select{ const TYPE_CONDITION = ‘TYPE_CONDITION’;

const STRAIGHT_JOIN_ON = ‘straight_join’; const STRAIGHT_JOIN = ‘straightjoin’; const SQL_STRAIGHT_JOIN = ‘STRAIGHT_JOIN’;[/code]

There it is.

Moral of the story. Make sure your updates actually complete before making such an assumption.

ImageMagick: Batch Crop and Rename Files

There are many better ways to do this, but here is one method if you need to do a quick and dirty jobs of cropping and renaming a bunch of files in a batch with ImageMagick.

Quick little background. Even though I’ve got a Macbook, if I have to look at code, I’m usually on a desktop thats running Ubuntu 10.04. We host client sites on servers running Ubuntu 10.04, so its best to write code in that environment. So today, after finishing up code for a Magento site, I needed to upload a set of fabric swatches that would be used with configurable products. The client provided images for the fabric swatches, but they were all different sizes. All I needed was a 60x60px selection of each image and the filenames to be something descriptive with the image size. 

Of course, this can be done pretty easily in Photoshop. I’m sure there is some plugin for it, but you can record an action, and run it against a batch of files. The problem was that I didn’t want to hop on my Macbook just to crop and rename files.

Since I was on an Ubuntu machine, my first gut reaction was to fire up Gimp and see if I could do it. Turns out there is a plugin called David’s Batch Processor that pretty much does that. Ubuntu has the plugin in the repository, just search for ‘gimp-plugin-registry’ in Synaptic. Gimp also supports scripting, but the scripting language is Scheme-like, and I didn’t want to recall knowledge from freshman year in college to do this.

Then I remembered ImageMagick. While ImageMagick has a GUI for image manipulation, its got a powerful CLI that lets you do pretty much anything you want to do. So no need to open up a big honkin’ application just to do some basic cropping and renaming.

So save the following code in the directory of the files you want cropped and renamed and run it:

[code]#!/bin/bashwidth=60;height=60;x_offset=10;y_offset=5;filelist=`ls | grep ‘.jpg’`for image_file in $filelistdo preextensionfilename=`convert $image_file -format “%t” info:` convert $image_file -crop ${width}x${height}+${x_offset}+${y_offset} ${preextensionfilename}_${width}x${height}.jpgdone[/code]

Most of this should be pretty self-explanatory. Up top we define what sizes we want the images to be cropped to and from where in the image we want to crop. Then we grab a list of all the files we want to crop, and grab the filename before the extension (to be used for saving the new files). The convert command is what actually does the cropping and saving the files with the new names, in this case, something like oldgold_60x60.jpg.

The script is most definitely not robust, but hopefully it will be a good starting off point for some.

How to do a Jawbone Icon Hard Reset

With a new Galaxy Nexus, I couldn’t pair my bluetooth headset with it. Seemed like I needed to reset it. So here are instructions on how to reset the Jawbone Icon:

  • Turn it on
  • Wait for white blinking light.
  • Very quickly, click the talk button 6 times
  • Wait for white blinking light to blink red.
  • Hold down the talk button.

When it flashes red and white alternately, the Jawbone Icon is done resetting.

iPad Pin It Pinterest Bookmarklet in Safari

iPad Pin It Pinterest Bookmarklet in Safari

It looks like Pinterest hasn’t provided a convenient way of adding the Pin It bookmarklet to Safari on the iPad. But try the instructions below. Its been tested with iOS 5.

Step 1Bookmark this page in Safari on the iPad. Give it a useful name like Pin It.

iPad Pin It Pinterest Bookmarklet in SafariiPad Pin It Pinterest Bookmarklet in SafariStep 2Copy the javascript below:


iPad Pin It Pinterest Bookmarklet in SafariStep 3Go back and replace the bookmarklet address with the javascript above.

iPad Pin It Pinterest Bookmarklet in SafariStep 4Pin away!

iPad Pin It Pinterest Bookmarklet in SafariiPad Pin It Pinterest Bookmarklet in SafariiPad Pin It Pinterest Bookmarklet in SafariiPad Pin It Pinterest Bookmarklet in SafariFollow me on Pinterest.

Tweet me if the Pin It bookmarklet no longer works.

How to Fix Internet Explorer + iFrame + PNG Transparency Issue

Working on a client site, we ran into issues with Internet Explorer, iFrames, and transparent PNGs. For the site, we are using an iFrame to load content when the user clicks on a button. On the fly, with javascript, a bit of code gets generated like:

Blah, Blah, Blah

[code]#bazImage {color: white;font-size: 16px;font-weight: bold;padding: 25px 30px 0px 18px;font-family: Arial, Helvetica, sans-serif;background: url(images/bazImage.png) no-repeat;width: 256px;height: 107px;}[/code]

The background image is bazImage.png, a transparent PNG. This worked fine in Chrome, Firefox, and Safari, but all the transparent pixels turned up as white in IE. My first thought was we needed to apply a PNG fix.

But that didn’t help.

Not so surprisingly, Internet Explorer handles transparency differently than other browsers. Elements have an allowTransparency attribute that defaults to false, so embedded iFrames won’t be transparent. Simply set it to true.

One final step, set ‘background-color: transparent;’ in the body element. MVC: Expecting element ‘root’ from namespace ”.. Encountered ‘None’ with name ”, namespace ”. MVC Expecting element 'root' from namespace ''.. Encountered 'None' with name '', namespace ''.

While walking through an MVC3 app, I noticed that Ajax calls resulted in nothing happening. Debugging in Visual Studio, I noticed a SerializationException at the following code:

[code]public override void OnActionExecuting(ActionExecutingContext filterContext) {….object o = new DataContractJsonSerializer(RootType).ReadObject(filterContext.HttpContext.Request.InputStream);}[/code]

The JSON response from the Ajax was supposed to be read here, but it was failing. It was a runtime exception, “SerializationException was unhandled by user code.” Turns out InputStream wasn’t being read from the beginning of the stream, so the JSON couldn’t be deserialized properly.

Resetting the position in the current stream to the beginning should make it readable again:

[code]public override void OnActionExecuting(ActionExecutingContext filterContext) {….//move current position in the stream back to the beginningfilterContext.HttpContext.Request.InputStream.Position = 0;object o = new DataContractJsonSerializer(RootType).ReadObject(filterContext.HttpContext.Request.InputStream);}[/code]