uc_product.theme.inc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. * @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 $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 $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 $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. * @ingroup themeable
  93. */
  94. function theme_uc_product_weight($variables) {
  95. $amount = $variables['amount'];
  96. $units = $variables['units'];
  97. $attributes = $variables['attributes'];
  98. $attributes['class'][] = "product-info";
  99. $attributes['class'][] = "weight";
  100. $output = '';
  101. if ($amount) {
  102. $output = '<div ' . drupal_attributes($attributes) . '>';
  103. $output .= '<span class="product-info-label">' . t('Weight') . ':</span> ';
  104. $output .= '<span class="product-info-value">' . uc_weight_format($amount, $units) . '</span>';
  105. $output .= '</div>';
  106. }
  107. return $output;
  108. }
  109. /**
  110. * Formats a product's length, width, and height.
  111. *
  112. * @param $variables
  113. * An associative array containing:
  114. * - length: A numerical length value.
  115. * - width: A numerical width value.
  116. * - height: A numerical height value.
  117. * - units: String abbreviation representing the units of measure.
  118. * - attributes: (optional) Array of attributes to apply to enclosing DIV.
  119. *
  120. * @see uc_length_format()
  121. * @ingroup themeable
  122. */
  123. function theme_uc_product_dimensions($variables) {
  124. $length = $variables['length'];
  125. $width = $variables['width'];
  126. $height = $variables['height'];
  127. $units = $variables['units'];
  128. $attributes = $variables['attributes'];
  129. $attributes['class'][] = "product-info";
  130. $attributes['class'][] = "dimensions";
  131. $output = '';
  132. if ($length || $width || $height) {
  133. $output = '<div ' . drupal_attributes($attributes) . '>';
  134. $output .= '<span class="product-info-label">' . t('Dimensions') . ':</span> ';
  135. $output .= '<span class="product-info-value">' ;
  136. $output .= uc_length_format($length, $units) . ' × ';
  137. $output .= uc_length_format($width, $units) . ' × ';
  138. $output .= uc_length_format($height, $units) . '</span>';
  139. $output .= '</div>';
  140. }
  141. return $output;
  142. }
  143. /**
  144. * Formats a product's images.
  145. *
  146. * @param $variables
  147. * - images: An array of image render elements, each containing:
  148. * - uri: URI of image.
  149. * - alt: Alternate text to display for image.
  150. * - title: Title for image.
  151. *
  152. * @see theme_image_style()
  153. * @ingroup themeable
  154. */
  155. function theme_uc_product_image($variables) {
  156. static $rel_count = 0;
  157. $images = $variables['images'];
  158. // Get the current product image widget.
  159. $image_widget = uc_product_get_image_widget();
  160. $first = array_shift($images);
  161. $output = '<div class="product-image"><div class="main-product-image">';
  162. $output .= '<a href="' . image_style_url('uc_product_full', $first['uri']) . '" title="' . $first['title'] . '"';
  163. if ($image_widget) {
  164. $image_widget_func = $image_widget['callback'];
  165. $output .= $image_widget_func($rel_count);
  166. }
  167. $output .= '>';
  168. $output .= theme('image_style', array(
  169. 'style_name' => 'uc_product',
  170. 'path' => $first['uri'],
  171. 'alt' => $first['alt'],
  172. 'title' => $first['title'],
  173. ));
  174. $output .= '</a></div>';
  175. if (!empty($images)) {
  176. $output .= '<div class="more-product-images">';
  177. foreach ($images as $thumbnail) {
  178. // Node preview adds extra values to $images that aren't files.
  179. if (!is_array($thumbnail) || empty($thumbnail['uri'])) {
  180. continue;
  181. }
  182. $output .= '<a href="' . image_style_url('uc_product_full', $thumbnail['uri']) . '" title="' . $thumbnail['title'] . '"';
  183. if ($image_widget) {
  184. $output .= $image_widget_func($rel_count);
  185. }
  186. $output .= '>';
  187. $output .= theme('image_style', array(
  188. 'style_name' => 'uc_thumbnail',
  189. 'path' => $thumbnail['uri'],
  190. 'alt' => $thumbnail['alt'],
  191. 'title' => $thumbnail['title'],
  192. ));
  193. $output .= '</a>';
  194. }
  195. $output .= '</div>';
  196. }
  197. $output .= '</div>';
  198. $rel_count++;
  199. return $output;
  200. }