| 1 | use utf8; | ||
| 2 | |||
| 3 | package Dancer::Plugin::Interchange6::Cart::Product; | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | Dancer::Plugin::Interchange6::Cart::Product | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | Extends L<Interchange6::Cart::Product>. | ||
| 12 | |||
| 13 | =cut | ||
| 14 | |||
| 15 | use Interchange6::Types -types; | ||
| 16 | |||
| 17 | use Moo; | ||
| 18 | use MooseX::CoverableModifiers; | ||
| 19 | extends 'Interchange6::Cart::Product'; | ||
| 20 | use namespace::clean; | ||
| 21 | |||
| 22 | =head1 ATTRIBUTES | ||
| 23 | |||
| 24 | See L<Interchange6::Cart::Product/ATTRIBUTES> for inherited attributes. | ||
| 25 | |||
| 26 | =head2 dbic_product | ||
| 27 | |||
| 28 | Used to stash the related L<Interchange6::Schema::Result::Product> object | ||
| 29 | so that other accessors can be lazily built from it on demand. | ||
| 30 | |||
| 31 | Required. | ||
| 32 | |||
| 33 | =cut | ||
| 34 | |||
| 35 | has dbic_product => ( | ||
| 36 | is => 'lazy', | ||
| 37 | required => 1, | ||
| 38 | ); | ||
| 39 | |||
| 40 | =head2 selling_price | ||
| 41 | |||
| 42 | Inherited. Lazily set via L</dbic_product>. | ||
| 43 | |||
| 44 | =over | ||
| 45 | |||
| 46 | =item clearer: clear_selling_price | ||
| 47 | |||
| 48 | =back | ||
| 49 | |||
| 50 | L</clear_selling_price> is called whenever | ||
| 51 | L<Interchange6::Cart::Product/set_quantity> gets called so that possible | ||
| 52 | quantity based pricing is recalculated. | ||
| 53 | |||
| 54 | =cut | ||
| 55 | |||
| 56 | has '+selling_price' => ( | ||
| 57 | is => 'lazy', | ||
| 58 | clearer => 1, | ||
| 59 | ); | ||
| 60 | |||
| 61 | sub _build_selling_price { | ||
| 62 | my $self = shift; | ||
| 63 | $self->dbic_product->selling_price({quantity => $self->quantity}); | ||
| 64 | } | ||
| 65 | |||
| 66 | after 'set_quantity' => sub { | ||
| 67 | shift->clear_selling_price; | ||
| 68 | }; | ||
| 69 | |||
| 70 | 1; |