type != 'product') { return; } switch ($op) { case 'prepare': $sell_price = $node->sell_price / (1 + _uc_product_taxes_calculate($node)); $node->sell_price = round($sell_price, 2); break; case 'load': $sell_price = $node->sell_price + ($node->sell_price * _uc_product_taxes_calculate($node)); $node->sell_price = round($sell_price, 2); break; } } } /** * hook_form_alter() */ function uc_taxes_price_form_alter($form_id, &$form) { if (!user_access('pricing without vat')) { //drupal_set_message('
'.print_r($form_id, true).'
'); if ($form_id == 'uc_cart_checkout_form') { //drupal_set_message('
'.print_r($form['panes']['payment'], true).'
'); $form['panes']['payment']['shown_total']['#suffix'] = '

'.t('VAT is round up/down to the nearest real amount then applied on total price').'

'; } if (strpos($form_id, 'add_to_cart_form') || strpos($form_id, 'add_product_form')) { $result = db_query("SELECT * FROM {uc_product_attributes} WHERE nid = %d ORDER BY ordering", $form['nid']['#value']); $total_attributes = db_num_rows($result); if ($node = node_load((int)$form['nid']['#value'])){ while ($relation = db_fetch_object($result)){ $attribute = uc_attribute_load($relation->aid, $form['nid']['#value'], 'product'); $opt_array = array(); foreach($attribute->options as $option){ $option->price = $option->price + ($option->price * _uc_product_taxes_calculate($node)); $option->price = round($option->price, 2); switch (variable_get('uc_attribute_option_price_format', 'adjustment')){ case 'total': $display_price = ', '.$node->sell_price.'+'.$option->price.'='. uc_currency_format($node->sell_price + $option->price); if ($total_attributes == 1){ break; } case 'adjustment': $display_price = ($option->price != 0 ? ', '. ($option->price > 0 ? '+' : '') . uc_currency_format($option->price) : ''); break; case 'none': default: $display_price = ''; break; } $opt_array[$option->oid] = $option->name . $display_price; } if (count($attribute->options)){ $form['attributes'][$attribute->aid] = array('#type' => 'select', '#title' => $attribute->name, '#default_value' => $relation->default_option, '#options' => $opt_array, ); } else{ $form['attributes'][$attribute->aid] = array('#type' => 'textfield', '#title' => $attribute->name, ); } $form['attributes']['#theme'] = 'uc_attribute_add_to_cart'; } } } } } /****************************************************************************** * Ubercart Hooks * ******************************************************************************/ /** * Implementation of hook_cart_item(). */ function uc_taxes_price_cart_item($op, &$item) { if (!user_access('pricing without vat')) { switch ($op) { case 'load': $item->options = _uc_cart_product_get_options($item); $product = node_load($item->nid); $item->price = $product->sell_price; $op_costs = 0; $op_prices = 0; $op_weight = 0; foreach ($item->options as $option){ $op_prices = $option['price'] + ($option['price'] * _uc_product_taxes_calculate($product)); } $item->price += $op_prices; //drupal_set_message('
'.print_r($product, true).'
'); if ($_GET['q'] == 'cart/checkout') { $item->price = round($item->price, 2); //drupal_set_message('
'.print_r($item->price, true).'
'); $item->price = $item->price / (1 + _uc_product_taxes_calculate($product)); $item->price = round($item->price, 2); //drupal_set_message('
'.print_r($item->price, true).'
'); } else { $item->price = round($item->price, 2); } if (!empty($item->data['model'])) { $item->model = $item->data['model']; } break; } } } function uc_taxes_price_cart_pane($items) { $panes[] = array( 'id' => 'taxes_price', 'title' => t('Title'), 'enabled' => TRUE, 'weight' => 10, 'body' => t('Unit price including VAT tax, rounded up/down to the nearest cent'), ); return $panes; } /****************************************************************************** * Module Functions * ******************************************************************************/ /** * Calculate all taxes amount applied to a product */ function _uc_product_taxes_calculate($node) { $type = $node->type; $taxes = uc_taxes_get_rates(); foreach ($taxes as $taxe) { foreach ($taxe->taxed_product_types as $taxed_product_type) { if($type == $taxed_product_type) { $taxes_amount += $taxe->rate; } } } return $taxes_amount; } /****************************************************************************** * Theme Functions * ******************************************************************************/ function phptemplate_cart_review_table($show_subtotal = TRUE) { $items = uc_cart_get_contents(); $subtotal = 0; $output = '' .''; $row = 1; for ($i = 0; $i < count($items); $i++) { $item = $items[$i]; $rows = array(); foreach($item->options as $option){ $rows[] = $option['attribute'] .': '. $option['name']; } $desc = $item->title . theme('item_list', $rows, NULL, 'ul', array('class' => 'product-options')); $total = ($item->qty) ? $item->qty * $item->price : $item->price; $node = node_load(array('nid'=>$item->nid)); $vat += ($item->qty) ? $item->qty * $item->price * _uc_product_taxes_calculate($node) : $item->price * _uc_product_taxes_calculate($node); $subtotal += $total; $qty = ($item->qty) ? $item->qty : ''; $tr_class = ($i % 2 == 0) ? 'even' : 'odd'; if ($show_subtotal && $i == count($items)) { $tr_class .= ' last'; } $output .= ''; } if ($show_subtotal) { $tr_class = ($tr_class == 'even') ? 'odd' : 'even'; $output .= ''; } $output .= '
'. t('Qty') .''. t('Products') .''. t('Price') .'
' . t('!qtyx', array('!qty' => $qty)) .'' . $desc .''. uc_currency_format($total) .'
'. t('Subtotal') .' '. uc_currency_format($subtotal) .'
' .''. t('VAT:') .' '. uc_currency_format($vat) .'
' .''. t('Total:') .' '. uc_currency_format($subtotal+$vat) .'
' .'
'; return $output; }