-
Vim in 10 Minutes
This week at my local PHP user group we were speaking about IDEs. There were four of us who prepared to speak to attendees. I wasn’t sure what kind of time I’d be allotted, so I didn’t prepare as I usually do. I figured I’d just give an off-the-cuff introduction to some of the niceties of Vim. It didn’t work out as well as I’d hoped.
About a year ago I did a two-hour Vim talk. I spent a significant amount of time preparing for the talk. The presentation was well-received and, I’d like to think, resulted in a few new Vim users. Why do I mention this? It makes me feel better about the crummy introduction to Vim that I gave last night.
So I’m just throwing this out there… make sure you have more than 10 minutes if you want to introduce someone to Vim. If you have less than 10 minutes, I suggest grabbing a really messy file and cleaning it up using Vim power. This may be enough to spark some interest. Also you may find it beneficial to just point your audience to a YouTube video of a Vim power user working his/her magic. Vim Tutor is another approach.
-
Disable Specific States in Ubercart
Here’s a quick example that illustrates how to remove a few State/Province options from the billing and shipping panes of the Ubercart checkout form, as well as the order edit/create form. Please understand there are other ways to do this (like altering the united_states_840_1.cif file and re-importing). The hook_form_alter() method seems less permanent, so I favor it.
123456789101112131415161718192021/*** Implementation of hook_form_alter().*/function mymodule_form_alter(&$form, &$form_state, $form_id) {switch ($form_id) {case 'uc_cart_checkout_form':// Disable some State/Province values in the checkout formunset($form['panes']['delivery']['delivery_zone']['#options'][21]); // Hawaiiunset($form['panes']['delivery']['delivery_zone']['#options'][49]); // Oregonunset($form['panes']['billing']['billing_zone']['#options'][21]); // Hawaiiunset($form['panes']['billing']['billing_zone']['#options'][49]); // Oregonbreak;case 'uc_order_edit_form':// Disable some State/Province values in the order edit/create formunset($form['ship_to']['delivery_zone']['#options'][21]); // Hawaiiunset($form['ship_to']['delivery_zone']['#options'][49]); // Oregonunset($form['bill_to']['billing_zone']['#options'][21]); // Hawaiiunset($form['bill_to']['billing_zone']['#options'][49]); // Oregonbreak;}} -
Get the Value of the Cheapest Option for an Ubercart Product
This is just a quick code example. Imaging you have an Ubercart attribute that has several options and you’d like to show an “As low as $X.XX” price on the frontend. Here’s a simple solution. Note that if you wanted the lowest price across ALL attributes you could loop through each attribute too (instead of just looking at attributes[1]).
123456789if ($node->attributes[1]->options) {// Get lowest price of all "Units" attribute options$prices = array();foreach ($node->attributes[1]->options as $opt) {$prices[] = $opt->price;}$output .= t('As low as !price', array('!price' => uc_currency_format(min($prices))));} -
Lightbox2 Slideshows with Multiple-value Imagefields
This is a pretty simple example that illustrates the use of Lightbox2’s slideshow feature. In the example, we have an imagefield that allows an unlimited number of images. We only want to render an imagecache version of the first image that, when clicked, will provide a slideshow with the rest of the images in the field. In the example, our field is called “field_product_images”.
The two files I’m showing are both within the theme for the site.
There are a few other options for achieving the same end result, but this seemed easier to explain and execute. Depending on your needs, you may need to make this happen at a deeper level (module) or in a field template/function override. If you have another approach, please post a comment!
12345678910111213141516171819202122232425262728/*** Override or insert variables into the node templates.** @param $vars* An array of variables to pass to the theme template.* @param $hook* The name of the template being rendered ("node" in this case.)*/function yourthemename_preprocess_node(&$vars, $hook) {if ($vars['node']->type == 'product') {// Loop through images for the product. Show the first image, and build the lightbox links to the other// images (more efficient than rendering the entire image and hiding it)// The field is configured to be a lightbox slideshow via Display Settings on the content type.if ($vars['node']->field_product_images[0]) {$vars['image_html'] = '';foreach($vars['node']->field_product_images as $key => $item) {if ($key == 0) {$vars['image_html'] .= $item['view'];}else {$vars['image_html'] .= '<div class="for-lightbox" style="display:none;">';$vars['image_html'] .= "<a href='/{$item['filepath']}' rel='lightshow[field_product_images][{$item['data']['title']}]'>Img</a>";$vars['image_html'] .= '</div>';}}}}}12345<?php if (isset($image_html)): ?><div class="field product-thumb"><?php print $image_html; ?></div><?php endif; ?>
12345// Because we may be showing multiple slideshows on a page (the store view// renders many products) let's add a unique identifier to the end of the group$orig_group = 'lightshow[field_product_images]';$new_group = "lightshow[field_product_images_{$vars['node']->nid}]";$vars['image_html'] = str_replace($orig_group, $new_group, $vars['image_html']);