/[drupal]/contributions/modules/ubercart/uc_taxes/uc_taxes.js
ViewVC logotype

Contents of /contributions/modules/ubercart/uc_taxes/uc_taxes.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download) (as text)
Thu Jul 10 12:41:07 2008 UTC (16 months, 2 weeks ago) by islandusurper
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2
Changes since 1.9: +72 -36 lines
File MIME type: text/javascript
Begin the Ubercart 6.x-2.x branch.
1 // -*- js-var: set_line_item, base_path, li_titles, li_values, tax_weight; -*-
2 // $Id$
3
4 var pane = '';
5 if ($("input[@name*=delivery_]").length) {
6 pane = 'delivery'
7 }
8 else if ($("input[@name*=billing_]").length) {
9 pane = 'billing'
10 }
11
12 $(document).ready(function() {
13 getTax();
14 $("select[@name*=delivery_country], "
15 + "select[@name*=delivery_zone], "
16 + "input[@name*=delivery_postal_code], "
17 + "select[@name*=billing_country], "
18 + "select[@name*=billing_zone], "
19 + "input[@name*=billing_postal_code]").change(getTax);
20 });
21
22 function getTax() {
23 var products = $("[@name=cart_contents]").val();
24 var s_zone = $("select[@name*=delivery_zone]").val();
25 if (!s_zone) {
26 s_zone = "0";
27 }
28 var s_code = $("input[@name*=delivery_postal_code]").val();
29 if (!s_code) {
30 s_code = '';
31 }
32 var s_country = $("select[@name*=delivery_country]").val();
33 if (!s_country) {
34 s_country = "0";
35 }
36 var b_zone = $("select[@name*=billing_zone]").val();
37 if (!b_zone) {
38 b_zone = "0";
39 }
40 var b_code = $("input[@name*=billing_postal_code]").val();
41 if (!b_code) {
42 b_code = '';
43 }
44 var b_country = $("select[@name*=billing_country]").val();
45 if (!b_country) {
46 b_country = "0";
47 }
48 var order_size = 8;
49 var line_item = '';
50 var key;
51 var i = 0;
52 for (key in li_titles) {
53 if (key != 'subtotal') {
54 line_item = line_item + 'i:' + i + ';a:3:{s:5:"title";s:' + li_titles[key].length + ':"' + li_titles[key] + '";s:4:"type";s:'+ key.length + ':"'+ key + '";s:6:"amount";d:' + li_values[key] + ';}';
55 i++;
56 }
57 }
58 line_item = 's:10:"line_items";a:' + i + ':{' + line_item + '}';
59 var order = 'O:8:"stdClass":' + order_size + ':{s:8:"products";' + encodeURIComponent(products)
60 + 's:13:"delivery_zone";i:' + s_zone
61 + ';s:20:"delivery_postal_code";s:' + s_code.length +':"' + encodeURIComponent(s_code)
62 + '";s:16:"delivery_country":i:' + s_country + ';'
63 + 's:12:"billing_zone";i:' + b_zone
64 + ';s:19:"billing_postal_code";s:' + b_code.length +':"' + encodeURIComponent(b_code)
65 + '";s:15:"billing_country":i:' + b_country + ';'
66 + line_item + '}';
67 if (!!products) {
68 $.ajax({
69 type: "POST",
70 url: Drupal.settings.basePath + "taxes/calculate",
71 data: 'order=' + order,
72 dataType: "json",
73 success: function(taxes) {
74 var key;
75 for (key in li_titles) {
76 if (key.substr(0, 4) == 'tax_') {
77 delete li_titles[key];
78 delete li_values[key];
79 delete li_weight[key];
80 }
81 }
82 var j;
83 for (j in taxes) {
84 if (taxes[j].id == 'subtotal') {
85 summed = 0;
86 }
87 else {
88 summed = 1;
89 }
90 set_line_item("tax_" + taxes[j].id, taxes[j].name, taxes[j].amount, tax_weight + taxes[j].weight / 10, summed, false);
91 }
92 render_line_items();
93 }
94 });
95 }
96 }

  ViewVC Help
Powered by ViewVC 1.1.2