]> git.imager.perl.org - bse.git/blob - site/cgi-bin/modules/BSE/Generate/Product.pm
move product module into bse module dir
[bse.git] / site / cgi-bin / modules / BSE / Generate / Product.pm
1 package BSE::Generate::Product;
2 use strict;
3 use BSE::Generate::Article;
4 use Products;
5 use BSE::TB::Images;
6 use base qw(BSE::Generate::Article);
7 use Constants qw(:shop $CGI_URI $ADMIN_URI);
8 use Carp qw(confess);
9 use BSE::Util::HTML;
10 use BSE::Util::Tags qw(tag_article);
11
12 our $VERSION = "1.001";
13
14 sub edit_link {
15   my ($self, $id) = @_;
16   return "/cgi-bin/admin/add.pl?id=$id";
17 }
18
19 sub generate {
20   my ($self, $article, $articles) = @_;
21
22   my $product = Products->getByPkey($article->{id});
23   return $self->SUPER::generate($product, $articles);
24 }
25
26 sub _default_admin {
27   my ($self, $product, $embedded) = @_;
28
29        my $html = <<HTML;
30 <table>
31 <tr>
32 <td><form action="$CGI_URI/admin/add.pl">
33 <input type=hidden name="edit" value=1>
34 <input type=hidden name=id value=$product->{id}>
35 <input type=submit value="Edit Product"></form></td>
36 <td><form action="$ADMIN_URI">
37 <input type=submit value="Admin menu">
38 </form></td>
39 <td><form action="$CGI_URI/admin/admin.pl" target="_blank">
40 <input type=submit value="Display">
41 <input type=hidden name=admin value=0>
42 <input type=hidden name=id value="$product->{id}"></form></td>
43 </tr>
44 </table>
45 HTML
46 }
47
48 sub baseActs {
49   my ($self, $articles, $acts, $product, $embedded) = @_;
50
51   unless ($product->isa('Product')) {
52     $product = Products->getByPkey($product->{id});
53   }
54
55   my @stepcats = $product->step_parents();
56   my $stepcat_index;
57   my @options = $product->option_descs($self->{cfg});
58   my $option_index;
59
60   return
61     (
62      $self->SUPER::baseActs($articles, $acts, $product, $embedded),
63      product=> [ \&tag_article, $product, $self->{cfg} ],
64      admin => [ tag_admin => $self, $product, 'product', $embedded ],
65      iterate_options_reset => sub { $option_index = -1 },
66      iterate_options => sub { ++$option_index < @options },
67      option => 
68      sub {
69        if ($_[0] eq 'popup') {
70          my $option = $options[$option_index];
71          my @args =
72            (
73             -name      => $option->{id},
74             -id        => $option->{id},
75             -values    => $option->{values},
76             -override  => 1,
77            );
78          push(@args, -labels=>$option->{labels}) if $option->{labels};
79          push(@args, -default=>$option->{default}) if $option->{default};
80          return BSE::Util::HTML::popup_menu(@args);
81        }
82        else {
83          return escape_html($options[$option_index]{$_[0]})
84        }
85      },
86      ifOptions => sub { @options },
87      iterate_stepcats_reset => sub { $stepcat_index = -1 },
88      iterate_stepcats => sub { ++$stepcat_index < @stepcats },
89      stepcat => sub { tag_article($stepcats[$stepcat_index], $self->{cfg}, $_[0]) },
90      ifStepCats => sub { @stepcats },
91     );
92 }
93
94 sub visible {
95   my ($self, $article) = @_;
96   return $article->{listed};
97 }
98
99 sub get_real_article {
100   my ($self, $article) = @_;
101
102   return Products->getByPkey($article->{id});
103 }
104
105 1;
106
107 __END__
108
109 =head1 NAME
110
111   BSE::Generate::Product - generates product detail pages for BSE
112
113 =head1 DESCRIPTION
114
115 Like the NAME says.
116
117 =head1 TAGS
118
119 =over 4
120
121 =item product I<field>
122
123 Access to product fields of the product being rendered.  This is the
124 same as the C<article> I<field> tag for normal articles, but also give
125 you access to the product fields.
126
127 =item admin
128
129 Produces product specific administration links in admin mode.
130
131 =item iterator ... options
132
133 Iterates over the options available for the product, setting the option tag.
134
135 =item option popup
136
137 The popup list of values for the current option.
138
139 =item option field
140
141 Retrieves the given field from the option.  Most commonly you just
142 want the desc field.
143
144   <:if Options:>
145   <!-- you might want to start a table here -->
146   <:iterator begin options:>
147   <:option desc:>: <:option popup:>
148   <:iterator end options:>
149   <!-- and end a table here -->
150   <:or Options:><:eif Options:>
151
152 =item iterator ... stepcats
153
154 Iterates over any step parents of the product, setting the I<stepcat>
155 for each element.
156
157 =item stepcat I<field>
158
159 Access to fields of the step catalogs of the parent.
160
161 =item ifStepCats
162
163 Conditional tag, true if the product has any step catalogs.
164
165 =back
166
167 =head2 Product specific fields
168
169 =over 4
170
171 =item summary
172
173 An in-between length description of the article for use on the catalog
174 page.
175
176 =item leadTime
177
178 The number of days it takes to receive the product after it has been
179 ordered.
180
181 =item retailPrice
182
183 The cost to the customer of the product.  You need to use the C<money>
184 tag to format this field for display.
185
186 =item wholesalePrice
187
188 Your cost.  You need to use the C<money> tag to format this field for
189 display.
190
191 =item gst
192
193 The GST (in Australia) payable on the product.
194
195 =item options
196
197 The raw version of the options that can be set for this product.
198
199 =back
200
201 =cut