uc_cart.theme.inc 9.1 KB

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