make the order variable available to the two purchase time mail templates
authorTony Cook <tony@develop-help.com>
Wed, 3 Jul 2013 14:13:36 +0000 (00:13 +1000)
committerTony Cook <tony@develop-help.com>
Sun, 21 Jul 2013 23:34:16 +0000 (09:34 +1000)
MANIFEST
site/cgi-bin/modules/BSE/TB/Order.pm
site/cgi-bin/modules/BSE/UI/Shop.pm
site/templates/admin/order_detail.tmpl
site/templates/mailcommon.tmpl [new file with mode: 0644]
site/templates/mailconfirm.tmpl
site/templates/mailorder.tmpl

index b85c4c8..af8cfcd 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -760,6 +760,7 @@ site/templates/interest/confirm_base.tmpl
 site/templates/interest/error_base.tmpl
 site/templates/location.tmpl
 site/templates/lowmap.tmpl
+site/templates/mailcommon.tmpl
 site/templates/mailconfirm.tmpl
 site/templates/mailconfirm_html.tmpl
 site/templates/mailorder.tmpl
index 3340862..7e37d29 100644 (file)
@@ -7,7 +7,7 @@ use vars qw/@ISA/;
 use Carp 'confess';
 use BSE::Shop::PaymentTypes;
 
-our $VERSION = "1.021";
+our $VERSION = "1.022";
 
 sub columns {
   return qw/id
@@ -567,6 +567,34 @@ sub _tags {
     );
 }
 
+sub cfg_must_be_paid {
+  BSE::Cfg->single->entryBool("download", "must_be_paid", 0);
+}
+
+sub cfg_must_be_filled {
+  BSE::Cfg->single->entryBool("download", "must_be_filled", 0);
+}
+
+=item file_available
+
+Given an order file, return true if available for download.
+
+This will return nonsensical results for files not associated with the
+order.
+
+=cut
+
+sub file_available {
+  my ($self, $file) = @_;
+
+  $file->forSale or return 1;
+
+  return 0 if $self->cfg_must_be_paid && !$self->paidFor;
+  return 0 if $self->cfg_must_be_filled && !$self->filled;
+
+  return 1;
+}
+
 =item mail_tags
 
 =cut
index 62019d6..2cae178 100644 (file)
@@ -18,7 +18,7 @@ use BSE::Countries qw(bse_country_code);
 use BSE::Util::Secure qw(make_secret);
 use BSE::Template;
 
-our $VERSION = "1.042";
+our $VERSION = "1.043";
 
 =head1 NAME
 
@@ -1574,6 +1574,11 @@ sub _send_order {
      ifSubscribingTo => [ \&tag_ifSubscribingTo, \%subscribing_to ],
     );
 
