uc_product.theme.inc 6.3 KB

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