array( 'arguments' => array('show_subtotal' => TRUE), ), ); } /* * hook_form_alter */ function uc_buyingclub_cart_form_alter(&$form, &$form_state, $form_id) { // make units show up in cart if ($form_id == 'uc_cart_view_form') { $form['items']['#columns']['unit'] = array( 'cell' => t('Unit'), 'weight' => 4, 'enabled' => true, ); $form['items']['#columns']['qty']['weight'] = 5; $form['items']['#columns']['total']['weight'] = 6; $i = 0; foreach ($form['#parameters'][2] as $item) { $n = node_load($item->nid); $form['items'][$i]['unit']['#value'] = $n->field_unit[0]['value']; $i = $i + 1; } } } function uc_buyingclub_cart_checkout_pane_alter(&$panes) { foreach ($panes as &$pane) { // make units show up in cart summary on checkout if ($pane['id'] == 'cart') { $pane['callback'] = 'uc_buyingclub_cart_checkout_pane_cart'; } } } function uc_buyingclub_cart_checkout_pane_cart($op) { switch ($op) { case 'view': // change the first table users see $contents['cart_review_table'] = array( '#value' => theme('uc_buyingclub_cart_review_table'), '#weight' => variable_get('uc_pane_cart_field_cart_weight', 2), ); return array('contents' => $contents, 'next-button' => FALSE); case 'review': // change the second, review table users see $items = uc_cart_get_contents(); $output = ''; $context = array( 'revision' => 'themed', 'type' => 'cart_item', 'subject' => array(), ); foreach ($items as $item) { $desc = check_plain($item->title) . uc_product_get_description($item); $node = node_load($item->nid); $price_info = array( 'price' => $item->price, 'qty' => $item->qty, ); $context['subject'] = array( 'cart' => $items, 'cart_item' => $item, 'node' => $node, ); $output .= ''; } $output .= '
'. $item->qty .'×'. $desc .''. $node->field_unit[0]['value'] .''. uc_price($price_info, $context) .'
'; $review[] = $output; return $review; } } function theme_uc_buyingclub_cart_review_table($show_subtotal = TRUE) { $subtotal = 0; // Set up table header. $header = array( array('data' => t('Qty'), 'class' => 'qty'), array('data' => t('Products'), 'class' => 'products'), array('data' => t('Unit'), 'class' => 'unit'), array('data' => t('Price'), 'class' => 'price'), ); $context = array(); // Set up table rows. $contents = uc_cart_get_contents(); foreach ($contents as $item) { $node = node_load($item->nid); $price_info = array( 'price' => $item->price, 'qty' => $item->qty, ); $context['revision'] = 'altered'; $context['type'] = 'cart_item'; $context['subject'] = array( 'cart' => $contents, 'cart_item' => $item, 'node' => $node, ); $total = uc_price($price_info, $context); $subtotal += $total; $description = check_plain($item->title) . uc_product_get_description($item); // Remove node from context to prevent the price from being altered. $context['revision'] = 'themed-original'; $context['type'] = 'amount'; unset($context['subject']); $rows[] = array( array('data' => t('@qty×', array('@qty' => $item->qty)), 'class' => 'qty'), array('data' => $description, 'class' => 'products'), array('data' => $node->field_unit[0]['value'], 'class' => 'unit'), array('data' => uc_price($total, $context), 'class' => 'price'), ); } // Add the subtotal as the final row. if ($show_subtotal) { $context = array( 'revision' => 'themed-original', 'type' => 'amount', ); $rows[] = array( 'data' => array(array('data' => '' . t('Subtotal:') . ' ' . uc_price($subtotal, $context), 'colspan' => 3, 'class' => 'subtotal')), 'class' => 'subtotal', ); } return theme('table', $header, $rows, array('class' => 'cart-review')); }