/** * Returns a structured array representing the given product's description. * * Modules that add data to cart items when they are selected should display it * with this hook. The return values from each implementation will be * sent through to hook_product_description_alter() implementations and then * all descriptions are rendered using drupal_render(). * * @param $product * Product. Usually one of the values of the array returned by * uc_cart_get_contents(). * * @return * A structured array that can be fed into drupal_render(). */ function hook_uc_product_description($product) { $description = array('attributes' => array('#product' => array('#type' => 'value', '#value' => $product), '#theme' => 'uc_product_attributes', '#weight' => 1)); $desc =& $description['attributes']; // Cart version of the product has numeric attribute => option values so we // need to retrieve the right ones $weight = 0; if (empty($product->order_id)) { foreach (_uc_cart_product_get_options($product) as $option) { if (!isset($desc[$option['aid']])) { $desc[$option['aid']]['#attribute_name'] = $option['attribute']; $desc[$option['aid']]['#options'] = array($option['name']); } else { $desc[$option['aid']]['#options'][] = $option['name']; } $desc[$option['aid']]['#weight'] = $weight++; } } else { foreach ((array) $product->data['attributes'] as $attribute => $option) { $desc[] = array('#attribute_name' => $attribute, '#options' => $option, '#weight' => $weight++); } } return $description; }
/** * Format data added to an item in the cart for display. * * Modules that add data to cart items when they are selected should display it * with this hook. The return values from each implementation will be * concatenated. * * @param $item * One of the values of the array returned by uc_cart_get_contents(). * @return * A formatted string to be displayed in the shopping cart block and on the * cart page. */ function hook_cart_item_description($item) { $rows = array(); foreach (_uc_cart_product_get_options($item) as $option) { $rows[] = t('@attribute: @option', array('@attribute' => $option['attribute'], '@option' => $option['name'])); } if (count($rows)) { $output = theme('item_list', $rows, NULL, 'ul', array('class' => 'product-description')); } return $output; }