mail on order create and important order changes
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Tue, 8 Feb 2011 21:37:01 +0000 (21:37 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Tue, 8 Feb 2011 21:37:01 +0000 (21:37 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@724 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

www/config.php.template
www/inc/rendering/twig_extensions.php
www/inc/wext/cart.php
www/inc/wext/order.php
www/inc/wext/ticket.php
www/template/en/ordermail.txt [new file with mode: 0644]

index a9f6a21..854b646 100644 (file)
@@ -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
index 5bc9a66..36e9366 100644 (file)
@@ -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'),
                );
        }
index c88c6c9..8f123e9 100644 (file)
@@ -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*/
index 991cae0..22d7ff0 100644 (file)
@@ -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
index 56632cc..f80a5d3 100644 (file)
@@ -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 (file)
index 0000000..7a36469
--- /dev/null
@@ -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