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