1. создает и приаттачивает к письму, оповещающему админа о новом заказе XLS-файл с содержимым заказа
2. дает возможность нажав кнопку в админке в списке заказов получить аналогичный XLS-файл
Установка:
----------
1. распаковываваем архив с PHPExcel, находим в подкаталоге Classes файл PHPExcel.php и каталог PHPExcel и копируем оба (файл и каталог) в корень сайта.
2. копируем файл order2xls.php в core/includes/processor/
3. в файле admin.php вместо строки
if ( in_array($_GET["do"], array( "invoice", "configurator", "wishcat", "wishlist", "wishprod", "get_file", "crosslink_conf" ))) {
вставляем
# BEGIN XLS-to-email
#if ( in_array($_GET["do"], array( "invoice", "configurator", "wishcat", "wishlist", "wishprod", "get_file", "crosslink_conf" ))) {
if ( in_array($_GET["do"], array( "invoice", "configurator", "wishcat", "wishlist", "wishprod", "get_file", "crosslink_conf", "order2xls" ))) {
# END XLS-to-email
4. в файле order_functions.php
4.1 вставляем функцию
# BEGIN XLS-to-email
function order2xls ($orderID,$order,$content)
{
include_once 'PHPExcel.php';
$baseFont = array('font'=>array('name'=>'Arial Cyr','size'=>'10','bold'=>false));
$boldFont = array('font'=>array('name'=>'Arial Cyr','size'=>'10','bold'=>true));
$center = array('alignment'=>array('horizontal'=>PHPExcel_Style_Alignment::HORIZONTAL_CENTER,'vertical'=>PHPExcel_Style_Alignment::VERTICAL_TOP));
$right = array('alignment'=>array('horizontal'=>PHPExcel_Style_Alignment::HORIZONTAL_RIGHT, 'vertical'=>PHPExcel_Style_Alignment::VERTICAL_TOP));
$left = array('alignment'=>array('horizontal'=>PHPExcel_Style_Alignment::HORIZONTAL_LEFT, 'vertical'=>PHPExcel_Style_Alignment::VERTICAL_TOP));
$pExcel = new PHPExcel();
$pExcel->setActiveSheetIndex(0);
$aSheet = $pExcel->getActiveSheet();
$aSheet->setTitle(iconv('cp1251','UTF8','Заказ на поставку №').$orderID);
$aSheet->setCellValue('B1',iconv('cp1251','UTF8','Заказ на поставку №'));
$aSheet->getStyle('B1')->applyFromArray($boldFont)->applyFromArray($right);
$aSheet->setCellValue('C1',$orderID);
$aSheet->getStyle('C1')->applyFromArray($boldFont)->applyFromArray($center);
$aSheet->setCellValue('D1',iconv('cp1251','UTF8','от'));
$aSheet->getStyle('D1')->applyFromArray($boldFont)->applyFromArray($center);
$aSheet->setCellValue('E1',format_datetime($order["order_time"]));
$aSheet->getStyle('E1')->applyFromArray($boldFont)->applyFromArray($left);
$aSheet->setCellValue('A3',iconv('cp1251','UTF8','№'));
$aSheet->getStyle('A3')->applyFromArray($boldFont)->applyFromArray($center);
$aSheet->setCellValue('B3',iconv('cp1251','UTF8','Артикул'));
$aSheet->getStyle('B3')->applyFromArray($boldFont)->applyFromArray($center);
$aSheet->setCellValue('C3',iconv('cp1251','UTF8','Цена'));
$aSheet->getStyle('C3')->applyFromArray($boldFont)->applyFromArray($center);
$aSheet->setCellValue('D3',iconv('cp1251','UTF8','Кол-во'));
$aSheet->getStyle('D3')->applyFromArray($boldFont)->applyFromArray($center);
$aSheet->setCellValue('E3',iconv('cp1251','UTF8','Сумма'));
$aSheet->getStyle('E3')->applyFromArray($boldFont)->applyFromArray($center);
$aSheet->getColumnDimension('B')->setWidth(25);
foreach($content as $key => $value)
{
$aSheet->setCellValue('A'.($key+4),$key+1);
$aSheet->getStyle('A'.($key+4))->applyFromArray($baseFont)->applyFromArray($center);
$aSheet->setCellValue('B'.($key+4),$value['product_code']);
$aSheet->getStyle('B'.($key+4))->applyFromArray($baseFont)->applyFromArray($left);
$aSheet->setCellValue('C'.($key+4),$value['Price']);
$aSheet->getStyle('C'.($key+4))->applyFromArray($baseFont)->applyFromArray($right);
$aSheet->setCellValue('D'.($key+4),$value['Quantity']);
$aSheet->getStyle('D'.($key+4))->applyFromArray($baseFont)->applyFromArray($right);
$aSheet->setCellValue('E'.($key+4),$value['Price']*$value['Quantity']);
$aSheet->getStyle('E'.($key+4))->applyFromArray($baseFont)->applyFromArray($right);
$sum+=$value['Price']*$value['Quantity'];
}
$aSheet->setCellValue('B'.($key+6),iconv('cp1251','UTF8','Итого:'));
$aSheet->getStyle('B'.($key+6))->applyFromArray($boldFont)->applyFromArray($right);
$aSheet->setCellValue('E'.($key+6),$sum);
$aSheet->getStyle('E'.($key+6))->applyFromArray($boldFont)->applyFromArray($right);
include("PHPExcel/Writer/Excel5.php");
$objWriter = new PHPExcel_Writer_Excel5($pExcel);
return $objWriter;
}
# END XLS-to-email
4.2 в функции _sendOrderNotifycationToAdmin вместо строк
if (!CONF_ACTIVE_ORDER) xMailTxtHTMLDATA(CONF_ORDERS_EMAIL, STRING_ORDER." #".$orderID." - ".CONF_SHOP_NAME, $html);
else xMailTxtHTMLDATA(CONF_ORDERS_EMAIL, STRING_ORDER." #".$orderID." (".ADMIN_SEND_INACT_ORDER.") - ".CONF_SHOP_NAME, $html);
вставляем
# BEGIN XLS-to-email
# if (!CONF_ACTIVE_ORDER) xMailTxtHTMLDATA(CONF_ORDERS_EMAIL, STRING_ORDER." #".$orderID." - ".CONF_SHOP_NAME, $html);
# else xMailTxtHTMLDATA(CONF_ORDERS_EMAIL, STRING_ORDER." #".$orderID." (".ADMIN_SEND_INACT_ORDER.") - ".CONF_SHOP_NAME, $html);
$objWriter = order2xls($orderID,$order,$content);
$filename = 'core/temp/o_'.$orderID.'.xls';
$objWriter->save($filename);
if (!CONF_ACTIVE_ORDER) xMailTxtHTMLDATA(CONF_ORDERS_EMAIL, STRING_ORDER." #".$orderID." - ".CONF_SHOP_NAME, $html, CONF_GENERAL_EMAIL, CONF_SHOP_NAME, $filename);
else xMailTxtHTMLDATA(CONF_ORDERS_EMAIL, STRING_ORDER." #".$orderID." (".ADMIN_SEND_INACT_ORDER.") - ".CONF_SHOP_NAME, $html, CONF_GENERAL_EMAIL, CONF_SHOP_NAME, $filename);
unlink($filename);
# END XLS-to-email
5. в файле functions.php в функции xMailTxtHTMLDATA
5.1 вместо строки
function xMailTxtHTMLDATA($_Email, $_Subject, $_Text, $castmail = CONF_GENERAL_EMAIL, $castname = CONF_SHOP_NAME)
вставляем
# BEGIN XLS-to-email
# function xMailTxtHTMLDATA($_Email, $_Subject, $_Text, $castmail = CONF_GENERAL_EMAIL, $castname = CONF_SHOP_NAME)
function xMailTxtHTMLDATA($_Email, $_Subject, $_Text, $castmail = CONF_GENERAL_EMAIL, $castname = CONF_SHOP_NAME, $xlsname = "")
# END XLS-to-email
5.2 после строки
$mail->AltBody = ERROR_NO_TEXT_IN_MAILDATA;
вставляем
# BEGIN XLS-to-email
if ($xlsname) $mail->AddAttachment($xlsname);
# END XLS-to-email
6. в файле custord_new_orders.tpl.html
6.1 после строки
<td align="left" class="toph3"><a href='{$urlToSort}&sort=orderID&direction=ASC' title="{$smarty.const.ADMIN_ADMIN_MENUNEW11}" class="liv">{$smarty.const.STRING_ORDER_ID}</a></td>
вставляем
{* BEGIN XLS-to-email *}
<td align="center">Save</td>
{* END XLS-to-email *}
6.2 после строки
<td align="left" class="toph3"><a href='{$smarty.const.ADMIN_FILE}?dpt=custord&sub=new_orders&orders_detailed=yes&orderID={$orders[i].orderID}&urlToReturn={$urlToReturn}' title="{$smarty.const.ADMIN_ORDER_NAMEN2} # {$orders[i].orderID}">{$smarty.const.ADMIN_ORDER_NAMEN2} # {$orders[i].orderID}</a> </td>
вставляем
{* BEGIN XLS-to-email *}
<td align="center"><a href="{$smarty.const.ADMIN_FILE}?do=order2xls&orderID={$orders[i].orderID}">XLS</a></td>
{* END XLS-to-email *}
6.3 вместо строки
<td class="navigator" colspan="7">{$navigator}</td>
вставляем
{* BEGIN XLS-to-email *}
{* <td class="navigator" colspan="7">{$navigator}</td>*}
<td class="navigator" colspan="8">{$navigator}</td>
{* END XLS-to-email *}
PS. Думаю, PHPExcel желающие найдут Яндексом без особых проблем.