i0.15_12 commit
[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
5d88571c 26 ccStatus2 ccTranId complete/;
0ec4ac8a
TC
27}
28
29=item siteuser
30
31returns the SiteUser object of the user who made this order.
32
33=cut
34
35sub siteuser {
36 my ($self) = @_;
37
38 $self->{userId} or return;
39
40 require SiteUsers;
41
42 return ( SiteUsers->getBy(userId=>$self->{userId}) )[0];
43}
44
45sub items {
46 my ($self) = @_;
47
48 require BSE::TB::OrderItems;
49 return BSE::TB::OrderItems->getBy(orderId => $self->{id});
50}
51
ab2cd916
TC
52sub files {
53 my ($self) = @_;
54
55 BSE::DB->query(orderFiles=>$self->{id});
56}
57
58sub products {
59 my ($self) = @_;
60
61 require Products;
62 Products->getSpecial(orderProducts=>$self->{id});
63}
64
41e7c841
TC
65sub valid_fields {
66 my ($class, $cfg) = @_;
67
68 my %fields =
69 (
70 delivFirstName => { description=>'Delivery First Name', },
71 delivLastName => { description => 'Delivery Last Name' },
72 delivStreet => { description => 'Delivery Street' },
73 delivState => { description => 'Delivery State' },
74 delivSuburb => { description => 'Delivery Suburb' },
75 delivPostCode => { description => 'Delivery Post Code' },
76 delivCountry => { description => 'Delivery Country' },
77 billFirstName => { description => 'Billing First Name' },
78 billLastName => { description => 'Billing Last Name' },
79 billStreet => { description => 'Billing First Name' },
80 billSuburb => { description => 'Billing First Name' },
81 billState => { description => 'Billing First Name' },
82 billPostCode => { description => 'Billing First Name' },
83 billCountry => { description => 'Billing First Name' },
84 telephone => { description => 'Telephone Number',
85 rules => "phone" },
86 facsimile => { description => 'Facsimile Number',
87 rules => 'phone' },
88 emailAddress => { description => 'Email Address',
89 rules=>'email;required' },
90 instructions => { description => 'Instructions' },
91 billTelephone => { description => 'Billing Telephone Number',
92 rules=>'phone' },
93 billFacsimile => { description => 'Billing Facsimile Number',
94 rules=>'phone' },
95 billEmail => { description => 'Billing Email Address',
96 rules => 'email' },
97 delivMobile => { description => 'Delivery Mobile Number',
98 rules => 'phone' },
99 billMobile => { description => 'Billing Mobile Number',
100 rules=>'phone' },
101 instructions => { description => 'Instructions' },
102 );
103
104 for my $field (keys %fields) {
105 my $display = $cfg->entry('shop', "display_$field");
106 $display and $fields{$field}{description} = $display;
107 }
108
109 return %fields;
110}
111
112sub valid_rules {
113 my ($class, $cfg) = @_;
114
115 return;
116}
117
118sub valid_payment_fields {
119 my ($class, $cfg) = @_;
120
121 my %fields =
122 (
123 cardNumber =>
124 {
125 description => "Credit Card Number",
126 rules=>"creditcardnumber",
127 },
128 cardExpiry =>
129 {
130 description => "Credit Card Expiry Date",
131 rules => 'creditcardexpirysingle',
132 },
133 cardHolder => { description => "Credit Card Holder" },
134 cardType => { description => "Credit Card Type" },
135 cardVerify =>
136 {
137 description => 'Card Verification Value',
138 rules => 'creditcardcvv',
139 },
140 );
141
142 for my $field (keys %fields) {
143 my $display = $cfg->entry('shop', "display_$field");
144 $display and $fields{$field}{description} = $display;
145 }
146
147 return %fields;
148}
149
150sub valid_payment_rules {
151 return;
152}
153
5d88571c
TC
154sub clear_items {
155 my ($self) = @_;
156
157 confess "Attempt to clear items on completed order $self->{id}"
158 if $self->{complete};
159
160 BSE::DB->run(deleteOrdersItems => $self->{id});
161}
162
0ec4ac8a 1631;