Aw: Resend the updated Purchase order as an invoice
Here's what I've done. Not always elegant, but it seems to work.
Files affected:
administrator/components/com_jshopping/controllers/orders.php
components/com_jshopping/models/checkout.php
components/com_jshopping/templates/default/checkout/invoiceemail.php - copied and modified from orderemail.php
I copied and modified function sendOorderEmail() from checkout.php I put it outside the class JshoppingColtrolOrders in order.php
function AsendOrderEmail($order_id, $manuallysend = 0){
$mainframe = JFactory::getApplication();
$lang = JSFactory::getLang();
$jshopConfig = JSFactory::getConfig();
$db = JFactory::getDBO();
$order = JTable::getInstance('order', 'jshop');
$jshopConfig->user_field_title[0] = '';
$jshopConfig->user_field_client_type[0] = '';
$file_generete_pdf_order = $jshopConfig->file_generete_pdf_order;
$tmp_fields = $jshopConfig->getListFieldsRegister();
$config_fields = $tmp_fields["address"];
$count_filed_delivery = $jshopConfig->getEnableDeliveryFiledRegistration('address');
$order->load($order_id);
$status = JTable::getInstance('orderStatus', 'jshop');
$status->load($order->order_status);
$name = $lang->get("name");
$order->status = $status->$name;
$order->order_date = strftime($jshopConfig->store_date_format, strtotime($order->order_date));
$order->products = $order->getAllItems();
$order->weight = $order->getWeightItems();
if ($jshopConfig->show_delivery_time_checkout){
$deliverytimes = JSFactory::getAllDeliveryTime();
if (isset($deliverytimes[$order->delivery_times_id])){
$order->order_delivery_time = $deliverytimes[$order->delivery_times_id];
}else{
$order->order_delivery_time = '';
}
if ($order->order_delivery_time==""){
$order->order_delivery_time = $order->delivery_time;
}
}
$order->order_tax_list = $order->getTaxExt();
$show_percent_tax = 0;
if (count($order->order_tax_list)>1 || $jshopConfig->show_tax_in_product) {$show_percent_tax = 1;}
if ($jshopConfig->hide_tax) {$show_percent_tax = 0;}
$hide_subtotal = 0;
if (($jshopConfig->hide_tax || count($order->order_tax_list)==0) && $order->order_discount==0 && $jshopConfig->without_shipping && $order->order_payment==0){$hide_subtotal = 1;}
$country = JTable::getInstance('country', 'jshop');
$country->load($order->country);
$field_country_name = $lang->get("name");
$order->country = $country->$field_country_name;
$d_country = JTable::getInstance('country', 'jshop');
$d_country->load($order->d_country);
$field_country_name = $lang->get("name");
$order->d_country = $d_country->$field_country_name;
if ($jshopConfig->show_delivery_date && !datenull($order->delivery_date)){
$order->delivery_date_f = formatdate($order->delivery_date);
}else{
$order->delivery_date_f = '';
}
$order->title = $jshopConfig->user_field_title[$order->title];
$order->d_title = $jshopConfig->user_field_title[$order->d_title];
$order->birthday = getDisplayDate($order->birthday, $jshopConfig->field_birthday_format);
$order->d_birthday = getDisplayDate($order->d_birthday, $jshopConfig->field_birthday_format);
$order->client_type_name = $jshopConfig->user_field_client_type[$order->client_type];
$shippingMethod = JTable::getInstance('shippingMethod', 'jshop');
$shippingMethod->load($order->shipping_method_id);
$pm_method = JTable::getInstance('paymentMethod', 'jshop');
$pm_method->load($order->payment_method_id);
$paymentsysdata = $pm_method->getPaymentSystemData();
$payment_system = $paymentsysdata->paymentSystem;
$name = $lang->get("name");
$description = $lang->get("description");
$order->shipping_information = $shippingMethod->$name;
$order->payment_name = $pm_method->$name;
$order->payment_information = $order->payment_params;
if ($payment_system){
$payment_system->prepareParamsDispayMail($order, $pm_method);
}
if ($pm_method->show_descr_in_email) {
$order->payment_description = $pm_method->$description;
}else{
$order->payment_description = "";
}
$statictext = JTable::getInstance("statictext","jshop");
$rowstatictext = $statictext->loadData("order_email_descr");
$order_email_descr = $rowstatictext->text;
$order_email_descr = str_replace("{name}",$order->f_name, $order_email_descr);
$order_email_descr = str_replace("{family}",$order->l_name, $order_email_descr);
$order_email_descr = str_replace("{email}",$order->email, $order_email_descr);
$order_email_descr = str_replace("{title}",$order->title, $order_email_descr);
$rowstatictext = $statictext->loadData("order_email_descr_end");
$order_email_descr_end = $rowstatictext->text;
$order_email_descr_end = str_replace("{name}",$order->f_name, $order_email_descr_end);
$order_email_descr_end = str_replace("{family}",$order->l_name, $order_email_descr_end);
$order_email_descr_end = str_replace("{email}",$order->email, $order_email_descr_end);
$order_email_descr_end = str_replace("{title}",$order->title, $order_email_descr_end);
$text_total = _JSHOP_ENDTOTAL;
if (($jshopConfig->show_tax_in_product || $jshopConfig->show_tax_product_in_cart) && (count($order->order_tax_list)>0)){
$text_total = _JSHOP_ENDTOTAL_INKL_TAX;
}
$uri = JURI::getInstance();
$liveurlhost = $uri->toString(array("scheme",'host', 'port'));
if ($jshopConfig->admin_show_vendors){
$listVendors = $order->getVendors();
}else{
$listVendors = array();
}
$vendors_send_message = $jshopConfig->vendor_order_message_type==1;
$vendor_send_order = $jshopConfig->vendor_order_message_type==2;
$vendor_send_order_admin = (($jshopConfig->vendor_order_message_type==2 && $order->vendor_type == 0 && $order->vendor_id) || $jshopConfig->vendor_order_message_type==3);
if ($vendor_send_order_admin) {$vendor_send_order = 0;}
$admin_send_order = 1;
if ($jshopConfig->admin_not_send_email_order_vendor_order && $vendor_send_order_admin && count($listVendors)) {$admin_send_order = 0;}
JPluginHelper::importPlugin('jshoppingorder');
$dispatcher = JDispatcher::getInstance();
$dispatcher->trigger('onBeforeSendEmailsOrder', array(&$order, &$listVendors, &$file_generete_pdf_order, &$admin_send_order));
//client message
include_once(JPATH_COMPONENT_SITE."/views/checkout/view.html.php");
$view_name = "checkout";
$view_config = array("template_path"=>JPATH_COMPONENT_SITE."/templates/".$jshopConfig->template."/".$view_name);
$view = new JshoppingViewCheckout($view_config);
$view->setLayout("invoiceemail");
/*if($order->status,,,
...}*/
$pdfsend = 1;
if ($jshopConfig->send_invoice_manually && !$manuallysend){ $pdfsend = 0;}
if ($pdfsend && ($jshopConfig->order_send_pdf_client || $jshopConfig->order_send_pdf_admin)){
include_once($file_generete_pdf_order);
$order->setInvoiceDate();
$order->pdf_file = generatePdf($order, $jshopConfig);
$order->insertPDF();
}
$mailfrom = $mainframe->getCfg('mailfrom');
$fromname = $mainframe->getCfg('fromname');
//send mail client
if ($order->email){
$subj= _JSHOP_PURCHASE_ORDER;
$os=$order->status;
if($os=="Paid"||$os=="Shipped"||$os=="Collectable"){$subj= _JSHOP_PO_TO_INVOICE." ".$os;}
if($os=="Confirmed"||$os=="Pending"||$os=="Adjusted"){$subj.= " ".$os;}
$mailer = JFactory::getMailer();
$mailer->setSender(array(/*$mailfrom*/"sales@partyshop.co.za", $fromname));
$mailer->addRecipient($order->email);
$mailer->setSubject( sprintf($subj, $order->order_number));
$mailer->setBody($message_client);
if ($pdfsend && $jshopConfig->order_send_pdf_client){
$mailer->addAttachment($jshopConfig->pdf_orders_path."/".$order->pdf_file);
}
$mailer->isHTML(true);
$send = $mailer->Send();
}
/*send mail admin...
...}*/
$dispatcher->trigger('onAfterSendEmailsOrder', array(&$order));
}// function AsendOrderEmail end
Below jimport('joomla.application.component.controller');
I added the A (AsendOrderEmail) to indicate it used from Admin (backend).
In order.php further down I did this:
//message client
if ($notify){
$ishtml = true;
//copied the function sendOrderEmail from checkout.php put it at the top
AsendOrderEmail($order_id,0);
/* $subject = sprintf(_JSHOP_ORDER_STATUS_CHANGE_SUBJECT, $order->order_number);
$dispatcher->trigger('onBeforeSendClientMailOrderStatus', array(&$message, &$order, &$comments, &$new_status, &$vendorinfo, &$order_details_url, &$ishtml, &$mailfrom, &$fromname, &$subject));
$mailer = JFactory::getMailer();
$mailer->setSender(array($mailfrom, $fromname));
$mailer->addRecipient($order->email);
$mailer->setSubject($order_status." - ".$prev_order_status);
$mailer->setBody($message);
$mailer->isHTML($ishtml);
$send = $mailer->Send();
*/ }
Now here is the interesting stuff I did with the template invoiceemail.php. Below the <body> tag I put the following:
<?php /*Define variables basend on conditions so you don't have so many "if" statements all over the place.*/
$emailtitle=_JSHOP_EMAIL_PURCHASE_ORDER;
$emailtitle1=$emailtitle;
// Paid
if($this->order->status=="Paid"){
$emailtitle=_JSHOP_EMAIL_INVOICE;
$emailtitle1=$emailtitle;
$infotext="<p style='padding:10px; background:#fff;'>This is confirmation that we have received payment for your order.<br />";
if($this->order->shipping_information=="Courier to me"){$infotext.="We will notify you soon when your order has been couriered.</p>";}
if($this->order->shipping_information=="I will Collect"){$infotext.="We will notify you soon when your order is ready for collection.</p>";}
$eftinfo="<b>Payment received, Thank you.</b>";
}
// Shipped
if($this->order->status=="Shipped"){
$emailtitle=_JSHOP_EMAIL_INVOICE;
$emailtitle1=$emailtitle;
$infotext="<p style='padding:10px; background:#fff;'>This is to inform you that your order has now collected by the courier. Your way bill number is: <b>".$this->order->payment_information."</b>. Should it not arrive with in 2 working days please contact us during normal business hours.<br />Mon-Fri 09:00-17:00, Sat 08:00-13:00<br />";
$eftinfo="<b>Payment received, Thank you.</b>";
}
// Collectable
if($this->order->status=="Collectable"){
$emailtitle=_JSHOP_EMAIL_INVOICE;
$emailtitle1=$emailtitle;
$infotext="<p style='padding:10px; background:#fff;'>This is to let you know your order is now ready for collection. You are welcome to fectch it any time during normal business hours.<br />Mon-Fri 09:00-17:00, Sat 08:00-13:00<br />";
/* $eftinfo="<b>Payment received, Thank you.</b>";*/
}
// Confirmed
if($this->order->status=="Confirmed"){
$emailtitle.=" ".$this->order->status;
$infotext="<p style='padding:10px; background:#fff;'>Thank you for your order.<br />We have checked stock availability";
if($this->order->shipping_information=="Courier to me"){$infotext.=" and your delivery cost based on the address provided";}
$infotext.=". We confirm that all stock ordered is available and no adjustments to your order were done.<br />Please check through your order carefully and if everything is correct please pay via EFT with the bank details provided below.<br />Should you need to change anything please call us on 012 3489600, or reply to this email indicating the changes required.</p>";
$eftinfo="<b>Bank Details</b><br />Bank: Standard Bank<br />Account Name: Party Shop<br />Account Number: 411335391<br />Account type: Cheque Account<br />Branch: Menlyn 012345";
}
// Adjusted
if($this->order->status=="Adjusted"){
$emailtitle.=" ".$this->order->status;
$infotext="<p style='padding:10px; background:#fff;'>Thank you for your order.<br />We have checked stock availability";
if($this->order->shipping_information=="Courier to me"){$infotext.=" and your delivery cost based on the address provided";}
$infotext.=". We have made some necessary adjustments to your order.<br />Please check through your order carefully and if everything is correct please pay via EFT with the bank details provided below.<br />Should you find any mistakes or need to change anything please call us on 012 3489600, or reply to this email indicating the changes required.</p>";
$eftinfo="<b>Bank Details</b><br />Bank: Standard Bank<br />Account Name: Party Shop<br />Account Number: 411335391<br />Account type: Cheque Account<br />Branch: Menlyn 012345";
}
// Pending
?>
Then changed various line in the template to use the variables $infotext, $eftinof, $emailtitle etc.
<h2><?php print $emailtitle; ?></h2>
<h2> </h2>
<p style="font-size:16px;">Hello <?php print $this->order->f_name; ?> <?php print $this->order->l_name; ?>.</p><br />
<?php print $infotext; ?>
</td>
...
<tr class = "bg_gray">
<td colspan = "2"> <h3><?php print $emailtitle1; ?></h3> </td>
</tr>
<?php if (!$this->config->without_payment){?>
<td valign="top">
<div><?php print $this->order->payment_name;?><br />
<?php print $eftinfo; ?>
</div>
I move $this->order->payment_information from under payment to under delivery and use it to put the tracking number of the couriered order before changing the status to shipped.
if ($this->config->show_delivery_date && $order->delivery_date_f){
print "<div>"._JSHOP_DELIVERY_DATE.": ".$order->delivery_date_f."</div>";
}
if($this->order->payment_information){ print nl2br("\n<b>".$this->order->payment_information."</b>\n"); }
}?>
I hope this helps.