=== modified file 'uc_product/uc_product.css' --- uc_product/uc_product.css 2009-01-07 15:08:16 +0000 +++ uc_product/uc_product.css 2009-03-16 10:36:33 +0000 @@ -9,6 +9,17 @@ margin-left: 4px; } +.uc-price-display { + float: right; + clear: right; + width: 100px; + text-align: center; + font-size: 1.3em; + font-weight: bold; + padding-bottom: 4px; + padding-left: 4px; +} + .display-price { float: right; clear: right; === modified file 'uc_product/uc_product.module' --- uc_product/uc_product.module 2009-03-13 14:35:14 +0000 +++ uc_product/uc_product.module 2009-03-16 10:36:15 +0000 @@ -693,27 +693,49 @@ function uc_product_view($node, $teaser 'add_to_cart' => 10, )); + $context = array( + 'location' => 'product-view', + 'class' => array( + 'product', + ), + 'subject' => array( + 'nid' => $node->nid, + ), + ); + + if (module_exists('imagecache') && ($field = variable_get('uc_image_'. $node->type, '')) && isset($node->$field) && file_exists($node->{$field}[0]['filepath'])) { - $node->content['image'] = array('#value' => theme('uc_product_image', $node->$field, $teaser, $page), + $node->content['image'] = array( + '#value' => theme('uc_product_image', $node->$field, $teaser, $page), '#access' => $enabled['image'], '#weight' => $weight['image'], ); } - $node->content['display_price'] = array('#value' => theme('uc_product_price', $node->sell_price, 'display-price', TRUE), + + $context['class'][1] = 'display'; + $node->content['display_price'] = array( + '#value' => uc_price(array('value' => $node->sell_price, 'qty' => 1), $context), '#access' => $enabled['display_price'], '#weight' => $weight['display_price'], ); if (!$teaser) { - $node->content['model'] = array('#value' => theme('uc_product_model', $node->model, $teaser, $page), + $node->content['model'] = array( + '#value' => theme('uc_product_model', $node->model, $teaser, $page), '#access' => $enabled['model'], '#weight' => $weight['model'], ); $node->content['body']['#weight'] = 1; - $node->content['list_price'] = array('#value' => theme('uc_product_price', $node->list_price, 'list-price'), + + $context['class'][1] = 'list'; + $node->content['list_price'] = array( + '#value' => uc_price(array('value' => $node->list_price, 'qty' => 1), $context), '#access' => $enabled['list_price'], '#weight' => $weight['list_price'], ); - $node->content['cost'] = array('#value' => theme('uc_product_price', $node->cost, 'cost'), + + $context['class'][1] = 'cost'; + $node->content['cost'] = array( + '#value' => uc_price(array('value' => $node->cost, 'qty' => 1), $context), '#access' => $enabled['cost'] && user_access('administer products'), '#weight' => $weight['cost'], ); @@ -722,29 +744,35 @@ function uc_product_view($node, $teaser $node->content['#attributes'] = array('style' => 'display: inline'); } - $node->content['sell_price'] = array('#value' => theme('uc_product_price', $node->sell_price, 'sell-price', $teaser), + $context['class'][1] = 'sell'; + $node->content['sell_price'] = array( + '#value' => uc_price(array('value' => $node->sell_price, 'qty' => 1), $context), '#access' => $enabled['sell_price'], '#weight' => $weight['sell_price'], ); if (!$teaser) { - $node->content['weight'] = array('#value' => theme('uc_product_weight', $node->weight, $node->weight_units, $teaser, $page), + $node->content['weight'] = array( + '#value' => theme('uc_product_weight', $node->weight, $node->weight_units, $teaser, $page), '#access' => $enabled['weight'], '#weight' => $weight['weight'], ); - $node->content['dimensions'] = array('#value' => theme('uc_product_dimensions', $node->length, $node->width, $node->height, $node->length_units, $teaser, $page), + $node->content['dimensions'] = array( + '#value' => theme('uc_product_dimensions', $node->length, $node->width, $node->height, $node->length_units, $teaser, $page), '#access' => $enabled['dimensions'], '#weight' => $weight['dimensions'], ); if (module_exists('uc_cart')) { - $node->content['add_to_cart'] = array('#value' => theme('uc_product_add_to_cart', $node, $teaser, $page), + $node->content['add_to_cart'] = array( + '#value' => theme('uc_product_add_to_cart', $node, $teaser, $page), '#access' => $enabled['add_to_cart'], '#weight' => $weight['add_to_cart'], ); } } elseif (module_exists('uc_cart') && variable_get('uc_product_add_to_cart_teaser', TRUE)) { - $node->content['add_to_cart'] = array('#value' => theme('uc_product_add_to_cart', $node, $teaser, $page), + $node->content['add_to_cart'] = array( + '#value' => theme('uc_product_add_to_cart', $node, $teaser, $page), '#access' => $enabled['add_to_cart'], '#weight' => $weight['add_to_cart'], ); === added file 'uc_store/includes/uc_price.inc' --- uc_store/includes/uc_price.inc 1970-01-01 00:00:00 +0000 +++ uc_store/includes/uc_price.inc 2009-03-16 10:49:24 +0000 @@ -0,0 +1,117 @@ +options = array( + 'sign' => variable_get('uc_currency_sign', '$'), + 'sign_after' => variable_get('uc_sign_after_amount', FALSE), + 'prec' => variable_get('uc_currency_prec', 2), + 'dec' => variable_get('uc_currency_dec', '.'), + 'thou' => variable_get('uc_currency_thou', ','), + 'label' => TRUE, + ); + } + + function calculate($price, $context, $options, $revision) { + switch ($revision) { + case 'original': + case 'altered': + case 'formatted': + case 'themed': + break; + + default: + $revision = 'themed'; + } + $options += $this->options; + // Build the cache key with the original state. + global $user; + $key = 'uc-price-'. $user->uid .'-'. get_class($this) .'-'. md5(serialize($price + $context + $options)); + // Is it cached? + if ($cache = cache_get($key, 'cache')) { + $cache = $cache->data; + } + // Otherwise, build it. + else { + $cache = array(); + $cache['original'] = $price['value'] * $price['qty']; + // Alter the price, context, and options. + $this->alter($price, $context, $options); + if (isset($price['placeholder'])) { + $value = $price['placeholder']; + $cache['altered'] = $value; + $cache['formatted'] = $value; + } + else { + $value = $price['value'] * $price['qty']; + $cache['altered'] = $value; + // Format the price. + $value = $this->format($value, $options); + $cache['formatted'] = $value; + } + // Theme the price. + $cache['themed'] = theme('uc_price', $value, $context, $options);; + // Cache this price's revisions. + cache_set($key, $cache, 'cache', CACHE_TEMPORARY); + } + + // Return the requested revision. + return $cache[$revision]; + } + + function alter(&$price, &$context, &$options) { + if (in_array('list', $context['class'])) { + $options['prefixes'][] = t('List Price: '); + } + if (in_array('cost', $context['class'])) { + $options['prefixes'][] = t('Cost: '); + } + if (in_array('sell', $context['class'])) { + $options['prefixes'][] = t('Price: '); + } + } + + function format($value, $options) { + $output = ''; + // If the value is less than the minimum precision, zero it. + if ($options['prec'] > 0 && abs($value) < 1 / pow(10, $options['prec'])) { + $value = 0; + } + // Value is always positive, and we'll add the negative sign if necessary. + if ($value < 0) { + $value = abs($value); + $output .= '-'; + } + // Add the currency sign first? + if ($options['sign'] && !$options['sign_after']) { + $output .= $options['sign']; + } + // Format the number, like 1234.567 => 1,234.57 + $output .= number_format($value, $options['prec'], $options['dec'], $options['thou']); + // Add the currency sign last? + if ($options['sign'] && $options['sign_after']) { + $output .= $options['sign']; + } + return $output; + } + +} + +function _uc_price_get_class_list() { + $list = array(); + $classes = get_declared_classes(); + foreach ($classes as $class) { + if ($class == 'UbercartPriceFormatter' || get_parent_class($class) == 'UbercartPriceFormatter') { + $list[] = $class; + } + } + return drupal_map_assoc($list); +} + +function uc_price($price, $context = array(), $options = array(), $revision = NULL) { + global $uc_price_handler; + return $uc_price_handler->calculate($price, $context, $options, $revision); +} \ No newline at end of file === modified file 'uc_store/uc_store.module' --- uc_store/uc_store.module 2009-03-11 04:33:33 +0000 +++ uc_store/uc_store.module 2009-03-16 10:41:52 +0000 @@ -330,6 +330,12 @@ function uc_store_init() { require_once($dir .'/includes/summaries.inc'); require_once($dir .'/includes/tapir.inc'); + // For uc_price + require_once($dir .'/includes/uc_price.inc'); + global $uc_price_handler; + $class = variable_get('uc_price_handler_class', 'UbercartPriceFormatter'); + $uc_price_handler = new $class; + drupal_add_css($dir .'/uc_store.css'); } @@ -371,6 +377,9 @@ function uc_store_theme() { 'summary_overview' => array( 'arguments' => array(), ), + 'uc_price' => array( + 'arguments' => array('value' => 0, 'context' => array(), 'options' => array()), + ), ); } @@ -530,6 +539,29 @@ function uc_store_exit() { * Callback Functions, Forms, and Tables ******************************************************************************/ +function theme_uc_price($value, $context, $options) { + // Fixup class names. + foreach ((array) $context['class'] as $key => $class) { + $context['class'][$key] = 'uc-price-'. $class; + } + $context['class'][] = 'uc-price'; + // Class the element. + $output = '
'; + // Prefix(es). + if ($options['label']) { + $output .= implode('', (array) $options['prefixes']); + } + // Value. + $output .= $value; + // Suffix(es). + if ($options['label']) { + $output .= implode('', (array) $options['suffixes']); + } + $output .= '
'; + + return $output; +} + // Themes the dashboard on the admin/store page. function theme_uc_admin_dashboard($type, $menus) { if ($type == 1) {