]> git.imager.perl.org - bse.git/blame - site/cgi-bin/modules/BSE/CustomBase.pm
re-work coupons to allow multiple coupon types
[bse.git] / site / cgi-bin / modules / BSE / CustomBase.pm
CommitLineData
5163fd16
TC
1package BSE::CustomBase;
2use strict;
3
b7cadc84 4our $VERSION = "1.005";
cb7fd78d 5
331fd099
TC
6sub new {
7 my ($class, %params) = @_;
8
9 exists $params{cfg} or die "No cfg parameter passed to custom class constructor";
10
11 return bless \%params, $class;
12}
13
5163fd16 14sub enter_cart {
9168c88c 15 my ($class, $items, $products, $state, $cfg) = @_;
5163fd16
TC
16
17 return 1;
18}
19
20sub cart_actions {
9168c88c 21 my ($class, $acts, $items, $products, $state, $cfg) = @_;
5163fd16
TC
22
23 return ();
24}
25
26sub checkout_actions {
9168c88c 27 my ($class, $acts, $items, $products, $cfg) = @_;
5163fd16
TC
28
29 return ();
30}
31
9168c88c
TC
32sub checkout_update {
33 my ($class, $q, $items, $products, $state, $cfg) = @_;
34}
35
5163fd16 36sub order_save {
81f3292d 37 my ($class, $cgi, $order, $items, $products, $custom, $cfg) = @_;
5163fd16
TC
38
39 return 1;
40}
41
42sub total_extras {
9168c88c 43 my ($class, $cart, $state, $cfg) = @_;
5163fd16
TC
44
45 0;
46}
47
48sub recalc {
9168c88c 49 my ($class, $q, $items, $products, $state, $cfg) = @_;
5163fd16
TC
50}
51
1546e1f0
TC
52=item required_fields($cgi, $state, $cfg)
53
54Return a list of order field names that must have a non-blank value.
55
56Previously this could return SiteUser field names, this is no longer
57true.
58
59=cut
60
5163fd16 61sub required_fields {
9168c88c 62 my ($class, $q, $state, $cfg) = @_;
5163fd16 63
1546e1f0 64 my @fields = qw(billFirstName billLastName billStreet billSuburb billPostCode billCountry billTelephone billEmail);
c4f18087
TC
65 push @fields, split /,/, $cfg->entry("shop", "require_fields", "");
66 if ($q->param("need_delivery")) {
67 if ($cfg->entry("shop", "require_delivery", 1)) {
94522840 68 push @fields, qw(delivFirstName delivLastName delivStreet delivSuburb delivPostCode delivCountry);
c4f18087
TC
69 }
70 push @fields, split /,/, $cfg->entry("shop", "require_delivery_fields", "");
71 }
72
73 return @fields;
5163fd16
TC
74}
75
76sub purchase_actions {
9168c88c 77 my ($class, $acts, $items, $products, $state, $cfg) = @_;
99ef7979
TC
78
79 return;
5163fd16
TC
80}
81
df45a70d
TC
82sub order_mail_actions {
83 my ($class, $acts, $order, $items, $products, $state, $cfg) = @_;
84
85 return ();
86}
87
721cd24c 88sub base_tags {
9168c88c 89 my ($class, $articles, $acts, $article, $embedded, $cfg) = @_;
721cd24c
TC
90
91 return ();
92}
93
331fd099
TC
94# called to validate fields for a custom application
95# $cfg - a BSE::Cfg object
96# $new - the new data to be stored
97# $old - the existing article if any
98# $type - the type of article (Article, Product, Catalog)
99# $errors - hashref of fields to messages
100# Return non-zero if all fields are valid.
101# Set an error message in $errors for any invalid fields
102sub article_validate {
103 my ($self, $new, $old, $type, $errors) = @_;
104
105 1;
106}
107
108sub article_fill_new {
109 my ($self, $data, $type) = @_;
110
111 $self->article_fill($data, $data, $type);
112}
113
114sub article_fill_old {
115 my ($self, $out, $in, $type) = @_;
116
117 $self->article_fill($out, $in, $type);
118}
119
120sub article_fill {
121 my ($self, $out, $in, $type) = @_;
122
123 1;
124}
125
505456b1
TC
126sub siteusers_changed {
127 my ($self, $cfg) = @_;
128
129 1;
130}
131
132sub siteuser_auth {
133 my ($self, $session, $cgi, $cfg) = @_;
134
135 return;
136}
137
d49667a2
TC
138sub can_user_see_wishlist {
139 my ($self, $wishlist_user, $current_user, $req) = @_;
140
141 1;
142}
143
288ef5b8
TC
144my @dont_touch =
145 qw(id userId password confirmed confirmSecret waitingForConfirmation flags affiliate_name previousLogon);
146my %dont_touch = map { $_ => 1 } @dont_touch;
147
148sub siteuser_required {
149 my ($self, $req) = @_;
150
b7cadc84 151 require BSE::TB::SiteUsers;
288ef5b8
TC
152 my $cfg = $req->cfg;
153 my @required = qw(email);
154 push @required, grep $cfg->entry('site users', "require_$_", 0),
b7cadc84 155 grep !$dont_touch{$_}, BSE::TB::SiteUser->columns;
288ef5b8
TC
156
157 return @required;
158}
159
160sub siteuser_add_required {
161 my ($self, $req) = @_;
162
163 return $self->siteuser_required($req);
164}
165
166sub siteuser_edit_required {
167 my ($self, $req, $user) = @_;
168
169 return $self->siteuser_required($req);
170}
171
5163fd16
TC
1721;
173
174=head1 NAME
175
176 BSE::CustomBase - base class for the customization class.
177
178=head1 SYNOPSIS
179
180 package BSE::Custom;
181 use base 'BSE::CustomBase';
182
183 ... implement overridden functions ...
184
185=head1 DESCRIPTION
186
187This class provides basic implementations of various methods of
188BSE::Custom.
189
190The aim is that if extra customization methods are created, you can
191upgrade everything but BSE::Custom, and your code will still work.
192
193Current methods that can be implemented in BSE::Custom are:
194
195=over
196
5d18c301 197=item checkout_actions($acts, $items, $products, $state, $cgi)
5163fd16
TC
198
199Return a list of extra "actions" or members of the %acts hash used for
200converting the checkout template to the final output. Used to define
201extra tags for the checkout page.
202
9168c88c
TC
203=item checkout_update($cgi, $items, $products, $state, $cfg)
204
205This is called by the checkupdate target of shop.pl, which does
206nothing else.
207
81f3292d 208=item order_save($cgi, $order, $items, $products, $custom, $cfg)
5163fd16
TC
209
210Called immediately before the order is saved. You can perform extra
211validation and die() with an error message describing the problem, or
212perform extra data manipulation.
213
214=item BSE::Custom->enter_cart($q, $items, $products, $state)
215
216Called just before the cart is displayed.
217
218=item BSE::Custom->cart_actions($acts, $items, $products, $state)
219
220Defines tags available in the cart.
221
222=item BSE::Custom->total_extras($item, $products, $state)
223
224Extras that should be added to the total. You should probably define
225extra tags in cart_actions() and purchase_actions() to display the
226extra data.
227
228=item BSE::Custom->recalc($q, $items, $products, $state)
229
230Called when a recalc is done. Useful for storing form values into the
231state.
232
233=item BSE::Custom->required_field($q, $state)
234
235Called to get the fields required for checkout. You might want to add
236or remove them, depending on the products bought.
237
238=item BSE::Custom->purchase_actions($acts, $items, $products, $state)
239
240Defines extra tags for use on the checkout page.
241
721cd24c
TC
242=item BSE::Custom->base_tags($articles, $acts, $article, $embedded)
243
244Defines extra tags for use on any page.
245
505456b1
TC
246=item BSE::Custom->siteusers_changed($cfg)
247
248Called when a change is made to the site users table.
249
0f09d542 250=item $self->siteuser_saveops($user, $req)
f2bf0d11 251
0f09d542
TC
252Called at the beginning of the save_opts() action, if
253[custom].saveopts is true.
254
255=item $self->admin_siteuser_save_validate($user, $req, \%errors)
256
257Called by the admin siteuser save code to allow custom validation of
258the siteuser edit form, if present and if [custom].admin_saveopts. is
259true.
260
261=item $self->admin_siteuser_save($user, $req)
262
263Called by the admin siteuser save code to allow custom processing of
264the siteuser edit form, if present and if [custom].admin_saveopts. is
265true.
f2bf0d11 266
9b6f84a5
TC
267=item send_session_cookie($cookie_name, $session, $sessionid)
268
269Called whenever the session cookie is set.
270
ad34a019
TC
271=item siteuser_add($user, $who, $cfg)
272
273Called when a new user is created. $user is the user object, $who is
274'user' for registration, 'admin' for added by the admin.
275
276=item siteuser_edit($user, $who, $cfg)
277
278Called when changes to a user are saved. $user is the user object,
279$who is 'user' for user saving options, 'admin' for changes made by
280the admin, or 'import' if a file of users was imported.
281
282=item group_add_member($group, $user_id, $cfg)
283
284Called when a user is added to a group. $group is the group object,
285$user_id is the numeric id of the user.
286
287=item group_remove_member($group, $user_id, $cfg)
288
289Called when a user is removed from a group. $group is the group
290object, $user_id is the numeric id of the user.
291
14604ada
TC
292=item order_complete($cfg, $order)
293
294Called when the supplied order has been completed. It may or may not
295have been paid.
296
5163fd16 297=back
5d18c301
TC
298
299=cut