rename coupon_discount to match the method in BSE::Cart
authorTony Cook <tony@develop-help.com>
Thu, 13 Jun 2013 01:17:24 +0000 (11:17 +1000)
committerTony Cook <tony@develop-help.com>
Sun, 21 Jul 2013 23:34:15 +0000 (09:34 +1000)
for improved compat between the two

schema/bse.sql
site/cgi-bin/modules/BSE/TB/Order.pm
site/util/mysql.str

index 988843e5060471af517306ff370501ab9a250ac0..146fce59fa11d2e5b5d468b396d3b7a04bfc3860 100644 (file)
@@ -350,7 +350,7 @@ create table orders (
   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),
index 3c256fecfc050995d2926b50119312cd0e22e2a9..835e0ea62ce690288ff4c0b85ea41ae43cfa6cc7 100644 (file)
@@ -7,7 +7,7 @@ use vars qw/@ISA/;
 use Carp 'confess';
 use BSE::Shop::PaymentTypes;
 
-our $VERSION = "1.018";
+our $VERSION = "1.019";
 
 sub columns {
   return qw/id
@@ -30,7 +30,7 @@ sub columns {
            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 {
@@ -684,4 +684,78 @@ sub is_manually_paid {
     ($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;
index ad6680c32f1705bb42d1775fbfc98a5cc58a031d..2bf7bfb180c827d2b4511c987d5e4b75aa1f3edb 100644 (file)
@@ -677,7 +677,7 @@ Column stage;varchar(20);NO;;
 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]