From e451fdb29259e318cba5498f2e989a17c1d154f8 Mon Sep 17 00:00:00 2001 From: konrad Date: Tue, 8 Feb 2011 21:37:01 +0000 Subject: [PATCH] mail on order create and important order changes git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@724 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- www/config.php.template | 3 + www/inc/rendering/twig_extensions.php | 1 + www/inc/wext/cart.php | 2 + www/inc/wext/order.php | 54 +++++++++++++++++++++++- www/inc/wext/ticket.php | 6 +++ www/template/en/ordermail.txt | 72 +++++++++++++++++++++++++++++++++ 6 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 www/template/en/ordermail.txt diff --git a/www/config.php.template b/www/config.php.template index a9f6a21..854b646 100644 --- a/www/config.php.template +++ b/www/config.php.template @@ -143,4 +143,7 @@ $CustomerResetTime=24 * 60 * 60; // leave commented out or empty if MagicSmoke should figure it out automatically // $BaseUrl = "https://localhost/smoke/index.php"; +//make sure files are interpreted as UTF-8 +// mb_language('uni'); + ?> \ No newline at end of file diff --git a/www/inc/rendering/twig_extensions.php b/www/inc/rendering/twig_extensions.php index 5bc9a66..36e9366 100644 --- a/www/inc/rendering/twig_extensions.php +++ b/www/inc/rendering/twig_extensions.php @@ -49,6 +49,7 @@ class SmokeFilterExtension extends Twig_Extension return array( 'isObject' => new Twig_Filter_Method($this, 'isObjectTest'), 'isFalse' => new Twig_Filter_Method($this, 'isFalse'), + 'isNull' => new Twig_Filter_Method($this, 'isFalse'), 'getClass' => new Twig_Filter_Method($this, 'getClass'), ); } diff --git a/www/inc/wext/cart.php b/www/inc/wext/cart.php index c88c6c9..8f123e9 100644 --- a/www/inc/wext/cart.php +++ b/www/inc/wext/cart.php @@ -110,6 +110,8 @@ class WOCartOrder extends WOCartOrderAbstract //return verified cart and order $trans->setorder($ord); $trans->setcart($cart); + //send mail + $ord->mailDetails(); } /**helper function for createOrder: verifies customer settings*/ diff --git a/www/inc/wext/order.php b/www/inc/wext/order.php index 991cae0..22d7ff0 100644 --- a/www/inc/wext/order.php +++ b/www/inc/wext/order.php @@ -218,7 +218,10 @@ class WOOrder extends WOOrderAbstract $ord->status=WTorder::Sent; $ord->update(); //return - $trans->setorder(WOOrder::fromTableorder($ord)); + $order=WOOrder::fromTableorder($ord); + $trans->setorder($order); + //mail + $order->mailDetails(); } /**called from the OrderAddComment transaction*/ @@ -401,7 +404,10 @@ class WOOrder extends WOOrderAbstract $tick->update(); } //return - $trans->setorder(WOOrder::fromTableorder($ord)); + $order=WOOrder::fromTableorder($ord); + $trans->setorder($order); + //mail + $order->mailDetails(); } /**called from the ReturnTicketVoucher transaction*/ @@ -526,7 +532,10 @@ class WOOrder extends WOOrderAbstract $ord->update(); //return - $trans->setorder(WOOrder::fromTableorder($ord)); + $order=WOOrder::fromTableorder($ord); + $trans->setorder($order); + //send mail + $order->mailDetails(); } /**called from the two functions below - checks whether the ticket can be changed*/ @@ -693,6 +702,45 @@ class WOOrder extends WOOrderAbstract $trans->setvouchers( WOVoucherAudit::fromTableArrayvoucher_audit( WTvoucher_audit::selectFromDB($w))); $trans->settickets( WOTicketAudit::fromTableArrayticket_audit( WTticket_audit::selectFromDB($w))); } + + ///mail order details to customer + public function mailDetails() + { + //get customer + $ct=WTcustomer::getFromDB($this->getcustomerid()); + if(!is_a($ct,"WTcustomer")){ + return; + } + if(!isEmail($ct->email)){ + return; + } + //set reset parameters + global $MailFrom; + //init twig + BaseVars::initTwig(); + BaseVars::init(); + //gather basics and render mail + global $twig,$basevars; + $p=$twig->loadTemplate("ordermail.txt"); + $list['customer']=WOCustomer::fromTablecustomer($ct); + $list['order']=$this; + $page=explode("\n",trim($p->render($list))); + //parse mail + if(count($page)<2)return; + $subject=array_shift($page); + $mode=0; + $mailtext="";$mailheader=""; + foreach($page as $line){ + if($mode==0){ + if(trim($line)=="")$mode=1; + else $mailheader.=$line."\n"; + }else{ + $mailtext.=$line."\n"; + } + } + //send mail + mb_send_mail($ct->email,$subject,$mailtext,$mailheader); + } }; ?> \ No newline at end of file diff --git a/www/inc/wext/ticket.php b/www/inc/wext/ticket.php index 56632cc..f80a5d3 100644 --- a/www/inc/wext/ticket.php +++ b/www/inc/wext/ticket.php @@ -76,6 +76,12 @@ class WOTicket extends WOTicketAbstract //return $trans->setticketuse($ret); } + + ///helper to get the event data in templates + public function getevent() + { + return WOEvent::fromTableevent(WTevent::getFromDB($this->geteventid())); + } }; ?> \ No newline at end of file diff --git a/www/template/en/ordermail.txt b/www/template/en/ordermail.txt new file mode 100644 index 0000000..7a36469 --- /dev/null +++ b/www/template/en/ordermail.txt @@ -0,0 +1,72 @@ +{# +This template contains the mail sent to a customer +when an order for this customer is created or changes. + +The first non-empty line contains the subject, +subsequent lines contain the headers, then an empty line +and after that the body of the mail. +#} +Order {{order.orderid}} Details at MagicSmoke.silmor.de +From: no-reply@localdomain.com +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 8bit + +Hello {{customer.title}} {{customer.name}}! + +Your order number {{order.orderid}} is currently at the status {{order.str_status}}. + +{% if order.invoiceaddress|isObject %} +Your order will be invoiced to the following address: +{{order.invoiceaddress.name}} +{{order.invoiceaddress.addr1}} +{{order.invoiceaddress.addr2}} +{{order.invoiceaddress.city}} {{order.invoiceaddress.state}} +{{order.invoiceaddress.zipcode}} {% if order.invoiceaddress.country|isObject %}{{order.invoiceaddress.country.name}}{% endif %} +{% endif %} + +{% if order.deliveryaddress|isObject %} +Your order will be delivered to the following address: +{{order.deliveryaddress.name}} +{{order.deliveryaddress.addr1}} +{{order.deliveryaddress.addr2}} +{{order.deliveryaddress.city}} {{order.deliveryaddress.state}} +{{order.deliveryaddress.zipcode}} {% if order.deliveryaddress.country|isObject %}{{order.deliveryaddress.country.name}}{% endif %} +{% endif %} + + + +total price : {{order.totalprice|asMoney}} +already paid: {{order.amountpaid|asMoney}} +payment due : {{order.amountdue|asMoney}} + + +Detailed listing: + +{% for ticket in order.tickets %} +Ticket: {{ticket.event.title}} ({{ticket.pricecategory.name}}) {{ticket.price|asMoney}} ({{ticket.str_status}}) +{% endfor %} +{% for voucher in order.vouchers %} +Voucher (Value: {{voucher.value|asMoney}}): {{voucher.price|asMoney}} +{% endfor %} +{% for item in order.items %} +{{item.amount}}x {{item.productname}} {{item.totalprice}} +{% endfor %} +{% if order.shippingtype|isObject %} +Shipping: {{order.shippingtype.description}} {{order.shippingcosts|asMoney}} +{% endif %} + + + +The order was created {{order.ordertime|asDateTime}}. + +{% if not order.senttime|isNull %} +{% if order.senttime > 0 %} +The order has been shipped {{order.senttime|asDateTime}}. +{% endif %} +{% endif %} + + + + + with best regards, + your MagicSmoke team -- 1.7.2.5