+  my %vars =
+    (
+     order => $order,
+    );
+
   my $email_order = $cfg->entryBool('shop', 'email_order', $Constants::SHOP_EMAIL_ORDER);
   require BSE::ComposeMail;
   if ($email_order) {
@@ -1581,6 +1586,8 @@ sub _send_order {
       $acts{cardNumber} = $cgi->param('cardNumber');
       $acts{cardExpiry} = $cgi->param('cardExpiry');
       $acts{cardVerify} = $cgi->param('cardVerify');
+      @vars{qw(cardNumber cardExpiry cardVerify)} =
+       @acts{qw(cardNumber cardExpiry cardVerify)};
     }
 
     my $mailer = BSE::ComposeMail->new(cfg => $cfg);
@@ -1594,6 +1601,7 @@ sub _send_order {
        log_component => "shop:sendorder:mailowner",
        log_object => $order,
        log_msg => "Send Order No. $order->{id} to admin",
+       vars => \%vars,
       );
 
     unless ($noencrypt) {
@@ -1610,6 +1618,7 @@ sub _send_order {
     }
 
     delete @acts{qw/cardNumber cardExpiry cardVerify/};
+    delete @vars{qw/cardNumber cardExpiry cardVerify/};
   }
   my $to_email = $order->billEmail;
   my $user = $req->siteuser;
@@ -1628,6 +1637,7 @@ sub _send_order {
      log_component => "shop:sendorder:mailbuyer",
      log_object => $order,
      log_msg => "Send Order No. $order->{id} to customer ($to_email)",
+     vars => \%vars,
     );
   my $bcc_order = $cfg->entry("shop", "bcc_email");
   if ($bcc_order) {
index 7db60eb..38bd109 100644 (file)
 </tr>
 <:.if order.coupon -:>
 <tr>
-   <td>Coupon code <b><:= order.coupon.code -:></b></td>
+   <td>Coupon code <b><:= order.coupon_code -:></b></td>
    <td colspan="6" class="col_label_right">Discount:</td>
    <td class="col_extension">(<:= bse.number("money", order.product_cost_discount) -:>)</td>
 </tr>
diff --git a/site/templates/mailcommon.tmpl b/site/templates/mailcommon.tmpl
new file mode 100644 (file)
index 0000000..5d56dcb
--- /dev/null
@@ -0,0 +1,27 @@
+Order: <:= order.id.format("%06d") |raw :>
+
+Delivery: <:= order.delivFirstName |raw :> <:= order.delivLastName |raw:>
+          <:= order.delivStreet |raw:>
+          <:= order.delivSuburb |raw:> <:= order.delivPostCode |raw:> <:= order.delivState |raw:>
+          <:= order.delivCountry |raw:>
+
+Phone   : <:= order. telephone |raw:>
+<:.if order.delivMobile:>Mobile  : <:= order.delivMobile |raw:>
+<:.end if:>Fax     : <:= order.facsimile |raw:>
+Email   : <:= order.emailAddress |raw:>
+
+Product                                   Units  Price   Extended
+-----------------------------------------------------------------
+<:.for item in [ order.items ] -:>
+<:-= item.title.format("%-42s") |raw:>
+<:-= item.units.format("%2d") |raw:>
+<:-= bse.number("money", item.price).format("%10s") |raw:>
+<:-= bse.number("money", item.extended("price")).format("%11s") |raw:>
+<:-.if item.nice_options :>
+   <:= item.nice_options:>
+<:-.end if:>
+<:.end for -:>
+-----------------------------------------------------------------
+                                             Shipping: <:= bse.number("money", order.shipping_cost).format("%10s") :>
+                                                Total: <:= bse.number("money", order.total).format("%10s") :>
+                                                 GST: <:= bse.number("money", order.gst).format("%10s"):>
index 0e07f75..a58c514 100644 (file)
@@ -2,42 +2,27 @@ You have created an order with <:siteName:>:
 
 To stay up to date on the status of your order, see:
 
-  <:target user oda id [order randomId]:>
+  <:= cfg.user_url("user", "oda", "id", order.randomId) |raw:>
 
-Order: <:order id |%06d:>
+<:include mailcommon.tmpl:>
 
-Delivery: <:order delivFirstName :> <:order delivLastName :>
-          <:order delivStreet:>
-          <:order delivSuburb:> <:order delivPostCode:> <:order delivState:>
-          <:order delivCountry:>
-
-Phone   : <:order telephone:>
-<:ifOrder delivMobile:>Mobile  : <:order delivMobile:>
-<:or:><:eif:>Fax     : <:order facsimile:>
-Email   : <:order emailAddress:>
-
-Product                                   Units  Price   Extended
------------------------------------------------------------------
-<:iterator begin items:><:product title |42:><:item units|%2d:><:item price |m10:><:extended price|m11:><:if Options:>
-   <:options:><:or Options:><:eif Options:>
-<:iterator separator items:><:iterator end items 
-:>-----------------------------------------------------------------
-                                             Shipping: <:order shipping_cost |m10:>
-                                                Total: <:order total |m10:>
-                                                 GST: <:order gst   |m10:>
-
-<:ifEq [order paymentType] "0" :>Paid by credit card.
-<:if Order ccOnline
-:>Processed online.
-Receipt No.  : <:order ccReceipt:>
-<:or Order
-:><:eif Order:><:or:><:eif
-:><:ifEq [order paymentType] "1" :>Will be paid by cheque<:or
-:><:eif:><:ifEq [order paymentType] "2"
-:>We will call you to arrange for payment<:or:><:eif:><:ifEq [order paymentType] "4"
-:>Paid by PayPal, transaction id <:order paypal_tran_id:><:or:><:eif:><:
-include custom/payment_type_email.include:>
-To be shipped by: <:order shipping_method:>
-<:if Order instructions:>
-<:with begin wrap:>Special Instructions: <:order instructions:><:with end wrap:>
-<:or Order:><:eif Order:>
+<:.if order.paymentType == 0 -:>
+Paid by credit card:
+<:-  .if order.ccOnline :>
+  Processed online.
+  Receipt No.  : <:= order.ccReceipt:>
+<:  .end if -:>
+<:-.elsif order.paymentType == 1 -:>
+Will be paid by cheque
+<:-.elsif order.paymentType == 2 -:>
+Please call the customer to arrange for payment
+<:- .elsif order.paymentType == 4 -:>
+Paid by PayPal:
+  Transaction id: <:order paypal_tran_id:>
+<:.else -:>
+<:include custom/payment_type_email.include:>
+<:.-end if :>
+To be shipped by: <:= order.shipping_method :>
+<:.if order.instructions -:>
+<:with begin wrap:>Special Instruction: <:= order.instructions:><:with end wrap:>
+<:.end if -:>
index 02fe14f..495a0c2 100644 (file)
@@ -1,50 +1,38 @@
 A new order has arrived:
 
-Order: <:order id |%06d:>
+<:include mailcommon.tmpl:>
+<:.if order.paymentType == 0 -:>
+Paid by credit card:
+<:-  .if order.ccOnline :>
+  Processed online.
+  Receipt No.  : <:= order.ccReceipt:>
+<:-  .else :>
+  Card No.     : <:= cardNumber:>
+  Expires      : <:= cardExpiry:>
+  Name on Card : <:= order.ccName:>
+  Card Type    : <:= order.ccType :>
+<:  .end if -:>
+<:-.elsif order.paymentType == 1 -:>
+Will be paid by cheque
+<:-.elsif order.paymentType == 2 -:>
+Please call the customer to arrange for payment
+<:- .elsif order.paymentType == 4 -:>
+Paid by PayPal:
+  Transaction id: <:order paypal_tran_id:>
+<:.else -:>
+<:include custom/payment_type_email.include:>
+<:-.end if :>
 
-Delivery: <:order delivFirstName :> <:order delivLastName :>
-          <:order delivStreet:>
-          <:order delivSuburb:> <:order delivPostCode:> <:order delivState:>
-          <:order delivCountry:>
+To be shipped by: <:= order.shipping_method :>
+<:.if order.instructions :>
+<:with begin wrap:>Special Instruction: <:= order.instructions:><:with end wrap:>
+<:-.end if -:>
 
-Phone   : <:order telephone:>
-<:ifOrder delivMobile:>Mobile  : <:order delivMobile:>
-<:or:><:eif:>Fax     : <:order facsimile:>
-Email   : <:order emailAddress:>
-
-Product                                   Units  Price   Extended
------------------------------------------------------------------
-<:iterator begin items:><:product title |42:><:item units|%2d:><:item price |m10:><:extended price|m11:><:if Options:>
-   <:options:><:or Options:><:eif Options:>
-<:iterator separator items:><:iterator end items 
-:>-----------------------------------------------------------------
-                                             Shipping: <:order shipping_cost |m10:>
-                                                Total: <:order total |m10:>
-                                                 GST: <:order gst   |m10:>
-
-<:ifEq [order paymentType] "0":>Paid by credit card:
-<:if Order ccOnline
-:>Processed online.
-Receipt No.  : <:order ccReceipt:>
-<:or Order
-:>Card No.     : <:cardNumber:>
-Expires      : <:cardExpiry:>
-Name on Card : <:order ccName:>
-Card Type    : <:order ccType :><:eif Order:><:or:><:eif
-:><:ifEq [order paymentType] "1" :>Will be paid by cheque<:or
-:><:eif:><:ifEq [order paymentType] "2"
-:>Please call the customer to arrange for payment<:or:><:eif:><:ifEq [order paymentType] "4"
-:>Paid by PayPal, transaction id <:order paypal_tran_id:><:or:><:eif:><:
-include custom/payment_type_email.include:>
-To be shipped by: <:order shipping_method:>
-<:if Order instructions:>
-<:with begin wrap:>Special Instruction: <:order instructions:><:with end wrap:>
-<:or Order:><:eif Order:>
-
-<:if Orderfiles:>
-<:iterator begin orderfiles:>
+<:-.set files = [ order.files ] -:>
+<:-.if files.size :>
 File                                               Available
 -------------------------------------------------- ---------
-<:orderfile displayName |50:> <:ifFileAvail:>Yes<:or:>No<:eif:>
-<:iterator end orderfiles:>
-<:or Orderfiles:><:eif Orderfiles:>
+<:.for file in files -:>
+<:= file.displayName.format("%-50s") |raw:> <:= order.file_available(file) ? "Yes" : "No" :>
+<:.end for -:>
+<:.end if :>