A tiny cart block for Ubercart
by Dylan Tack, Lead Development Architect
Here's a tiny shopping cart block for Ubercart that fits right in with the menu. Of course the standard block could be themed this way, but this is handy when the design calls for the full-sized block elsewhere in the layout.

/** * Implementation of hook_block(). */ function uc_microcart_block($op = 'list', $delta = 0, $edit = array()) { switch ($op) { case 'list': $blocks[0] = array( 'info' => t('Micro-sized cart block for page header.'), // This block cannot be cached, because anonymous // sessions can have differing cart contents. // To improve this, see drupal.org/project/uc_ajax_cart 'cache' => BLOCK_NO_CACHE, ); return $blocks; case 'view': if ($item_count = uc_cart_get_total_qty()) { $block = array(); $block['subject'] = ''; $block['content'] = theme('image', drupal_get_path('module', 'uc_cart') .'/images/cart-full.png'); $block['content'] .= format_plural($item_count, 'My cart: 1 item', 'My cart: @count items'); $block['content'] = l($block['content'], 'cart', array('html' => TRUE)); return $block; } break; } }
Comments
Looks brilliant, but i
Posted by a_c_m on . [Reply]
Looks brilliant, but i couldn't find it on Drupal.org are you going to upload it?
It won't be published on d.o
Posted by Dylan Tack on . [Reply]
It won't be published on d.o but you can paste the code into a .module file of your own.
Hi Dylan, It looks great.
Posted by evdh on . [Reply]
Hi Dylan, It looks great. I've added the code to one of my custom module files but how do I make it appear on my site? The item doesn't show up in my blocks list.
evhd, perhaps you need to
Posted by Dylan Tack on . [Reply]
evhd, perhaps you need to rename the function as MODULENAME_block()?
Thanks Dylan, this really
Posted by meg on . [Reply]
Thanks Dylan, this really helped!
Works great, but how to do menu integration?
Posted by Joe on . [Reply]
Hey Dylan,
Got the block going and its great, but what is the next step if I want to have it integrated into the nav menu like you having going on in the screenshot? Right now i've got the micro cart block sitting right next to my nav menu block.
Thanks, Joe
Thanks, Joe
fake it
Posted by Dylan Tack on . [Reply]
It's not really part of the menu - I just use CSS positioning to make it appear that way.
posted on drupal.org?
Posted by Anonymous on . [Reply]
Is this the same solution as what's posted on drupal.org?
https://drupal.org/project/uc_microcart
not exactly
Posted by Dylan Tack on . [Reply]
The project above seems to have a few more options, and is themeable.
Hi, thanks a lot for this
Posted by Autofilms on . [Reply]
Hi, thanks a lot for this great portion of code. I have a question of compatibility, does this code works on Drupal 7 and Ubercart 3 ?
Thanks a lot for you work
Fredj, CEO of vitre teintée
not sure
Posted by Dylan Tack on . [Reply]
If you test it with Drupal 7, let us know what you find! Some changes will probably be needed, since the APIs change with each major release.
How to add small cart block in menu ?
Posted by buythiscomputer on . [Reply]
Hello,
Thank you but can you tell me how to use your tiny cart in my shop menu ?
Thanks a lot.
Hi, the block doesn't appear
Posted by kristin.e on . [Reply]
Hi, the block doesn't appear at all for some reason. I"m using ubercart 2.7 with Drupal 6.22. Any ideas?
Thanks.
Add new comment