uc_cart.theme.inc 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <?php
  2. /**
  3. * @file
  4. * Theme functions for the uc_cart module.
  5. */
  6. /**
  7. * Themes the shopping cart block title.
  8. *
  9. * @param $variables
  10. * An associative array containing:
  11. * - title: The text to use for the title of the block.
  12. * - icon_class: Class to use for the cart icon image or FALSE if the icon is
  13. * disabled.
  14. * - collapsible: TRUE or FALSE indicating whether or not the cart block is
  15. * collapsible.
  16. * - collapsed: TRUE or FALSE indicating whether or not the cart block is
  17. * collapsed.
  18. *
  19. * @ingroup themeable
  20. */
  21. function theme_uc_cart_block_title($variables) {
  22. $title = $variables['title'];
  23. $icon_class = $variables['icon_class'];
  24. $collapsible = $variables['collapsible'];
  25. $collapsed = $variables['collapsed'];
  26. $output = '';
  27. // Add in the cart image if specified.
  28. if ($icon_class) {
  29. $output .= theme('uc_cart_block_title_icon', array('icon_class' => $icon_class));
  30. }
  31. // Add the main title span and text, with or without the arrow based on the
  32. // cart block collapsibility settings.
  33. if ($collapsible) {
  34. $output .= '<span class="cart-block-title-bar" title="' . t('Show/hide shopping cart contents.') . '">' . $title;
  35. if ($collapsed) {
  36. $output .= '<span class="cart-block-arrow arrow-down"></span>';
  37. }
  38. else {
  39. $output .= '<span class="cart-block-arrow"></span>';
  40. }
  41. $output .= '</span>';
  42. }
  43. else {
  44. $output .= '<span class="cart-block-title-bar">' . $title . '</span>';
  45. }
  46. return $output;
  47. }
  48. /**
  49. * Themes the shopping cart icon.
  50. *
  51. * @param $variables
  52. * An associative array containing:
  53. * - icon_class: Class to use for the cart icon image, either cart-full or
  54. * cart-empty.
  55. *
  56. * @ingroup themeable
  57. */
  58. function theme_uc_cart_block_title_icon($variables) {
  59. $icon_class = $variables['icon_class'];
  60. return l('<span class="' . $icon_class . '" title="' . t('View your shopping cart.') . '"></span>', 'cart', array('html' => TRUE));
  61. }
  62. /**
  63. * Themes the shopping cart block content.
  64. *
  65. * @param $variables
  66. * An associative array containing:
  67. * - help_text: Text to place in the small help text area beneath the cart
  68. * block title or FALSE if disabled.
  69. * - items: An associative array of cart item information containing:
  70. * - qty: Quantity in cart.
  71. * - title: Item title.
  72. * - price: Item price.
  73. * - desc: Item description.
  74. * - item_count: The number of items in the shopping cart.
  75. * - item_text: A textual representation of the number of items in the
  76. * shopping cart.
  77. * - total: The unformatted total of all the products in the shopping cart.
  78. * - summary_links: An array of links used in the cart summary.
  79. * - collapsed: TRUE or FALSE indicating whether or not the cart block is
  80. * collapsed.
  81. *
  82. * @ingroup themeable
  83. */
  84. function theme_uc_cart_block_content($variables) {
  85. $help_text = $variables['help_text'];
  86. $items = $variables['items'];
  87. $item_count = $variables['item_count'];
  88. $item_text = $variables['item_text'];
  89. $total = $variables['total'];
  90. $summary_links = $variables['summary_links'];
  91. $collapsed = $variables['collapsed'];
  92. $output = '';
  93. // Add the help text if enabled.
  94. if ($help_text) {
  95. $output .= '<span class="cart-help-text">' . $help_text . '</span>';
  96. }
  97. // Add a table of items in the cart or the empty message.
  98. $output .= theme('uc_cart_block_items', array('items' => $items, 'collapsed' => $collapsed));
  99. // Add the summary section beneath the items table.
  100. $output .= theme('uc_cart_block_summary', array('item_count' => $item_count, 'item_text' => $item_text, 'total' => $total, 'summary_links' => $summary_links));
  101. return $output;
  102. }
  103. /**
  104. * Themes the table listing the items in the shopping cart block.
  105. *
  106. * @param $variables
  107. * An associative array containing:
  108. * - items: An associative array of cart item information containing:
  109. * - qty: Quantity in cart.
  110. * - title: Item title.
  111. * - price: Item price.
  112. * - desc: Item description.
  113. * - collapsed: TRUE or FALSE indicating whether or not the cart block is
  114. * collapsed.
  115. *
  116. * @ingroup themeable
  117. */
  118. function theme_uc_cart_block_items($variables) {
  119. $items = $variables['items'];
  120. $class = $variables['collapsed'] ? 'cart-block-items collapsed' : 'cart-block-items';
  121. // If there are items in the shopping cart...
  122. if ($items) {
  123. $output = '<table class="' . $class . '"><tbody>';
  124. // Loop through each item.
  125. $row_class = 'odd';
  126. foreach ($items as $item) {
  127. // Add the basic row with quantity, title, and price.
  128. $output .= '<tr class="' . $row_class . '"><td class="cart-block-item-qty">' . $item['qty'] . '</td>'
  129. . '<td class="cart-block-item-title">' . $item['title'] . '</td>'
  130. . '<td class="cart-block-item-price">' . theme('uc_price', array('price' => $item['price'])) . '</td></tr>';
  131. // Add a row of description if necessary.
  132. if ($item['desc']) {
  133. $output .= '<tr class="' . $row_class . '"><td colspan="3" class="cart-block-item-desc">' . $item['desc'] . '</td></tr>';
  134. }
  135. // Alternate the class for the rows.
  136. $row_class = ($row_class == 'odd') ? 'even' : 'odd';
  137. }
  138. $output .= '</tbody></table>';
  139. }
  140. else {
  141. // Otherwise display an empty message.
  142. $output = '<p class="' . $class . ' uc-cart-empty">' . t('There are no products in your shopping cart.') . '</p>';
  143. }
  144. return $output;
  145. }
  146. /**
  147. * Themes the summary table at the bottom of the default shopping cart block.
  148. *
  149. * @param $variables
  150. * An associative array containing:
  151. * - item_count: The number of items in the shopping cart.
  152. * - item_text: A textual representation of the number of items in the
  153. * shopping cart.
  154. * - total: The unformatted total of all the products in the shopping cart.
  155. * - summary_links: An array of links used in the summary.
  156. *
  157. * @ingroup themeable
  158. */
  159. function theme_uc_cart_block_summary($variables) {
  160. $item_count = $variables['item_count'];
  161. $item_text = $variables['item_text'];
  162. $total = $variables['total'];
  163. $summary_links = $variables['summary_links'];
  164. // Build the basic table with the number of items in the cart and total.
  165. $output = '<table class="cart-block-summary"><tbody><tr>'
  166. . '<td class="cart-block-summary-items">' . $item_text . '</td>'
  167. . '<td class="cart-block-summary-total"><label>' . t('Total:')
  168. . '</label> ' . theme('uc_price', array('price' => $total)) . '</td></tr>';
  169. // If there are products in the cart...
  170. if ($item_count > 0) {
  171. // Add a view cart link.
  172. $output .= '<tr class="cart-block-summary-links"><td colspan="2">'
  173. . theme('links', array('links' => $summary_links)) . '</td></tr>';
  174. }
  175. $output .= '</tbody></table>';
  176. return $output;
  177. }
  178. /**
  179. * Themes the uc_cart_view_form().
  180. *
  181. * Outputs a hidden copy of the update cart button first, so pressing Enter
  182. * updates the cart instead of removing an item.
  183. *
  184. * @param $variables
  185. * An associative array containing:
  186. * - form: A render element representing the form.
  187. *
  188. * @see uc_cart_view_form()
  189. * @ingroup themeable
  190. */
  191. function theme_uc_cart_view_form($variables) {
  192. $form = &$variables['form'];
  193. $output = '<div class="uc-default-submit">';
  194. $output .= drupal_render($form['actions']['update']);
  195. $output .= '</div>';
  196. $form['actions']['update']['#printed'] = FALSE;
  197. $output .= drupal_render_children($form);
  198. return $output;
  199. }
  200. /**
  201. * Themes the cart checkout button(s).
  202. *
  203. * @param $variables
  204. * An associative array containing:
  205. * - buttons: A render element representing the form buttons.
  206. *
  207. * @see uc_cart_view_form()
  208. * @ingroup themeable
  209. */
  210. function theme_uc_cart_checkout_buttons($variables) {
  211. $output = '';
  212. if ($buttons = element_children($variables['buttons'])) {
  213. // Render the first button.
  214. $button = array_shift($buttons);
  215. $output = drupal_render($variables['buttons'][$button]);
  216. // Render any remaining buttons inside a separate container.
  217. if ($buttons) {
  218. $output .= '<div class="uc-cart-checkout-button-container clearfix">';
  219. // Render the second button.
  220. $output .= '<div class="uc-cart-checkout-button">';
  221. $output .= '<div class="uc-cart-checkout-button-separator">' . t('- or -') . '</div>';
  222. $button = array_shift($buttons);
  223. $output .= drupal_render($variables['buttons'][$button]);
  224. $output .= '</div>';
  225. // Render any remaining buttons.
  226. foreach ($buttons as $button) {
  227. $output .= '<div class="uc-cart-checkout-button">';
  228. $output .= drupal_render($variables['buttons'][$button]);
  229. $output .= '</div>';
  230. }
  231. $output .= '</div>';
  232. }
  233. }
  234. return $output;
  235. }
  236. /**
  237. * Returns the text displayed for an empty shopping cart.
  238. *
  239. * @ingroup themeable
  240. */
  241. function theme_uc_empty_cart() {
  242. return '<p class="uc-cart-empty">' . t('There are no products in your shopping cart.') . '</p>';
  243. }
  244. /**
  245. * Themes the sale completion page.
  246. *
  247. * @param $variables
  248. * An associative array containing:
  249. * - message: Message containing order number info, account info, and link to
  250. * continue shopping.
  251. *
  252. * @ingroup themeable
  253. */
  254. function theme_uc_cart_complete_sale($variables) {
  255. return $variables['message'];
  256. }