Drupal

More complete breadcrumbs for Ubercart checkout

By default, Ubercart sets the breadcrumb on the checkout page to simply "Home", which I personally find a bit odd. Because it calls drupal_set_breadcrumb() late in the request cycle, it's not even possible to create menu links for use by the menu_breadcrumb or menutrails modules. Stranger still, the cart settings page offers a "Custom cart breadcrumb" text and URL option, but it's hard-coded to use a single link instead of a trail of links. Here is a small snippet that will set the breadcrumbs to mimic the URL paths, for example: Home › Cart › Checkout


Filed under:

By default, Ubercart sets the breadcrumb on the checkout page to simply "Home", which I personally find a bit odd. Because it calls drupal_set_breadcrumb() late in the request cycle, it's not even possible to create menu links for use by the menu_breadcrumb or menutrails modules. Stranger still, the cart settings page offers a "Custom cart breadcrumb" text and URL option, but it's hard-coded to use a single link instead of a trail of links.

Here is a small snippet that will set the breadcrumbs to mimic the URL paths, for example:

Home › Cart › Checkout

/**
 * Implementation of hook_preprocess_page().
 */
function mymodule_preprocess_page(&$variables) {
  /*
   * This section sets the breadcrumb on the cart pages hierarchically
   * according to the path elements.  A preprocess function is
   * needed instead of drupal_set_breadcrumb() because Ubercart
   * aleady calls drupal_set_breadcrumb() with undesirable results,
   * which also thwarts the menutrails module.
   */
  $menu = menu_get_item();
  if (preg_match('/^cart($|\/)/', $menu['path'])) {
    $crumbs = array(l(t('Home'), '<front>'));
    $paths = array();
    foreach ($menu['map'] as $arg) {
      $paths[] = $arg;
      $crumbs[] = l(ucfirst($arg), implode('/', $paths));
    }
   $variables['breadcrumb'] = theme('breadcrumb', $crumbs);
  }
}

Similar posts

Get notified on new marketing insights

Be the first to know about new B2B SaaS Marketing insights to build or refine your marketing function with the tools and knowledge of today’s industry.