Index: ca/ca.module ========================================================= --- ca/ca.module (revision 1.1.2.15) +++ ca/ca.module (revision 1.1.2.16) @@ -156,6 +156,10 @@ * TRUE or FALSE indicating if at least one predicate was evaluated. */ function ca_pull_trigger() { + // Trigger actions can pull other triggers. Lock predicates when they are + // marked for evaluation so they can't be evaluated again. + static $locked; + $args = func_get_args(); $trigger = array_shift($args); @@ -185,11 +189,17 @@ // Loop through the predicates and evaluate them one by one. foreach ($predicates as $pid => $predicate) { + // Prevent the predicate from being evaluated if it already has been with + // the same arguments. + $key = $pid . serialize($arguments); + if (!isset($locked[$key])) { - // If all of a predicate's conditions evaluate to TRUE... - if (ca_evaluate_conditions($predicate, $arguments)) { - // Then perform its actions. - ca_perform_actions($predicate, $arguments); - } + // If all of a predicate's conditions evaluate to TRUE... + if (ca_evaluate_conditions($predicate, $arguments)) { + // Then perform its actions. + ca_perform_actions($predicate, $arguments); + } + } + $locked[$key] = TRUE; } return TRUE; @@ -247,10 +257,6 @@ * An array of predicates. */ function ca_load_trigger_predicates($trigger, $all = FALSE) { - // Trigger actions can pull other triggers. Lock predicates when they are - // marked for evaluation so they can't be evaluated again. - static $locked = array(); - // Load all the module defined predicates. $predicates = module_invoke_all('ca_predicate'); @@ -266,18 +272,8 @@ if (!$all && $value['#status'] <= 0) { unset($predicates[$key]); } - else { - // Prevent predicates from being evaluated more than once in a page load. - if (in_array($key, $locked)) { - unset($predicates[$key]); - } - else { - $locked[$key] = $key; - } - - if (!isset($value['#weight'])) { + elseif (!isset($value['#weight'])) { - $predicates[$key]['#weight'] = 0; + $predicates[$key]['#weight'] = 0; - } } } @@ -288,28 +284,22 @@ // these, we unset the module defined predicate and reconsider adding it in. if (!is_numeric($data['pid'])) { unset($predicates[$data['pid']]); - unset($locked[$data['pid']]); } // Add predicates from the database to our return array if $all == TRUE or // if the predicate is active. if ($all || $data['status'] > 0) { - // Prevent predicates from being evaluated more than once in a page load. - if (!in_array($data['pid'], $locked)) { - $predicate = ca_prepare_db_predicate($data); + $predicate = ca_prepare_db_predicate($data); - // Set the actions' weight if necessary and sort actions by their weight. - for ($i = 0; $i < count($predicate['#actions']); $i++) { - if (!isset($predicate['#actions'][$i]['#weight'])) { - $predicate['#actions'][$i]['#weight'] = 0; - } - } - usort($predicate['#actions'], 'ca_weight_sort'); + // Set the actions' weight if necessary and sort actions by their weight. + for ($i = 0; $i < count($predicate['#actions']); $i++) { + if (!isset($predicate['#actions'][$i]['#weight'])) { + $predicate['#actions'][$i]['#weight'] = 0; + } + } + usort($predicate['#actions'], 'ca_weight_sort'); - $predicates[$data['pid']] = $predicate; + $predicates[$data['pid']] = $predicate; - - $locked[$key] = $data['pid']; - } } } Index: docs/hooks.php ========================================================= --- docs/hooks.php (revision 1.1.2.11) +++ docs/hooks.php (revision 1.1.2.12) @@ -1140,6 +1140,35 @@ } /** + * Use this hook to define price handlers for your module. You may define one + * price alterer and one price formatter. You may also define options that are + * merged into the options array in order of each price alterer's weight. + */ +function hook_uc_price_handler() { + return array( + 'alter' => array( + 'title' => t('My price handler'), + 'description' => t('Handles my price alteration needs.'), + 'callback' => 'my_price_handler_alter', + ), + 'format' => array( + 'title' => t('My price handler'), + 'description' => t('Handles my price formatting needs.'), + 'callback' => 'my_price_handler_format', + ), + 'options' => array( + 'sign' => variable_get('uc_currency_sign', '*'), + 'sign_after' => TRUE, + 'prec' => 4, + 'dec' => ',', + 'thou' => '.', + 'label' => FALSE, + 'my_option_that_my_formatter_recognizes' => 1337, + ) + ); +} + +/** * Notify core of any SKUs your module adds to a given node. * * NOTE: DO NOT map the array keys, as the possibility for numeric SKUs exists, and Index: uc_attribute/uc_attribute.module ========================================================= --- uc_attribute/uc_attribute.module (revision 1.12.2.20) +++ uc_attribute/uc_attribute.module (revision 1.12.2.22) @@ -596,19 +596,35 @@ $form_attributes = array(); + $context = array( + 'revision' => 'formatted', + 'location' => 'product-attribute-form-element', + 'subject' => array(), + ); + // Loop through each product attribute and generate its form element. foreach ($attributes as $attribute) { + $context['subject']['attribute'] = $attribute; // Build the attribute's options array. $options = array(); foreach ($attribute->options as $option) { + $context['subject']['option'] = $option; switch (variable_get('uc_attribute_option_price_format', 'adjustment')) { case 'total': - $display_price = in_array($attribute->aid, $priced_attributes) ? ', '. uc_currency_format(($product->sell_price + $option->price) * $qty) : ''; + $price_info = array( + 'price' => $product->sell_price + $option->price, + 'qty' => $qty, + ); + $display_price = in_array($attribute->aid, $priced_attributes) ? ', '. uc_price($price_info, $context) : ''; if (count($priced_attributes) == 1) { break; } case 'adjustment': - $display_price = ($option->price != 0 ? ', '. ($option->price > 0 ? '+' : '') . uc_currency_format($option->price * $qty) : ''); + $price_info = array( + 'price' => $option->price, + 'qty' => $qty, + ); + $display_price = ($option->price != 0 ? ', '. ($option->price > 0 ? '+' : '') . uc_price($price_info, $context) : ''); break; case 'none': default: Index: uc_product/uc_product.css ========================================================= --- uc_product/uc_product.css (revision 1.9.2.4) +++ uc_product/uc_product.css (revision 1.9.2.5) @@ -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; Index: uc_product/uc_product.module ========================================================= --- uc_product/uc_product.module (revision 1.14.2.21) +++ uc_product/uc_product.module (revision 1.14.2.22) @@ -695,27 +695,47 @@ 'add_to_cart' => 10, )); + $context = array( + 'location' => 'product-view', + 'class' => array( + 'product', + ), + 'subject' => array( + 'node' => $node, + ), + ); + 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), '#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'; + $context['subject']['field'] = 'sell_price'; + $node->content['display_price'] = array('#value' => uc_price($node->sell_price, $context), '#access' => $enabled['display_price'], '#weight' => $weight['display_price'], ); + if (!$teaser) { $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'; + $context['subject']['field'] = 'list_price'; + $node->content['list_price'] = array('#value' => uc_price($node->list_price, $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'; + $context['subject']['field'] = 'cost'; + $node->content['cost'] = array('#value' => uc_price($node->cost, $context), '#access' => $enabled['cost'] && user_access('administer products'), '#weight' => $weight['cost'], ); @@ -724,7 +744,9 @@ $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'; + $context['subject']['field'] = 'sell_price'; + $node->content['sell_price'] = array('#value' => uc_price($node->sell_price, $context, array('label' => !$teaser)), '#access' => $enabled['sell_price'], '#weight' => $weight['sell_price'], ); @@ -1076,7 +1098,21 @@ $element['title'] = array( '#value' => node_access('view', $node) ? l($item->title, 'node/'. $node->nid) : check_plain($item->title), ); - $element['#total'] = $item->price * $item->qty; + + $context = array( + 'revision' => 'altered', + 'location' => 'cart-item', + 'subject' => array( + 'cart_item' => $item, + 'node' => $node, + ), + ); + $price_info = array( + 'price' => $item->price, + 'qty' => $item->qty, + ); + + $element['#total'] = uc_price($price_info, $context); $element['data'] = array('#type' => 'hidden', '#value' => serialize($item->data)); $element['qty'] = array( '#type' => 'textfield', @@ -1199,6 +1235,9 @@ '#rows' => array(), ); + $context = array( + 'location' => 'product-tapir-table', + ); foreach ($args as $nid) { $data = array(); $node = node_load($nid); @@ -1217,11 +1256,16 @@ '#value' => l($node->title, 'node/'. $node->nid), '#cell_attributes' => array('width' => '100%'), ); + + $context['subject'] = array('node' => $node); if ($enabled['list_price']) { - $data['list_price'] = array('#value' => uc_currency_format($node->list_price), '#cell_attriubtes' => array('nowrap' => 'nowrap')); + $context['subject']['field'] = 'list_price'; + $data['list_price'] = array('#value' => uc_price($node->list_price, $context), '#cell_attriubtes' => array('nowrap' => 'nowrap')); } if ($enabled['sell_price']) { - $data['price'] = array('#value' => theme('uc_product_price', $node->sell_price, 'sell-price', TRUE), '#cell_attriubtes' => array('nowrap' => 'nowrap')); + $context['subject']['field'] = 'sell_price'; + $context['class'] = array('sell-price'); + $data['price'] = array('#value' => uc_price($node->sell_price, $context, array('label' => FALSE)), '#cell_attriubtes' => array('nowrap' => 'nowrap')); } if (module_exists('uc_cart') && arg(0) != 'admin' && $enabled['add_to_cart']) { Index: shipping/uc_quote/uc_quote.module ========================================================= --- shipping/uc_quote/uc_quote.module (revision 1.5.2.17) +++ shipping/uc_quote/uc_quote.module (revision 1.5.2.18) @@ -866,9 +866,14 @@ return TRUE; case 'review': + $context = array( + 'revision' => 'formatted', + 'location' => 'shipping-quote-checkout-pane-review', + ); $result = db_query("SELECT * FROM {uc_order_line_items} WHERE order_id = %d AND type = '%s'", $arg1->order_id, 'shipping'); if ($line_item = db_fetch_object($result)) { - $review[] = array('title' => $line_item->title, 'data' => uc_currency_format($line_item->amount)); + $context['subject']['line_item'] = $line_item; + $review[] = array('title' => $line_item->title, 'data' => uc_price($line_item->amount, $context)); } return $review; }