paid_manually integer not null default 0,
coupon_code varchar(40) not null default '',
- coupon_discount real not null default 0,
+ coupon_code_discount_pc real not null default 0,
primary key (id),
index order_cchash(ccNumberHash),
use Carp 'confess';
use BSE::Shop::PaymentTypes;
-our $VERSION = "1.018";
+our $VERSION = "1.019";
sub columns {
return qw/id
delivStreet2 billStreet2 purchase_order shipping_method
shipping_name shipping_trace
paypal_token paypal_tran_id freight_tracking stage ccPAN
- paid_manually/;
+ paid_manually coupon_code coupon_code_discount_pc/;
}
sub table {
($self->paid_manually || $self->paymentType == PAYMENT_MANUAL);
}
+=item coupon_valid
+
+For compatibility with cart objects, returns true if the currently
+stored coupon is valid.
+
+Since only an active coupon is stored, if we have a coupon code, then
+it's valid.
+
+=cut
+
+sub coupon_valid {
+ my ($self) = @_;
+
+ return $self->coupon_code ne "";
+}
+
+=item coupon_active
+
+For compatibility with cart objects, returns true if the currently
+stored coupon is active.
+
+Since only an active coupon is stored, if we have a coupon code, then
+it's valid.
+
+=cut
+
+*coupon_active = \&coupon_valid;
+
+=item total_cost
+
+Return the total cost of products without the coupon discount applied.
+
+=cut
+
+sub total_cost {
+ my ($self) = @_;
+
+ my $total = 0;
+ for my $item ($self->items) {
+ $total += $item->extended("price");
+ }
+
+ return $total;
+}
+
+=item discounted_product_cost
+
+Return the total cost of products less the discount from the coupon
+code.
+
+=cut
+
+sub discounted_product_cost {
+ my ($self) = @_;
+
+ my $cost = $self->total_cost;
+
+ $cost -= $cost * $self->coupon_code_discount_pc / 100;
+
+ return int($cost);
+}
+
+=item product_cost_discount
+
+Return any amount taken off the product cost.
+
+=cut
+
+sub product_cost_discount {
+ my ($self) = @_;
+
+ return $self->total_cost - $self->discounted_product_cost;
+}
+
1;
Column ccPAN;varchar(4);NO;;
Column paid_manually;int(11);NO;0;
Column coupon_code;varchar(40);NO;;
-Column coupon_discount;double;NO;0;
+Column coupon_code_discount_pc;double;NO;0;
Index PRIMARY;1;[id]
Index order_cchash;0;[ccNumberHash]
Index order_userId;0;[userId;orderDate]