add mail sendind

This commit is contained in:
Marion Muszynski 2017-09-26 17:34:21 +02:00
parent 8fb28292b8
commit a7e422af97
4 changed files with 381 additions and 0 deletions

View File

@ -0,0 +1,56 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Message de {shop_name}</title>
</head>
<body>
<table style="font-family: tahoma,arial,sans-serif; font-size: 12px; color:#000000; width: 550px;">
<tr>
<td align="left">
<a href="{shop_url}" title="{shop_name}"><img alt="{shop_name}" src="{shop_logo}" style="border:none;" ></a>
</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="left">Bonjour <strong>{firstname} {lastname}</strong>,</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="left">
<b>Vous avez pass&eacute; commande r&eacute;cemment sur notre site B&eacute;b&eacute; Boutik. Nous vous informons que le/les produits de la marque {sale} pour votre commande n&#176;{id_order} vient d'être envoy&eacute; directement de chez notre fournisseur par le transporteur {carrier}.</b>
</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="left">
Voici votre num&eacute;ro de suivi : {tracking_number}
</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="left">
Vous pourrez consulter l'acheminnement de votre colis à l'adresse suivante : <a href="{followup}" style="color: #e26ea2;">{followup}</a>
</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="left">
A très vite sur B&eacute;b&eacute; Boutik !
</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="left">
Cordialement,
</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align="center" style="font-size: 12px; border-top: 1px solid #cccccc; padding-top: 5px;">
{shop_name} - <a href="{shop_url}" style="color: #e26ea2;">{shop_url}</a>
</td>
</tr>
</table>
</body>
</html>

View File

@ -0,0 +1,13 @@
Bonjour {firstname} {lastname}
Vous avez passé commande récemment sur notre site Bébé Boutik. Nous vous informons que le/les produits de la marque {sale} pour votre commande n°{id_order} vient d'être envoyé directement de chez notre fournisseur par le transporteur {carrier}.
Voici votre numéro de suivi : {tracking_number}
Vous pourrez consulter l'acheminnement de votre colis à l'adresse suivante : {followup}
A très vite sur Bébé Boutik !
Cordialement,
{shop_name} - {shop_url}

View File

