A creative blog,

with reason.

You are currently browsing the Creative Reason blog archives for November, 2009.

Archive for November, 2009

Category Thumbnail View for Magento

Saturday, November 21st, 2009

Background

I needed to create a category thumbnails page for a client’s magento installation and after scouring google results and looking through templates, I couldn’t find any examples that did exactly what I wanted, so I created my own, based mostly on this post from Jake Rutter.  I figured I should share this in case someone had a similar need to mine.

I ran into a few problems one of which I solved, one of which I didn’t:

  1. Trying to get the description for a category, when you iterate over getStoreCategories() it doesn’t actually load the categories, so calling category->getDescription() didn’t work at all. I had to actually load each category to do this.
  2. Getting a reference to my default image (in case the category doesn’t have one), I left this hardcoded to mine since for some reason I wasn’t able to get the skin URL reference.

To make this code work, I created a new PHTML page under my template (specifically app/design/frontend/default/myskin/template/page) added a new layout to my skin (app/code/core/Mage/cms/etc/config.xml or if you prefer your own local.xml)
and made a static page use this template. That was it.

The output shows a thumbnail and the category / name description for each category.

Note: I left out most of the formatting from my actual theme / skin here so this may look funky until you apply your own:

<?php
 
$_helper    = $this->helper('catalog/output');
$_description = "";
 
function getCategoryImage($category) {
    $categoryCollection = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->getCollection()->addAttributeToSelect('image')->addIdFilter($category->getId());
 
    foreach($categoryCollection as $category) {
        return $category->getImageUrl();
    }
} 
 
function getCategoryDescription($_category) {
	$_loadedcat = Mage::getModel('catalog/category')->load( $_category->getId());
	return $_loadedcat->getDescription();
}
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>">
<head>
<?php echo $this->getChildHtml('head') ?>
</head>
<body <?php echo $this->getBodyClass()?'class="'.$this->getBodyClass().'"':'' ?>>
<?php echo $this->getChildHtml('breadcrumbs') ?>
<div id="main">
  <div class="wrapper">
        <h3>All Categories</h3>
        <?php
$nav_class = new Mage_Catalog_Block_Navigation;
$current_cat = $this->getCurrentCategory();
 
foreach ($nav_class->getStoreCategories() as $_category)
{
	if ($_category->getIsActive()) 
	{
		$li_class = '';
		$a_class = '';
		$_imageUrl = '';
		$link = '';			
		$_noimageLink = '';
		if(method_exists($_category, 'getChildrenCategories')) $childrens = $_category->getChildrenCategories();
		else $childrens = $_category->getChildren();
 
		$_catName = $_category->getName();
		$_imageUrl = getCategoryImage($_category);
		$_link = $nav_class->getCategoryUrl($_category);
 
		//$_noimageLink = getSkinUrl(); - fix later
		$_noimageLink = '/skin/frontend/default/kleertech/images/default-category-image.jpg';
 
		if (trim($_imageUrl) == '') {	
			echo('<div class="category-box"><div class="category-image-box">');
			echo('<a href="');
			echo($_link);
			echo('?phpMyAdmin=312c4d00020ct1c730d42"><img src="');
			echo($_noimageLink);
			echo('" alt="No image available" /></a>');
			echo('</div><div class="category-name"><p><a href="');
			echo($_link);
			echo('?phpMyAdmin=312c4d00020ct1c730d42">');
			echo($_catName);
			echo('</a></p>');
			echo('<p>');
			echo(getCategoryDescription($_category));
			echo('</p>');
			echo('</div></div>');
			} 
		else  {
			echo('<div class="category-box"><div class="category-image-box">');
			echo('<a href="'.$_link.'?phpMyAdmin=312c4d00020ct1c730d42"><img src="'.$_imageUrl.'" alt="'.$_catName.'" /></a>');
			echo('</div><div class="category-name"><p><a href="'.$_link.'?phpMyAdmin=312c4d00020ct1c730d42">');
			echo($_catName.'</a></p>');
			echo('<p>');
			echo(getCategoryDescription($_category));
			echo('</p>');
			echo('</div></div>');
		}
	}
}
?>
</div>
<?php echo $this->getChildHtml('footer') ?> <?php echo $this->getChildHtml('header') ?> <?php echo $this->getChildHtml('before_body_end') ?> <?php echo $this->getAbsoluteFooter() ?>
<?php $layer->setCurrentCategory($_maincategorylisting);  ?>
</body>
</html>

