modernize edit_prodopts.tmpl
[bse.git] / site / cgi-bin / modules / BSE / TB / ProductOption.pm
CommitLineData
58baa27b
TC
1package BSE::TB::ProductOption;
2use strict;
3use base 'Squirrel::Row';
4
c274a8aa 5our $VERSION = "1.001";
cb7fd78d 6
58baa27b
TC
7sub columns {
8 return qw/id product_id name type global_ref display_order enabled default_value/;
9}
10
11sub table {
12 "bse_product_options";
13}
14
15sub defaults {
16 return
17 (
18 global_ref => undef,
19 enabled => 1,
20 type => "select",
21 default_value => 0,
22 );
23}
24
25sub values {
26 my ($self) = @_;
27
28 require BSE::TB::ProductOptionValues;
29 return sort { $a->{display_order} <=> $b->{display_order} }
30 BSE::TB::ProductOptionValues->getBy(product_option_id => $self->{id});
31}
32
33sub key {
34 my $self = shift;
35 return "prodopt_" . $self->id;
36}
37
0cca6ce6
TC
38sub remove {
39 my ($self) = @_;
40
41 my @values = $self->values;
42 for my $value (@values) {
43 $value->remove;
44 }
45
46 return $self->SUPER::remove;
47}
48
c274a8aa
TC
49sub data_only {
50 my ($self) = @_;
51
52 my $result = $self->SUPER::data_only;
53 $result->{values} = [ map $_->data_only, $self->values ];
54
55 return $result;
56}
57
58baa27b 581;