allow more control over how words are picked out of text we're indexing
[bse.git] / site / cgi-bin / modules / BSE / TB / Order.pm
CommitLineData
0ec4ac8a
TC
1package BSE::TB::Order;
2use strict;
3# represents an order from the database
4use Squirrel::Row;
5use vars qw/@ISA/;
6@ISA = qw/Squirrel::Row/;
5d88571c 7use Carp 'confess';
0ec4ac8a
TC
8
9sub columns {
10 return qw/id
11 delivFirstName delivLastName delivStreet delivSuburb delivState
12 delivPostCode delivCountry
13 billFirstName billLastName billStreet billSuburb billState
14 billPostCode billCountry
15 telephone facsimile emailAddress
16 total wholesaleTotal gst orderDate
17 ccNumberHash ccName ccExpiryHash ccType
18 filled whenFilled whoFilled paidFor paymentReceipt
19 randomId cancelled userId paymentType
20 customInt1 customInt2 customInt3 customInt4 customInt5
21 customStr1 customStr2 customStr3 customStr4 customStr5
22 instructions billTelephone billFacsimile billEmail
e3d242f7 23 siteuser_id affiliate_code shipping_cost
41e7c841
TC
24 delivMobile billMobile
25 ccOnline ccSuccess ccReceipt ccStatus ccStatusText
37dd20ad 26 ccStatus2 ccTranId complete delivOrganization billOrganization
d9803c26 27 delivStreet2 billStreet2 purchase_order shipping_method
cb351412 28 shipping_name shipping_trace/;
0ec4ac8a
TC
29}
30
31=item siteuser
32
33returns the SiteUser object of the user who made this order.
34
35=cut
36
37sub siteuser {
38 my ($self) = @_;
39
40 $self->{userId} or return;
41
42 require SiteUsers;
43
44 return ( SiteUsers->getBy(userId=>$self->{userId}) )[0];
45}
46
47sub items {
48 my ($self) = @_;
49
50 require BSE::TB::OrderItems;
51 return BSE::TB::OrderItems->getBy(orderId => $self->{id});
52}
53
ab2cd916
TC
54sub files {
55 my ($self) = @_;
56
57 BSE::DB->query(orderFiles=>$self->{id});
58}
59
60sub products {
61 my ($self) = @_;
62
63 require Products;
64 Products->getSpecial(orderProducts=>$self->{id});
65}
66
41e7c841
TC
67sub valid_fields {
68 my ($class, $cfg) = @_;
69
70 my %fields =
71 (
37dd20ad
TC
72 delivFirstName => { description=>'Delivery First Name',
73 rules=>'dh_one_line' },
74 delivLastName => { description => 'Delivery Last Name',
75 rules=>'dh_one_line' },
76 delivOrganization => { description => 'Delivery Organization',
77 rules=>'dh_one_line' },
78 delivStreet => { description => 'Delivery Street',
79 rules=>'dh_one_line' },
80 delivStreet2 => { description => 'Delivery Street 2',
81 rules=>'dh_one_line' },
82 delivState => { description => 'Delivery State',
83 rules=>'dh_one_line' },
84 delivSuburb => { description => 'Delivery Suburb',
85 rules=>'dh_one_line' },
86 delivPostCode => { description => 'Delivery Post Code',
9074efa2 87 rules=>'dh_one_line;dh_int_postcode' },
37dd20ad
TC
88 delivCountry => { description => 'Delivery Country',
89 rules=>'dh_one_line' },
90 billFirstName => { description => 'Billing First Name',
91 rules=>'dh_one_line' },
92 billLastName => { description => 'Billing Last Name',
93 rules=>'dh_one_line' },
94 billOrganization => { description => 'Billing Organization',
95 rules=>'dh_one_line' },
96 billStreet => { description => 'Billing Street',
97 rules=>'dh_one_line' },
98 billStreet2 => { description => 'Billing Street 2',
99 rules=>'dh_one_line' },
100 billSuburb => { description => 'Billing Suburb',
101 rules=>'dh_one_line' },
102 billState => { description => 'Billing State',
103 rules=>'dh_one_line' },
104 billPostCode => { description => 'Billing Post Code',
9074efa2 105 rules=>'dh_one_line;dh_int_postcode' },
37dd20ad
TC
106 billCountry => { description => 'Billing First Name',
107 rules=>'dh_one_line' },
41e7c841
TC
108 telephone => { description => 'Telephone Number',
109 rules => "phone" },
110 facsimile => { description => 'Facsimile Number',
111 rules => 'phone' },
112 emailAddress => { description => 'Email Address',
113 rules=>'email;required' },
114 instructions => { description => 'Instructions' },
115 billTelephone => { description => 'Billing Telephone Number',
116 rules=>'phone' },
117 billFacsimile => { description => 'Billing Facsimile Number',
118 rules=>'phone' },
119 billEmail => { description => 'Billing Email Address',
120 rules => 'email' },
121 delivMobile => { description => 'Delivery Mobile Number',
122 rules => 'phone' },
123 billMobile => { description => 'Billing Mobile Number',
124 rules=>'phone' },
125 instructions => { description => 'Instructions' },
74b21f6d 126 purchase_order => { description => 'Purchase Order No' },
d8674b8b
AMS
127 shipping_cost => { description => 'Shipping charges' },
128 shipping_method => { description => 'Shipping method' },
41e7c841
TC
129 );
130
131 for my $field (keys %fields) {
132 my $display = $cfg->entry('shop', "display_$field");
133 $display and $fields{$field}{description} = $display;
134 }
135
136 return %fields;
137}
138
139sub valid_rules {
140 my ($class, $cfg) = @_;
141
142 return;
143}
144
145sub valid_payment_fields {
146 my ($class, $cfg) = @_;
147
148 my %fields =
149 (
150 cardNumber =>
151 {
152 description => "Credit Card Number",
153 rules=>"creditcardnumber",
154 },
155 cardExpiry =>
156 {
157 description => "Credit Card Expiry Date",
158 rules => 'creditcardexpirysingle',
159 },
160 cardHolder => { description => "Credit Card Holder" },
161 cardType => { description => "Credit Card Type" },
162 cardVerify =>
163 {
164 description => 'Card Verification Value',
165 rules => 'creditcardcvv',
166 },
167 );
168
169 for my $field (keys %fields) {
170 my $display = $cfg->entry('shop', "display_$field");
171 $display and $fields{$field}{description} = $display;
172 }
173
174 return %fields;
175}
176
177sub valid_payment_rules {
178 return;
179}
180
5d88571c
TC
181sub clear_items {
182 my ($self) = @_;
183
184 confess "Attempt to clear items on completed order $self->{id}"
185 if $self->{complete};
186
187 BSE::DB->run(deleteOrdersItems => $self->{id});
188}
189
0ec4ac8a 1901;