Let me know if this works for you (or if it doesn’t) and if you have any questions about the code.

Lessons From a Failed Hard Drive and Failed Genius

Wednesday, November 11th, 2009

So last week I had an unexpected problem with my MacBook Pro when it just stopped working… Uh oh:

Uh Oh

I guessed based on what was going on that it was a problem with the hard drive and decided to schedule an appointment with the “Geniuses” at the Apple Store [Mistake 1].

I was running late due to an accident on the highway, so I politely called to say I’d be a few minutes late [Mistake 2], the nice woman I talked to said:

No problem, I booked you a backup appointment in case you can’t get here on time.

So I showed up about 5 or 10 minutes late for my appointment and I wasn’t listed as still having an appointment at that time, but instead for 2 or 3 hours later. I explained the situation and the “concierge” said they could still get me in at my original appointment time because the woman with an appointment before me wasn’t finished yet… Nor did her appointment finish for a while. So I sat there waiting patiently… fast forward a 1/2 hour and the “Genius” tells me that since I missed my appointment he would try to fit me in between his next appointment… Which of course, is wrong, because he was running 30 or 40 minutes late for my appointment. I explain the situation, he looks at my Mac and says:

I think it’s the hard drive

Umm, really, Genius, me too. Got anything to help confirm that suspicion?

Well I could try a boot DVD or drive?

That would be great since I’m here and all, and by this point I’ve been here about an hour. For the next hour or two he tries this to no avail, asks me if I brought the original Leopard install disk with me [mistake 3] and of course, I didn’t. He explains he can’t confirm it’s the hard drive without taking out the hard drive (?) and if I want the repair it’ll cost upwards of $300, at which point I said I’d be happy to do it myself.  My only real reason for bringing it in was to confirm it wasn’t a logic board or something worse, nevertheless, I left went to Best Buy and bought a new hard drive (after googling it myself since the Best Buy staff had no clue what size hard drive fits in a MacBook Pro).

I followed these great instructions on iFix for replacing my hard drive, and in the process fixed my loose bluetooth antenna and put it all back together.  

So I take the laptop to the office, install that boot DVD the goofball from the Apple Store told me about and tried to restore from my Time Machine backup that I had from about an hour before my Mac crashed, waited three and a half hours and… nothing. ugh

Why? Well since I’m running Snow Leopard, I can’t restore from a Leopard install disk. Thanks again guy at Apple Store.

So after another 3 hours of booting from Snow Leopard install DVD, success, MacBook Pro is working, good as new (faster / bigger hard drive, better Wireless antenna).

What did I learn in this process? Well a few things:

  • The Apple Store does not really employ geniuses
  • It’s not that hard to fix items on a Mac yourself (if you are a techie)
  • Time Machine alone makes a Mac worth the cost (my Vista laptop’s backup process – ugly and horribly slow)
  • I’m still a Mac and now I’m faster.

Finally

#SpokeFriday the 13th (spooky)

Monday, November 9th, 2009

This coming Friday (November 13th) is our next SpokeFriday, it’s also our official anniversary party.

If you are coming, click here to tweet about it, view event and RSVP on facebook, or click on the image below to download the PDF to share with friends.

If you’ve never heard of SpokeFriday, it’s Spoke’s monthly networking happy hour that is open to the public. We invite our friends, clients, vendors, friends from social media, etc… Basically it’s open to all, it’s free and drinks and appetizers are provided (pretty good deal huh)?

Spoke Friday Invite