@ -0,0 +1,272 @@
<?php
if(!defined('_PS_VERSION_')) {
exit;
}
include_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php');
require_once(PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php');
class AdminAntDropshippingtracking extends AdminTab
{
public function postProcess() {
if(Tools::isSubmit('submitOrderTracking') && Tools::getValue('id_sale')){
$id_sale = (int)Tools::getValue('id_sale');
$sale_names = array();
foreach(Db::getInstance()->ExecuteS('
SELECT c.`name`, c.`id_lang`
FROM `'._DB_PREFIX_.'privatesale` p
LEFT JOIN `'._DB_PREFIX_.'category_lang` c ON (c.`id_category` = p.`id_category`)
WHERE `id_sale` = '.(int)$id_sale.'
') as $key => $row) {
$sale_names[(int)$row['id_lang']] = (int)$row['name'];
}
$sale_products = array();
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT `id_product`
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `is_sale` = '.(int) $id_sale.'
') as $key => $row) {
$sale_products[(int)$row['id_product']] = (int)$row['id_product'];
}
if(isset($_FILES['csvfile']) && $_FILES['csvfile']['name'] != '') {
$f = fopen($_FILES['csvfile']['tmp_name'], 'r');
fgetcsv($f, 0, ';');
$i = 1;
$orders = array();
while($line = fgetcsv($f, 0, ';')) {
$i++;
$orders[(int) $line[0]] = array(
'id_order' => (int) $line[0],
'tracking_number' => trim($line[1]),
'carrier' => $line[2],
'link' => trim($line[3]),
);
}
if(!empty($orders)) {
foreach ($orders as $id_order => $o) {
$order = new Order((int)$id_order);
$order_details = array();
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT `id_order_detail`, `product_name`,`product_id`, `product_attribute_id`, `product_quantity` - GREATEST(`product_quantity_return`, `product_quantity_refunded`) AS `quantity`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $id_order.'
') as $key => $row) {
$order_details[(int)$row['id_order_detail']] = (int)$row;
}
$fully_sent = false;
$products_sent = array();
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, IF(
(d.`product_quantity` - IF(
d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
) AS `remain`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT OUTER JOIN `'._DB_PREFIX_.'lapostews` s
ON s.`id_order_detail` = d.`id_order_detail`
WHERE d.`id_order` = '.(int) $order->id.'
GROUP BY d.`id_order_detail`
') as $quantity_remain) {
if((int) $quantity_remain['remain'] == 0) {
$products_sent[] = (int) $quantity_remain['id_order_detail'];
}
}
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, IF(
(d.`product_quantity` - IF(
d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
) AS `remain`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT OUTER JOIN `'._DB_PREFIX_.'exapaqws` s
ON s.`id_order_detail` = d.`id_order_detail`
WHERE d.`id_order` = '.(int) $order->id.'
GROUP BY d.`id_order_detail`
') as $quantity_remain) {
if((int) $quantity_remain['remain'] == 0) {
$products_sent[] = (int) $quantity_remain['id_order_detail'];
}
}
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, IF(
(d.`product_quantity` - IF(
d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
) AS `remain`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT OUTER JOIN `'._DB_PREFIX_.'mondialrelay_parcel` s
ON s.`id_order_detail` = d.`id_order_detail`
WHERE d.`id_order` = '.(int) $order->id.'
GROUP BY d.`id_order_detail`
') as $quantity_remain) {
if((int) $quantity_remain['remain'] == 0) {
$products_sent[] = (int) $quantity_remain['id_order_detail'];
}
}
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, IF(
(d.`product_quantity` - IF(
d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded`
) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0
) AS `remain`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT OUTER JOIN `'._DB_PREFIX_.'philea_parcel` s
ON s.`id_order_detail` = d.`id_order_detail`
WHERE d.`id_order` = '.(int) $order->id.'
GROUP BY d.`id_order_detail`
') as $quantity_remain) {
if((int) $quantity_remain['remain'] == 0) {
$products_sent[] = (int) $quantity_remain['id_order_detail'];
}
}
$remaining = array();
$html_products_sent = '';
foreach($order_details as $id_order_detail => $d) {
if(!in_array($id_order_detail, $products_sent) && in_array($d['product_id'],$sale_products)) {
$remaining[] = (int)$id_order_detail;
} elseif(in_array((int)$d['product_id'],$sale_products)) {
$html_products_sent .= '<br />'."\r\n".$d['quantity'] . 'x' . ' ' . $p['product_name'];
}
}
if(count($remaining) == 0) {
$fully_sent = true;
} else {
$fully_sent = false;
}
$customer = new Customer((int) $order->id_customer);
$templateVars = array(
'{followup}' => $o['link'],
'{carrier}' => $o['carrier'],
'{tracking_number}' => $o['tracking_number'],
'{sale}' => $sale_names[(int)$order->id_lang],
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
'{id_order}' => (int) $order->id,
// '{product_list}' => !empty($html_products_sent)? $content_html.$html_products_sent: '',
// '{product_list_txt}' => !empty($html_products_sent)? $content_txt.strip_tags($html_products_sent): '',
);
$history = new OrderHistory();
$history->id_order = (int) $order->id;
$history->changeIdOrderState(($fully_sent? Configuration::get('PS_OS_SHIPPING'): 17), (int) $order->id);
$history->id_employee = 0;
$history->add();
$order->shipping_number = $o['tracking_number'];
$order->save();
global $_LANGMAIL;
$subject = 'Package in transit';
Mail::Send(
intval($order->id_lang),
'in_transit_dropshipping',
(
(is_array($_LANGMAIL) && key_exists($subject, $_LANGMAIL))
? $_LANGMAIL[$subject]
: $subject
),
$templateVars,
$customer->email,
$customer->firstname.' '.$customer->lastname
);
}
if(!isset($_COOKIE['logistics_sales'])){
setcookie('logistics_sales', $id_sale, 0, __PS_BASE_URI__);
} else {
$sales = explode('-', $_COOKIE['logistics_sales']);
if(!in_array($id_sale,$sales)){
$sales[] = $id_sale;
}
setcookie('logistics_sales', implode('-', $sales), 0, __PS_BASE_URI__);
}
}
}
}
}
public function display() {
global $cookie, $currentIndex;
$base_link = $currentIndex . '&token='.Tools::getAdminTokenLite('AdminAntDropshippingtracking');
$form = '';
$id_category_options = array();
foreach(Db::getInstance()->ExecuteS('
SELECT p.`id_sale`, c.`name`, c.`id_category`
FROM `'._DB_PREFIX_.'privatesale` p
LEFT JOIN `'._DB_PREFIX_.'category_lang` c ON (c.`id_category` = p.`id_category`)
LEFT JOIN `'._DB_PREFIX_.'privatesale_shipping_sale` s ON (s.`id_sale` = p.`id_sale`)
WHERE c.`id_lang` = '.$cookie->id_lang.'
AND s.id_shipping = 2
-- AND p.`date_start` > "2017-01-01 00:00:00"
ORDER BY p.`id_sale` DESC
LIMIT 1200
') as $row) {
$extrafields = Category::getSalesInfos(array((int) $row['id_category']));
$id_category_options[] = array(
'label' => (int) $row['id_sale'].' (#'.(int) $row['id_category'].') - '.$row['name'].(empty($extrafields[(int) $row['id_category']]['sales'][1])?'':' - '.$extrafields[(int) $row['id_category']]['sales'][1]) ,
'value' => (int) $row['id_sale']
);
}
$helperForm = new HelperFormBootstrap();
$helperForm->_select2 = true;
$form .= $helperForm->renderStyle();
$form .= '
<div class="row">
<div class="col-md-12">
<div class="panel">
<h2 class="heading-title"><span class="anticon anticon-cog"></span> '.$this->l('Import information dropshipping').'</h2>
<div class="panel-content">
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" enctype="multipart/form-data">
<div class="col-md-5 col-md-offset-4">';
$help = '<br>
<p class="help-block">'.$this->l('Format: id_order;tracking_number;carrier;tracking_link').'</p>
<p class="help-block">'.$this->l('The subsequent columns and the first line are ignored.').'</p>
';
$input = array(
'label' => $this->l('Sale: '),
'type' => 'select2',
'label-class' => 'control-label',
'select-class' => 'input-class',
'name' => 'id_sale',
'options' => $id_category_options,
);
$form .= '<div class="clearfix"></div>'.$helperForm->generateInput($input);
$input = array(
'type' => 'file',
'label' => $this->l('File:'),
'name' => 'csvfile',
'html' => $help
);
$form .= $helperForm->generateInput($input);
$form .= '
</div>
<div class="clearfix"></div>
<div class="ln_solid"></div>
<div class="form-group text-right">
<button type="submit" class="btn btn-primary" name="submitOrderTracking">'.$this->l('Importer').'</button>
</div>
</form>
</div>
</div>
</div>
</div>';
$form .= $helperForm->renderScript();
echo $form;
}
}

View File

@ -0,0 +1,40 @@
<?php
if (!defined('_PS_VERSION_'))
exit;
class Ant_Dropshippingtracking extends Module
{
public function __construct()
{
$this->name = 'ant_dropshippingtracking';
$this->tab = 'administration';
$this->author = 'Antadis';
$this->version = '1.0';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('Dropshipping tracking');
$this->description = $this->l('Allow to import information to track orders sent by dropshipping');
}
public function install()
{
if(!(parent::install())) {
return false;
}
return true;
}
public function uninstall() {
if(parent::uninstall() == false) {
return false;
}
return true;
}
}