add support for storing custom metadata to cart/order items and options
[bse.git] / site / cgi-bin / modules / BSE / TB / ProductOption.pm
CommitLineData
58baa27b
TC
1package BSE::TB::ProductOption;
2use strict;
33d04a1b 3use parent 'Squirrel::Row', 'BSE::CustomData';
58baa27b 4
33d04a1b 5our $VERSION = "1.002";
cb7fd78d 6
58baa27b 7sub columns {
33d04a1b 8 return qw/id product_id name type global_ref display_order enabled default_value custom_data/;
58baa27b
TC
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,
33d04a1b 22 custom_data => undef,
58baa27b
TC
23 );
24}
25
26sub values {
27 my ($self) = @_;
28
29 require BSE::TB::ProductOptionValues;
30 return sort { $a->{display_order} <=> $b->{display_order} }
31 BSE::TB::ProductOptionValues->getBy(product_option_id => $self->{id});
32}
33
34sub key {
35 my $self = shift;
36 return "prodopt_" . $self->id;
37}
38
0cca6ce6
TC
39sub remove {
40 my ($self) = @_;
41
42 my @values = $self->values;
43 for my $value (@values) {
44 $value->remove;
45 }
46
47 return $self->SUPER::remove;
48}
49
c274a8aa
TC
50sub data_only {
51 my ($self) = @_;
52
53 my $result = $self->SUPER::data_only;
54 $result->{values} = [ map $_->data_only, $self->values ];
55
56 return $result;
57}
58
58baa27b 591;