98 lines
4.3 KiB
PHP
Executable File
98 lines
4.3 KiB
PHP
Executable File
<?php
|
|
class OrderHistory extends OrderHistoryCore {
|
|
public function addWithemail($autodate = true, $templateVars = false) {
|
|
$lastOrderState = $this->getLastOrderState($this->id_order);
|
|
|
|
if (!$this->add($autodate))
|
|
return false;
|
|
|
|
$result = Db::getInstance()->getRow('
|
|
SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`
|
|
FROM `'._DB_PREFIX_.'order_history` oh
|
|
LEFT JOIN `'._DB_PREFIX_.'orders` o ON oh.`id_order` = o.`id_order`
|
|
LEFT JOIN `'._DB_PREFIX_.'customer` c ON o.`id_customer` = c.`id_customer`
|
|
LEFT JOIN `'._DB_PREFIX_.'order_state` os ON oh.`id_order_state` = os.`id_order_state`
|
|
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = o.`id_lang`)
|
|
WHERE oh.`id_order_history` = '.(int)($this->id).' AND os.`send_email` = 1');
|
|
|
|
if (isset($result['template']) AND Validate::isEmail($result['email']))
|
|
{
|
|
if($lastOrderState->id == 17 && $this->id_order_state == 4) {
|
|
$result['template'] .= '_complete';
|
|
}
|
|
|
|
$topic = $result['osname'];
|
|
$data = array('{lastname}' => $result['lastname'], '{firstname}' => $result['firstname'], '{id_order}' => (int)$this->id_order);
|
|
if ($templateVars)
|
|
$data = array_merge($data, $templateVars);
|
|
$order = new Order((int)$this->id_order);
|
|
$data['{total_paid}'] = Tools::displayPrice((float)$order->total_paid, new Currency((int)$order->id_currency), false);
|
|
$data['{order_name}'] = sprintf("#%06d", (int)$order->id);
|
|
|
|
// An additional email is sent the first time a virtual item is validated
|
|
if ($virtualProducts = $order->getVirtualProducts() AND (!$lastOrderState OR !$lastOrderState->logable) AND $newOrderState = new OrderState($this->id_order_state, Configuration::get('PS_LANG_DEFAULT')) AND $newOrderState->logable)
|
|
{
|
|
global $smarty;
|
|
$assign = array();
|
|
foreach ($virtualProducts AS $key => $virtualProduct)
|
|
{
|
|
$id_product_download = ProductDownload::getIdFromIdProduct($virtualProduct['product_id']);
|
|
$product_download = new ProductDownload($id_product_download);
|
|
$assign[$key]['name'] = $product_download->display_filename;
|
|
$dl_link = $product_download->getTextLink(false, $virtualProduct['download_hash'])
|
|
.'&id_order='.$order->id
|
|
.'&secure_key='.$order->secure_key;
|
|
$assign[$key]['link'] = $dl_link;
|
|
if ($virtualProduct['download_deadline'] != '0000-00-00 00:00:00')
|
|
$assign[$key]['deadline'] = Tools::displayDate($virtualProduct['download_deadline'], $order->id_lang);
|
|
if ($product_download->nb_downloadable != 0)
|
|
$assign[$key]['downloadable'] = $product_download->nb_downloadable;
|
|
}
|
|
$smarty->assign('virtualProducts', $assign);
|
|
$smarty->assign('id_order', $order->id);
|
|
$iso = Language::getIsoById((int)($order->id_lang));
|
|
$links = $smarty->fetch(_PS_MAIL_DIR_.$iso.'/download-product.tpl');
|
|
$tmpArray = array('{nbProducts}' => count($virtualProducts), '{virtualProducts}' => $links);
|
|
$data = array_merge ($data, $tmpArray);
|
|
Mail::Send((int)$order->id_lang, 'download_product', Mail::l('Virtual product to download', $order->id_lang), $data, $result['email'], $result['firstname'].' '.$result['lastname']);
|
|
}
|
|
|
|
if (Validate::isLoadedObject($order)) {
|
|
Mail::Send((int)$order->id_lang, $result['template'], $topic, $data, $result['email'], $result['firstname'].' '.$result['lastname']);
|
|
}
|
|
}
|
|
|
|
$params = array(
|
|
'order' => array(
|
|
'id' => $this->id_order
|
|
),
|
|
'newOrderState' => $this->id_order_state
|
|
);
|
|
Module::hookExec('afterChangeStatus', $params);
|
|
|
|
|
|
/*if($this->id_order_state == 2) {
|
|
Db::getInstance()->ExecuteS('
|
|
INSERT IGNORE INTO `'._DB_PREFIX_.'logistics_order`
|
|
(
|
|
SELECT d.`id_order`, d.`id_order_detail`, c.`id_sale`, d.`product_quantity`, GREATEST(d.`product_quantity_refunded`, d.`product_quantity_return`), 0, dl.`value`, 0
|
|
FROM `'._DB_PREFIX_.'order_detail` d
|
|
LEFT JOIN `'._DB_PREFIX_.'orders` o
|
|
ON d.`id_order` = o.`id_order`
|
|
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c
|
|
ON d.`product_id` = c.`id_product`
|
|
LEFT JOIN `'._DB_PREFIX_.'privatesale_delay_sale` ds
|
|
ON c.`id_sale` = ds.`id_sale`
|
|
LEFT JOIN `'._DB_PREFIX_.'privatesale_delay_lang` dl
|
|
ON ds.`id_delay` = dl.`id_delay`
|
|
AND ds.`id_lang` = dl.`id_lang`
|
|
WHERE d.`id_order` = '.(int) $this->id_order.'
|
|
AND dl.`id_lang` = o.`id_lang`
|
|
)
|
|
');
|
|
}*/
|
|
|
|
return true;
|
|
}
|
|
}
|