Fix for template.php for D5 theming of UC checkout and cart

  1. /**
  2.  * Overriding theme_uc_cart_block_content() to hide
  3.  * TOTAL from Wholesalers
  4.  *
  5.  * Theme the shopping cart block content.
  6.  */
  7. function phptemplate_uc_cart_block_content() {
  8.   global $user;
  9.  
  10.   // Disabled until we figure out if this is actually screwing up caching. -RS
  11.   //if (!$user->uid && variable_get('cache', 0) !== 0) {
  12.   //  return t('<a href="!url">View</a> your shopping cart.', array('!url' => url('cart')));
  13.   //}
  14.  
  15.   if (variable_get('uc_cart_show_help_text', FALSE)) {
  16.     $output = '<span class="cart-help-text">'
  17.             . variable_get('uc_cart_help_text', t('Click title to display cart contents.'))
  18.              .'</span>';
  19.   }
  20.  
  21.   $output .= '<div id="block-cart-contents">';
  22.  
  23.   $items = uc_cart_get_contents();
  24.  
  25.   $item_count = 0;
  26.   if (!empty($items)) {
  27.     $output .= '<table class="cart-block-table">'
  28.               .'<tbody class="cart-block-tbody">';
  29.     foreach ($items as $item) {
  30.       $display_item = module_invoke($item->module, 'cart_display', $item);
  31.       if (!empty($display_item)) {
  32.         $output .= '<tr class="cart-block-item"><td class="cart-block-item-qty">'. $display_item['qty']['#default_value'] .'x</td>'
  33.                   .'<td class="cart-block-item-title">'. $display_item['title']['#value'] .'</td>'
  34.                   .'<td class="cart-block-item-price">'. uc_currency_format($display_item['#total']) .'</td></tr>';
  35.         if ($display_item['options']['#value']) {
  36.           $output .= '<tr><td colspan="3">'. $display_item['options']['#value'] .'</td></tr>';
  37.         }
  38.       }
  39.       $total += ($item->price) * $item->qty;
  40.       $item_count += $item->qty;
  41.     }
  42.  
  43.     $output .= '</tbody></table>';
  44.   }
  45.   else {
  46.     $output .= '<p>'. t('There are no products in your shopping cart.') .'</p>';
  47.   }
  48.  
  49.   $output .= '</div>';
  50.  
  51.   $item_text = format_plural($item_count, '@count Item', '@count Items');
  52.   $view = ''. l(t('View cart'), 'cart', array('rel' => 'nofollow')) .'';
  53.   if (variable_get('uc_checkout_enabled', TRUE)) {
  54.     $checkout = ' '. l(t('CHECKOUT'), 'cart', array('rel' => 'nofollow')) .'';
  55.   }
  56.   $uc_cart_path = base_path() . drupal_get_path('module', 'uc_cart');
  57.   $arrow_up_image = $uc_cart_path .'/images/bullet-arrow-up.gif';
  58.  
  59.   // do not show total to wholesale users
  60.   if (in_array('Wholesale', $user->roles)) {
  61.     $output .= '<ul id="shopDeetsList">'
  62.             .'<li>BASKET ITEMS: '
  63.             . str_replace('ITEMS', '', strtoupper($item_text)) . '</li>';
  64.   } else {
  65.     $output .= '<ul id="shopDeetsList">'
  66.             .'<li>BASKET ITEMS: '
  67.             . str_replace('ITEMS', '', strtoupper($item_text)) . '</li><li>'
  68.             //.'<span class="block-cart-title-bar cart-block-toggle" id="block-cart-title-bar-arrow"><img id="block-cart-title-arrow" src="'. $arrow_up_image .'" alt="[]" title="'. t('Expand cart block.') .'" /></span>' . '</li><li>'
  69.             .'<strong>'. t('TOTAL:') .'</strong> '. uc_currency_format($total) .'</li>';
  70.   }
  71.  
  72.   if ($item_count >= 0) {
  73.     //$output .= '<li>'. $checkout .'</li><li>'. $view .'</li>';
  74.     if($user->uid != 0){
  75.       $output .= '<li>'. $checkout .'</li><li class="last"><a href="/logout">SIGN-OUT</a></li>';
  76.     }
  77.     else{
  78.       $output .= '<li>'. $checkout .'</li><li class="last"><a href="/user">SIGN-IN</a></li>';
  79.     }
  80.    
  81.   }
  82.   $output .= '</ul>';
  83.  
  84.   return $output;
  85. }
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. /**
  94.  * Overriding theme_uc_cart_view_form() to hide
  95.  * prices from Wholesalers
  96.  *
  97.  * Theme the shopping cart block content.
  98.  */
  99. function phptemplate_uc_cart_view_form($form) {
  100.  
  101.   drupal_add_css(drupal_get_path('module', 'uc_cart') .'/uc_cart.css');
  102.  
  103.   $output = '<div id="cart-form-products">'
  104.           . tapir_get_table('uc_cart_view_table', $form) .'</div>';
  105.  
  106.   if (($page = variable_get('uc_continue_shopping_url', '')) != '<none>') {
  107.     if (variable_get('uc_continue_shopping_type', 'link') == 'link') {
  108.       $output .= '<div id="cart-form-buttons"><div id="continue-shopping-link">'
  109.                . l(variable_get('uc_continue_shopping_text', t('Continue shopping')), $page) .'</div>'
  110.                . drupal_render($form) .'</div>';
  111.     }
  112.     else {
  113.       $button = drupal_render($form['continue_shopping']);
  114.       $output .= '<div id="cart-form-buttons"><div id="update-checkout-buttons">'
  115.                . drupal_render($form) .'</div><div id="continue-shopping-button">'
  116.                . $button .'</div></div>';
  117.     }
  118.   }
  119.   else {
  120.     $output .= '<div id="cart-form-buttons">'. drupal_render($form) .'</div>';
  121.   }
  122.  
  123.   return $output;
  124. }
  125.  
  126.  
  127. /**
  128.  * Theme the checkout review order page.
  129.  *
  130.  * @param $help
  131.  *   A string containing the review order page help message.
  132.  * @param $panes
  133.  *   An associative array for each checkout pane that has information to add to
  134.  *   the review page.  The key is the pane's title and the value is either the
  135.  *   data returned for that pane or an array of returned data.
  136.  * @param $form
  137.  *   The HTML version of the form that by default includes the 'Back' and
  138.  *   'Submit order' buttons at the bottom of the review page.
  139.  * @return
  140.  *   A string of HTML for the page contents.
  141.  * @ingroup themeable
  142.  */
  143. function phptemplate_uc_cart_checkout_review($help, $panes, $form) {
  144.   drupal_add_css(drupal_get_path('module', 'uc_cart') .'/uc_cart.css');
  145.  
  146.   $output = '<div>'. check_markup(variable_get('uc_checkout_review_instructions',  uc_get_message('review_instructions')), variable_get('uc_checkout_review_instructions_format', 3), FALSE)
  147.            .'</div><table class="order-review-table">';
  148.  
  149.   foreach ($panes as $title => $data) {
  150.     $output .= '<tr class="pane-title-row"><td colspan="2">'. $title
  151.               .'</td></tr>';
  152.     if (is_array($data)) {
  153.       foreach ($data as $row) {
  154.         if (is_array($row)) {
  155.           if (isset($row['border'])) {
  156.             $border = ' class="row-border-'. $row['border'] .'"';
  157.           }
  158.           else {
  159.             $border = '';
  160.           }
  161.           $output .= '<tr valign="top"'. $border .'><td class="title-col" '
  162.                     .'nowrap>'. $row['title'] .':</td><td class="data-col">'
  163.                    . $row['data'] .'</td></tr>';
  164.         }
  165.         else {
  166.           $output .= '<tr valign="top"><td colspan="2">'. $row .'</td></tr>';
  167.         }
  168.       }
  169.     }
  170.     else {
  171.       $output .= '<tr valign="top"><td colspan="2">'. $data .'</td></tr>';
  172.     }
  173.   }
  174.  
  175.   $output .= '<tr class="review-button-row"><td colspan="2">'. $form
  176.             .'</td></tr></table>';
  177.  
  178.   return $output;
  179. }
  180.  
  181.  
  182. /*
  183.  * Checkout page pane theming
  184.  */
  185. function phptemplate_uc_cart_checkout_form($form) {
  186.   drupal_add_css(drupal_get_path('module', 'uc_cart') .'/uc_cart.css');
  187.  
  188.   $output = '<div>'. check_markup(variable_get('uc_checkout_instructions', ''), variable_get('uc_checkout_instructions_format', 3), FALSE) .'</div>';
  189.  
  190.   if (arg(1) == 'checkout2') {
  191.     foreach (element_children($form['panes']) as $pane_id) {
  192.       $output .= drupal_render($form['panes'][$pane_id]);
  193.     }
  194.   }
  195.   else {
  196.     foreach (element_children($form['panes']) as $pane_id) {
  197.       if (function_exists(($func = _checkout_pane_data($pane_id, 'callback')))) {
  198.         $result = $func('theme', $form['panes'][$pane_id], NULL);
  199.         if (!empty($result)) {
  200.           $output .= $result;
  201.           $form['panes'][$pane_id] = array();
  202.         }
  203.         else {
  204.           $output .= drupal_render($form['panes'][$pane_id]);
  205.         }
  206.       }
  207.       else {
  208.         $output .= drupal_render($form['panes'][$pane_id]);
  209.       }
  210.     }
  211.   }
  212.  
  213.   $output .= '<div id="checkout-form-bottom">'. drupal_render($form) .'</div>';
  214.   $output .= '<div class="clearfix"></div>';
  215.  
  216.   return $output;
  217. }
  218.  
  219. /*
  220.  * Cart pane in the checkout
  221.  */
  222. function phptemplate_cart_review_table($show_subtotal = TRUE) {
  223.   $items = uc_cart_get_contents();
  224.   $subtotal = 0;
  225.  
  226.   $output = '<table class="cart-review" id="checkout-product-table" width="100%"><thead>'
  227.            .'<tr class="first odd">'
  228.            // add picture to table head
  229.            .'<th class="first picture"></th>'
  230.            .'<th class="products">'. t('Products')
  231.            .'</th><th class="qty">'. t('Quantity')
  232.            .'</th><th class="unit">'. t('Unit')
  233.            .'</th><th class="last price">'. t('Total')
  234.            .'</th>'
  235.            .'</tr></thead><tbody>';
  236.  
  237.   $row = 1;
  238.   for ($i = 0; $i < count($items); $i++) {
  239.    
  240.     $item = $items[$i];
  241.     $rows = array();
  242.     foreach ($item->options as $option) {
  243.       $rows[] = t('@attribute: @option', array('@attribute' => $option['attribute'], '@option' => $option['name']));
  244.     }
  245.     $desc = check_plain($item->title) . theme('item_list', $rows, NULL, 'ul', array('class' => 'cart-options'));
  246.  
  247.     $total = ($item->qty) ? $item->qty * $item->price : $item->price;
  248.     $subtotal += $total;
  249.     $qty = ($item->qty) ? $item->qty : '';
  250.     $tr_class = ($i % 2 == 0) ? 'even' : 'odd';
  251.     if ($show_subtotal && $i == count($items)) {
  252.       $tr_class .= ' last';
  253.     }
  254.  
  255.     $output .= '<tr class="'. $tr_class .'">'
  256.              // we add in the picture
  257.              . '<td class="picture">'
  258.              . uc_product_get_picture($item->nid, 'cart')
  259.              . '</td>'
  260.              // end
  261.              .'<td class="products">'
  262.              . $desc .'</td>'
  263.              . '<td class="qty">'
  264.              . t('!qtyx', array('!qty' => $qty)) .'</td>'
  265.              . '<td class="unit">'. uc_currency_format($item->price)
  266.              . '</td>'
  267.              . '<td class="unit">'. uc_currency_format($total)
  268.              . '</td>'
  269.              . '</tr>';
  270.   }
  271.   if ($show_subtotal) {
  272.     $tr_class = ($tr_class == 'even') ? 'odd' : 'even';
  273.     // re-jig this for theming:
  274.     $output .= '<tr class="'. $tr_class .' last">'
  275.               .'<td colspan="3" class="subtotal-spacer">&nbsp;</td>'
  276.               .'<td class="subtotal-text">'
  277.               .'<strong>'. t('Total:') .'</strong>'
  278.               .'</td>'
  279.               .'<td class="subtotal">'
  280.               . uc_currency_format($subtotal) .'</td></tr>';
  281.   }
  282.   $output .= '</tbody></table>';
  283.  
  284.   return $output;
  285. }
  286.  
  287. // Theme the delivery/billing address forms in tables.
  288. function phptemplate_address_pane($form) {
  289.  
  290.   $req = '<span class="form-required">*</span>';
  291.  
  292.   if (isset($form['copy_address'])) {
  293.     $output = drupal_render($form['copy_address']);
  294.   }
  295.  
  296.   // show the billing address message (taken from credit card pane) here
  297.   if ($form['#attributes']['id'] == 'billing-pane') {
  298.     $output .= '<div class="billing-address-message">' . variable_get('uc_credit_policy', '') . '</div>';
  299.   }
  300.  
  301.   $output .= '<div class="address-pane-table"><table>';
  302.  
  303.   foreach (element_children($form) as $field) {
  304.     if (substr($field, 0, 9) == 'delivery_' || substr($field, 0, 8) == 'billing_') {
  305.       $title = $form[$field]['#title'] .':';
  306.       unset($form[$field]['#title']);
  307.       if (substr($field, -7) == 'street1') {
  308.         $title = uc_get_field_name('street') .':';
  309.       }
  310.       elseif (substr($field, -7) == 'street2') {
  311.         $title = ' ';
  312.       }
  313.       // we added field name as a class
  314.       $output .= '<tr><td class="field-label '.substr($field, -7).'">';
  315.       if ($form[$field]['#required']) {
  316.         $output .= $req;
  317.       }
  318.       $output .= $title .'</td><td>'. drupal_render($form[$field]) .'</td></tr>';
  319.     }
  320.   }
  321.   $output .= '</table></div>';
  322.  
  323.   foreach (element_children($form) as $element) {
  324.     $output .= drupal_render($form[$element]);
  325.   }
  326.  
  327.   return $output;
  328. }
  329.  
  330. // Themes the form to be in a compact table.
  331. // This is the credit card pane if you are using a payment gateway.
  332. function phptemplate_uc_payment_method_credit_form($form) {
  333.   // Comment out this function to just straight display the form.
  334.   $form['cc_number']['#title'] = '';
  335.   $form['cc_start_month']['#title'] = '';
  336.   $form['cc_start_year']['#title'] = '';
  337.   $form['cc_exp_month']['#title'] = '';
  338.   $form['cc_exp_year']['#title'] = '';
  339.   $form['cc_issue']['#title'] = '';
  340.  
  341.   if (arg(1) == 'checkout') {
  342.     $path = base_path() . drupal_get_path('module', 'uc_credit');
  343.     $output = '<table class="inline-pane-table" cellpadding="2">';
  344.     // we don't want this here - we want it up with the billing address pane
  345.     //if (strlen($form['cc_policy']) > 0) {
  346.       // added a class here for theming the warning message
  347.       //$output .= '<tr><td colspan="2" class="billing-message">'. variable_get('uc_credit_policy', '')
  348.       //          .'</td></tr>';
  349.     //}
  350.     if (variable_get('uc_credit_type_enabled', FALSE)) {
  351.       $form['cc_type']['#title'] = '';
  352.       $output .= '<tr><td class="field-label">'. t('Card Type:') .'</td><td>'
  353.                . drupal_render($form['cc_type']) .'</td></tr>';
  354.     }
  355.     if (variable_get('uc_credit_owner_enabled', FALSE)) {
  356.       $form['cc_owner']['#title'] = '';
  357.       $output .= '<tr><td class="field-label">'. t('Card Owner:') .'</td><td>'
  358.                . drupal_render($form['cc_owner']) .'</td></tr>';
  359.     }
  360.     $output .= '<tr><td class="field-label">'. t('Card Number:') .'</td><td>'
  361.              . drupal_render($form['cc_number']) .'</td></tr>';
  362.     if (variable_get('uc_credit_start_enabled', FALSE)) {
  363.       $output .= '<tr><td class="field-label">'. t('Start Date:') .'</td><td>'
  364.                . drupal_render($form['cc_start_month']) .' '. drupal_render($form['cc_start_year'])
  365.                 .' '. t('(if present)') .'</td></tr>';
  366.     }
  367.     $output .= '<tr><td class="field-label">'. t('Expiration Date:') .'</td><td>'
  368.              . drupal_render($form['cc_exp_month']) .' '
  369.              . drupal_render($form['cc_exp_year']) .'</td></tr>';
  370.     if (variable_get('uc_credit_issue_enabled', FALSE)) {
  371.       $output .= '<tr><td class="field-label">'. t('Issue Number:') .'</td><td>'
  372.                . drupal_render($form['cc_issue']) .' '. t('(if present)').'</td></tr>';
  373.     }
  374.     if (variable_get('uc_credit_cvv_enabled', TRUE)) {
  375.       $form['cc_cvv']['#title'] = '';
  376.       $output .= '<tr><td class="field-label">'. t('CVV:') .'</td><td>'. drupal_render($form['cc_cvv'])
  377.                 .' <img src="'. $path .'/images/info.png" onclick="cvv_info_popup();" style="cursor: pointer; position: relative; top: 3px;"> <a style="cursor: pointer; font-weight: normal;" onclick="cvv_info_popup();">'
  378.                 . t("What's the CVV?") .'</a></td></tr>';
  379.     }
  380.     if (variable_get('uc_credit_bank_enabled', FALSE)) {
  381.       $form['cc_bank']['#title'] = '';
  382.       $output .= '<tr><td class="field-label">'. t('Issuing Bank:') .'</td><td>'
  383.                . drupal_render($form['cc_bank']) .'</td></tr>';
  384.     }
  385.     $output .= '</table>';
  386.   }
  387.   else {
  388.     $output = '<table class="order-edit-table"><tbody style="border-top: 0px;">';
  389.     if (variable_get('uc_credit_type_enabled', FALSE)) {
  390.       $form['cc_type']['#title'] = '';
  391.       $output .= '<tr><td class="oet-label">'. t('Card Type:') .'</td><td>'
  392.                . drupal_render($form['cc_type']) .'</td></tr>';
  393.     }
  394.     if (variable_get('uc_credit_owner_enabled', FALSE)) {
  395.       $form['cc_owner']['#title'] = '';
  396.       $output .= '<tr><td class="oet-label">'. t('Card Owner:') .'</td><td>'
  397.                . drupal_render($form['cc_owner']) .'</td></tr>';
  398.     }
  399.     $output .= '<tr><td class="oet-label">'. t('Card Number:') .'</td><td>'
  400.              . drupal_render($form['cc_number']) .'</td></tr>';
  401.     $output .= '<tr><td class="oet-label">'. t('Expiration Date:') .'</td><td>'
  402.              . drupal_render($form['cc_exp_month']) .' '
  403.              . drupal_render($form['cc_exp_year']) .'</td></tr>';
  404.     if (variable_get('uc_credit_cvv_enabled', TRUE)) {
  405.       $form['cc_cvv']['#title'] = '';
  406.       $output .= '<tr><td class="oet-label">'. t('CVV:') .'</td><td>'
  407.                . drupal_render($form['cc_cvv']) .'</td></tr>';
  408.     }
  409.     if (variable_get('uc_credit_bank_enabled', FALSE)) {
  410.       $form['cc_bank']['#title'] = '';
  411.       $output .= '<tr><td class="oet-label">'. t('Issuing Bank:') .'</td><td>'
  412.                . drupal_render($form['cc_bank']) .'</td></tr>';
  413.     }
  414.     $output .= '</td></tr></tbody></table>';
  415.   }
  416.  
  417.   return $output;
  418. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.