Commit | Line | Data |
---|---|---|
0ec4ac8a TC |
1 | package BSE::TB::OrderItem; |
2 | use strict; | |
3 | # represents an order line item from the database | |
4 | use Squirrel::Row; | |
5 | use vars qw/@ISA/; | |
6 | @ISA = qw/Squirrel::Row/; | |
7 | ||
5014aef9 | 8 | our $VERSION = "1.007"; |
4ad0e50a TC |
9 | |
10 | sub table { "order_item" } | |
cb7fd78d | 11 | |
0ec4ac8a TC |
12 | sub columns { |
13 | return qw/id productId orderId units price wholesalePrice gst options | |
14 | customInt1 customInt2 customInt3 customStr1 customStr2 customStr3 | |
7b4490e1 | 15 | title description subscription_id subscription_period max_lapsed |
b55d4af1 | 16 | session_id product_code tier_id product_discount product_discount_units/; |
4ad0e50a TC |
17 | } |
18 | ||
19 | sub db_columns { | |
20 | return map { $_ eq "description" ? "summary" : $_ } $_[0]->columns; | |
0ec4ac8a TC |
21 | } |
22 | ||
14604ada TC |
23 | sub defaults { |
24 | return | |
25 | ( | |
26 | units => 1, | |
27 | options => '', | |
28 | customInt1 => undef, | |
29 | customInt2 => undef, | |
30 | customInt3 => undef, | |
31 | customStr1 => undef, | |
32 | customStr2 => undef, | |
33 | customStr3 => undef, | |
5014aef9 TC |
34 | tier_id => undef, |
35 | product_discount => 0, | |
36 | product_discount_units => 0, | |
14604ada TC |
37 | ); |
38 | } | |
39 | ||
58baa27b TC |
40 | sub option_list { |
41 | my ($self) = @_; | |
42 | ||
43 | require BSE::TB::OrderItemOptions; | |
44 | return sort { $a->{display_order} <=> $b->{display_order} } | |
45 | BSE::TB::OrderItemOptions->getBy(order_item_id => $self->{id}); | |
46 | } | |
47 | ||
13a986ee TC |
48 | sub product { |
49 | my ($self) = @_; | |
50 | ||
51 | $self->productId == -1 | |
52 | and return; | |
10dd37f9 AO |
53 | require BSE::TB::Products; |
54 | return BSE::TB::Products->getByPkey($self->productId); | |
13a986ee TC |
55 | } |
56 | ||
8d8895b4 TC |
57 | sub option_hashes { |
58 | my ($self) = @_; | |
59 | ||
60 | my $product = $self->product; | |
61 | if (length $self->{options}) { | |
62 | my @values = split /,/, $self->options; | |
63 | return map | |
64 | +{ | |
65 | id => $_->{id}, | |
66 | value => $_->{value}, | |
67 | desc => $_->{desc}, | |
68 | label => $_->{display}, | |
69 | }, $product->option_descs(BSE::Cfg->single, \@values); | |
70 | } | |
71 | else { | |
72 | my @options = $self->option_list; | |
73 | return map | |
74 | +{ | |
75 | id => $_->original_id, | |
76 | value => $_->value, | |
77 | desc => $_->name, | |
78 | label => $_->display | |
79 | }, @options; | |
80 | } | |
81 | } | |
82 | ||
83 | sub nice_options { | |
84 | my ($self) = @_; | |
85 | ||
86 | my @options = $self->option_hashes | |
87 | or return ''; | |
88 | ||
89 | return '('.join(", ", map("$_->{desc} $_->{label}", @options)).')'; | |
90 | } | |
91 | ||
f4f29389 TC |
92 | sub session { |
93 | my ($self) = @_; | |
94 | ||
95 | $self->session_id | |
96 | or return; | |
97 | ||
98 | require BSE::TB::SeminarSessions; | |
99 | return BSE::TB::SeminarSessions->getByPkey($self->session_id); | |
100 | } | |
101 | ||
676f5398 TC |
102 | # cart item compatibility |
103 | sub retailPrice { | |
104 | $_[0]->price; | |
105 | } | |
106 | ||
107 | sub extended { | |
108 | my ($self, $name) = @_; | |
109 | ||
110 | return $self->units * $self->$name(); | |
111 | } | |
112 | ||
4ad0e50a TC |
113 | sub tier { |
114 | my ($self) = @_; | |
115 | ||
116 | my $tier_id = $self->tier_id | |
117 | or return; | |
118 | ||
119 | require BSE::TB::PriceTiers; | |
120 | my $tier = BSE::TB::PriceTiers->getByPkey($tier_id) | |
121 | or return; | |
122 | ||
123 | return $tier; | |
124 | } | |
125 | ||
0ec4ac8a | 126 | 1; |