uc_product.theme.inc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. /**
  3. * @file
  4. * Theme functions for uc_product module.
  5. */
  6. /**
  7. * Formats a product's model number.
  8. *
  9. * @param array $variables
  10. * An associative array containing:
  11. * - model: Product model number, also known as SKU.
  12. * - attributes: (optional) Array of attributes to apply to enclosing DIV.
  13. *
  14. * @return string
  15. * The HTML output.
  16. *
  17. * @ingroup themeable
  18. */
  19. function theme_uc_product_model($variables) {
  20. $model = $variables['model'];
  21. $attributes = $variables['attributes'];
  22. $attributes['class'][] = "product-info";
  23. $attributes['class'][] = "model";
  24. $output = '<div ' . drupal_attributes($attributes) . '>';
  25. $output .= '<span class="product-info-label">' . t('SKU') . ':</span> ';
  26. $output .= '<span class="product-info-value">' . check_plain($model) . '</span>';
  27. $output .= '</div>';
  28. return $output;
  29. }
  30. /**
  31. * Wraps the "Add to Cart" form in a <div>.
  32. *
  33. * @param array $variables
  34. * An associative array containing:
  35. * - form: A render element representing the add-to-cart form.
  36. *
  37. * @ingroup themeable
  38. */
  39. function theme_uc_product_add_to_cart($variables) {
  40. $form = $variables['form'];
  41. $output = '<div class="add-to-cart">';
  42. $output .= drupal_render($form);
  43. $output .= '</div>';
  44. return $output;
  45. }
  46. /**
  47. * Formats a product's price.
  48. *
  49. * @param array $variables
  50. * An associative array containing:
  51. * - element: An associative array render element containing:
  52. * - #value: Price to be formatted.
  53. * - #attributes: (optional) Array of attributes to apply to enclosing DIV.
  54. * - #title: (optional) Title to be used as label.
  55. *
  56. * @ingroup themeable
  57. */
  58. function theme_uc_product_price($variables) {
  59. $element = $variables['element'];
  60. $price = $element['#value'];
  61. $attributes = isset($element['#attributes']) ? $element['#attributes'] : array();
  62. $label = isset($element['#title']) ? $element['#title'] : '';
  63. if (isset($attributes['class'])) {
  64. array_unshift($attributes['class'], 'product-info');
  65. }
  66. else {
  67. $attributes['class'] = array('product-info');
  68. }
  69. $output = '<div ' . drupal_attributes($attributes) . '>';
  70. if ($label) {
  71. $output .= '<span class="uc-price-label">' . $label . '</span> ';
  72. }
  73. $vars = array('price' => $price);
  74. if (!empty($element['#suffixes'])) {
  75. $vars['suffixes'] = $element['#suffixes'];
  76. }
  77. $output .= theme('uc_price', $vars);
  78. $output .= drupal_render_children($element);
  79. $output .= '</div>';
  80. return $output;
  81. }
  82. /**
  83. * Formats a product's weight.
  84. *
  85. * @param array $variables
  86. * An associative array containing:
  87. * - amount: A numerical weight value.
  88. * - units: String abbreviation representing the units of measure.
  89. * - attributes: (optional) Array of attributes to apply to enclosing DIV.
  90. *
  91. * @see uc_weight_format()
  92. *
  93. * @ingroup themeable
  94. */
  95. function theme_uc_product_weight($variables) {
  96. $amount = $variables['amount'];
  97. $units = $variables['units'];
  98. $attributes = $variables['attributes'];
  99. $attributes['class'][] = "product-info";
  100. $attributes['class'][] = "weight";
  101. $output = '';
  102. if ($amount) {
  103. $output = '<div ' . drupal_attributes($attributes) . '>';
  104. $output .= '<span class="product-info-label">' . t('Weight') . ':</span> ';
  105. $output .= '<span class="product-info-value">' . uc_weight_format($amount, $units) . '</span>';
  106. $output .= '</div>';
  107. }
  108. return $output;
  109. }
  110. /**
  111. * Formats a product's length, width, and height.
  112. *
  113. * @param array $variables
  114. * An associative array containing:
  115. * - length: A numerical length value.
  116. * - width: A numerical width value.
  117. * - height: A numerical height value.
  118. * - units: String abbreviation representing the units of measure.
  119. * - attributes: (optional) Array of attributes to apply to enclosing DIV.
  120. *
  121. * @see uc_length_format()
  122. *
  123. * @ingroup themeable
  124. */
  125. function theme_uc_product_dimensions($variables) {
  126. $length = $variables['length'];
  127. $width = $variables['width'];
  128. $height = $variables['height'];
  129. $units = $variables['units'];
  130. $attributes = $variables['attributes'];
  131. $attributes['class'][] = "product-info";
  132. $attributes['class'][] = "dimensions";
  133. $output = '';
  134. if ($length || $width || $height) {
  135. $output = '<div ' . drupal_attributes($attributes) . '>';
  136. $output .= '<span class="product-info-label">' . t('Dimensions') . ':</span> ';
  137. $output .= '<span class="product-info-value">';
  138. $output .= uc_length_format($length, $units) . ' × ';
  139. $output .= uc_length_format($width, $units) . ' × ';
  140. $output .= uc_length_format($height, $units) . '</span>';
  141. $output .= '</div>';
  142. }
  143. return $output;
  144. }
  145. /**
  146. * Formats a product's images.
  147. *
  148. * @param array $variables
  149. * - images: An array of image render elements, each containing:
  150. * - uri: URI of image.
  151. * - alt: Alternate text to display for image.
  152. * - title: Title for image.
  153. *
  154. * @see theme_image_style()
  155. *
  156. * @ingroup themeable
  157. */
  158. function theme_uc_product_image($variables) {
  159. static $rel_count = 0;
  160. $images = $variables['images'];
  161. // Get the current product image widget.
  162. $image_widget = uc_product_get_image_widget();
  163. $first = array_shift($images);
  164. $output = '<div class="product-image"><div class="main-product-image">';
  165. $output .= '<a href="' . image_style_url('uc_product_full', $first['uri']) . '" title="' . $first['title'] . '"';
  166. if ($image_widget) {
  167. $image_widget_func = $image_widget['callback'];
  168. $output .= $image_widget_func($rel_count);
  169. }
  170. $output .= '>';
  171. $output .= theme('image_style', array(
  172. 'style_name' => 'uc_product',
  173. 'path' => $first['uri'],
  174. 'alt' => $first['alt'],
  175. 'title' => $first['title'],
  176. ));
  177. $output .= '</a></div>';
  178. if (!empty($images)) {
  179. $output .= '<div class="more-product-images">';
  180. foreach ($images as $thumbnail) {
  181. // Node preview adds extra values to $images that aren't files.
  182. if (!is_array($thumbnail) || empty($thumbnail['uri'])) {
  183. continue;
  184. }
  185. $output .= '<a href="' . image_style_url('uc_product_full', $thumbnail['uri']) . '" title="' . $thumbnail['title'] . '"';
  186. if ($image_widget) {
  187. $output .= $image_widget_func($rel_count);
  188. }
  189. $output .= '>';
  190. $output .= theme('image_style', array(
  191. 'style_name' => 'uc_thumbnail',
  192. 'path' => $thumbnail['uri'],
  193. 'alt' => $thumbnail['alt'],
  194. 'title' => $thumbnail['title'],
  195. ));
  196. $output .= '</a>';
  197. }
  198. $output .= '</div>';
  199. }
  200. $output .= '</div>';
  201. $rel_count++;
  202. return $output;
  203. }