bebeboutik/modules/blockordersummary/blockordersummary.php

452 lines
22 KiB
PHP

<?php
if (!defined('_PS_VERSION_'))
exit;
class BlockOrderSummary extends Module {
private $types = array();
public function __construct() {
$this->name = 'blockordersummary';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'Antadis';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('Order summary block');
$this->description = $this->l('Displays a summary of the current order');
}
private $hooks = array(
'rightColumnSav' => array('BO SAV right column', 'Allow to add information in right column of SAV message thread'),
);
public function install() {
foreach($this->hooks as $k => $v) {
if(count(Db::getInstance()->ExecuteS('
SELECT `id_hook`
FROM `'._DB_PREFIX_.'hook`
WHERE `name` = "'.$k.'"
LIMIT 1
')) == 0) {
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'hook`
VALUES (DEFAULT, "'.$k.'", "'.$v[0].'", "'.$v[1].'", 0, 0)
');
}
}
$install_success = parent::install();
if ($install_success) {
foreach($this->hooks as $k => $v) {
$install_success = $this->registerHook($k);
if (!$install_success) {
break;
}
}
}
return $install_success && $this->registerHook('leftColumn');
}
public function hookLeftColumn($params) {
global $cookie, $smarty, $cart;
if(($step = (int) Tools::getValue('step')) && ($step == 3 || $step == 4)) {
$data = $this->getOrderDetail($cart,$cookie->id_lang);
$smarty->assign(array(
'order_address' => $data['order_address'],
'carrier_name' => $data['carrier_name'],
'delay_name' => $data['delay_name'],
'delivery_date' => (isset($data['delivery_date'])?$data['delivery_date']:null)
));
return $this->display(__FILE__, 'blockordersummary.tpl');
}
}
public function hookRightColumn($params) {
return $this->hookLeftColumn($params);
}
public function hookRightColumnSav($params) {
global $cookie;
if(isset($params['customer'])) {
$orders = Order::getCustomerOrders($params['customer']->id);
}
if(!empty($orders)) {
if(!isset($params['order'])) {
$params['order'] = new Order((int)$orders[0]['id_order']);
}
$cart = new Cart((int)$params['order']->id_cart);
$data = $this->getOrderDetail($cart,(int)$cart->id_lang,$params['order']);
echo "<style type='text/css'>
#blockordersummary {
width: 300px;
background: #fff;
padding-bottom: 5px;
padding-top: 5px;
margin-bottom: 20px;
-moz-box-shadow: 1px 1px 2px 2px #cccccc;
-webkit-box-shadow: 1px 1px 2px 2px #ccc;
-ms-box-shadow: 1px 1px 2px 2px #cccccc;
-o-box-shadow: 1px 1px 2px 2px #cccccc;
box-shadow: 1px 1px 2px 2px #ccc;
clear: both;
}
#blockordersummary .content {
padding: 5px;
}
#blockordersummary .content div{
color: #1e1633;
margin: 0px 5px;
font-size: 12px;
padding: 8px 0px 5px;
border-top: 1px dashed #ccc;
line-height: 1.4em;
}
#blockordersummary .content div.order-info{
border-top: 1px solid #ccc;
}
#blockordersummary h4{
display: block;
font-size: 18px;
color: #796dc7;
font-weight: normal;
margin: 0px 5px 2px;
padding: 12px 0px 10px;
border-bottom: 1px solid #ccc;
}
#blockordersummary h5 {
color: #444d52;
font-family: georgia, times new roman, serif;
margin-bottom: 10px;
font-weight: 600;
font-size: 13px;
}
#blockordersummary ul {
margin: 0px 0px 7px;
padding: 0px;
list-style: none;
border-bottom: 1px solid #999;
}
#blockordersummary li {
padding-bottom: 5px;
}
#blockordersummary p {
margin-bottom: 5px;
}
#blockordersummary p.carrier-info:after{
content: '';
display: block;
clear: both;
}
#blockordersummary span.carrier-name {
float: left;
max-width: 130px;
}
#blockordersummary p.delivery-delay {
color: #e36ea2;
font-weight: 600;
}
#blockordersummary p.delivery-date strong{
font-size: 11px;
}
#blockordersummary .price {
float: right;
}
#blockordersummary .price.price_total {
color: #e36ea2;
font-weight: bold;
}
#blockordersummary .address {
color: #1e1633;
}
#blockordersummary .order_total {
color: #e36ea2;
padding: 15px;
font-size: 14px;
font-weight: bold;
background: rgba(226,110,162,0.2) ;
}
</style>";
$status = array(
2 => array('anticon-credit-card','text-green-light'),
4 => array('anticon-truck','text-purple-light'),
5 => array('anticon-home3','text-purple'),
6 => array('anticon-blocked','text-rose'),
7 => array('anticon-blocked','text-rose'),
8 => array('anticon-blocked','text-rose'),
17 => array('anticon-truck','text-orange'),
18 => array('anticon-warning','text-orange'),
19 => array('anticon-pause','text-orange'),
);
$currency = new Currency((int)(Configuration::get('PS_CURRENCY_DEFAULT')));
$currentState = OrderHistory::getLastOrderState((int)$params['order']->id);
$tokenOrders = Tools::getAdminToken('AdminOrders'.(int)(Tab::getIdFromClassName('AdminOrders')).(int)($cookie->id_employee));
$addressDelivery = new Address($params['order']->id_address_delivery, (int)($cookie->id_lang));
$addressInvoice = new Address($params['order']->id_address_invoice, (int)($cookie->id_lang));
$shipping_numbers = Db::getInstance()->ExecuteS('
SELECT DISTINCT lpws.`shipping_number`, lpws.`date_add`
FROM `'._DB_PREFIX_.'lapostews` lpws
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = lpws.`id_order_detail`)
WHERE `id_order` ='. (int)$params['order']->id
);
$shipping_numbers2 = Db::getInstance()->ExecuteS('
SELECT DISTINCT ppp.`shipping_number`, ppp.`date_add`
FROM `'._DB_PREFIX_.'philea_parcel` ppp
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`id_order_detail` = ppp.`id_order_detail`)
WHERE od.`id_order` ='. (int)$params['order']->id
);
$carrier_socol = explode(',',Configuration::get('ANT_CARRIERS_SOCOL'));
echo '<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<div id="blockordersummary">
<div style="margin:10px auto;" class="styled-select semi-square bg-purple-light">
<select name="summary_id_order" id="summary_id_order" class="">';
foreach ($orders as $key => $order) {
echo '<option value="'.$order['id_order'].'" '.((int)$order['id_order'] == (int)$params['order']->id ? 'selected="selected"' : '').'">Commande #'.$order['id_order'].' ('.date('d/m/Y',strtotime($order['date_add'])).')</option>';
}
echo '</select>
</div>
<div class="content">
<h4>'.$this->l('Summary of my order' ).' <a target="_blank" href="?tab=AdminOrders&id_order='.(int)$params['order']->id.'&vieworder&token='.$tokenOrders.'">(#'.(int)$params['order']->id.')</a></h4>
<div class="order-info">
<h5>'.$this->l('Order Status').'</h5>
<p class="'.$status[$currentState->id][1].'"><span class="anticon '.$status[$currentState->id][0].'"></span> <b>'.$currentState->name.'</b></p>';
if(count($shipping_numbers) > 0 || count($shipping_numbers2) > 0) {
echo '<h5>'.$this->l('Shipping numbers').'</h5>';
if(count($shipping_numbers) > 0){
foreach ($shipping_numbers as $key => $number) {
$date = new DateTime($number['date_add']);
echo '<p>'. $number['shipping_number'] .' ajouté le '. $date->format('d/m/Y') .'</p>';
}
}
if(count($shipping_numbers2) > 0){
foreach ($shipping_numbers2 as $key => $number) {
$date = new DateTime($number['date_add']);
echo '<p>'. $number['shipping_number'] .' ajouté le '. $date->format('d/m/Y') .'</p>';
}
}
}
echo '<h5>'.$this->l('Paiement').'</h5>
<p><span class="anticon anticon-credit-card"></span> <b>'.$params['order']->payment.'</b></p>
</div>
<div class="my-cart">
<h5>'.$this->l('My Cart').'</h5>
<ul>';
foreach ($cart->getProducts() as $key => $product) {
echo '<li>'.$product['quantity'].' x '.mb_strimwidth($product['name'], 0, 35, "...").' <span class="price">'.Tools::displayPrice($product['total_wt'],$currency).'</span></li>';
}
echo '</ul>
<p>'.$this->l('Products total').' <span class="price price_total">'.Tools::displayPrice($cart->getOrderTotal(TRUE,1),$currency).'</span></p>';
if ($cart->getOrderTotal(TRUE, 2) != 0){
echo '<p>'.$this->l('Discounts total').' <span class="price price_total">'.Tools::displayPrice($cart->getOrderTotal(TRUE,2),$currency).'</span></p>';
}
echo '</div>
<div>
<h5>'.$this->l('Shipping').'</h5>
<p class="carrier-info"><span class="carrier-name">'.$data['carrier_name'].'</span> <span class="price price_total">'.Tools::displayPrice($cart->getOrderTotal(TRUE, 5),$currency).'</span></p>
</div>
<div>
<h5>'.$this->l('Delivery delays').'</h5>';
if(isset($data['delivery_date'])){
foreach($data['delivery_date'] as $k => $date) {
echo '<p class="delivery-delay">'.$data['delay_name'][$k].'</p>';
if($k == 1) {
echo '<p class="delivery-date">
'.$this->l('Date de réception prévue entre le').' <strong>'.$date['date_start']->format('d/m/Y').'</strong> '.$this->l('et le').' <strong>'.$date['date_end']->format('d/m/Y').'</strong>
</p>';
} elseif ($k == 5){
echo '<p class="delivery-date">'.$this->l('Livraison prévue avant le').' <strong>'.$this->l('24/12').'</strong></p>';
} elseif ($k == 8){
echo '<p class="delivery-date">'.$this->l('Envoi en 48h').'</p>';
} elseif ($k == 9){
echo '<p class="delivery-date">'.$this->l('Delai indiqué sur la fiche produit').'</p>';
}
}
}
echo '</div>
<div>
<h5>'.$this->l('My shipping address').' '.
(
($currentState->id != 8 && $currentState->id != 18 && in_array((int)$params['order']->id_carrier, $carrier_socol))
?'<a id="modif_address" data-url="scaddressedit.php?id_cart='.(int)$params['order']->id_cart.'"><span class="anticon anticon-pencil" style="font-size: 16px; vertical-align: baseline;cursor:pointer;"></span></a>'
:(
($currentState->id != 8 && $currentState->id != 18 && !in_array((int)$params['order']->id_carrier, $carrier_socol))
?'<a href="?tab=AdminAddresses&id_address='.$addressDelivery->id.'&addaddress&realedit=1&id_order='.$params['order']->id.($addressDelivery->id == $addressInvoice->id ? '&address_type=1' : '').'&token='.Tools::getAdminToken('AdminAddresses'.(int)(Tab::getIdFromClassName('AdminAddresses')).(int)($cookie->id_employee)).'&back='.urlencode($_SERVER['REQUEST_URI']).'"><span class="anticon anticon-pencil" style="font-size: 16px; vertical-align: baseline;cursor:pointer;"></span></a>'
:''
)
).
'</h5>
<p class="address">'.$data['order_address'].'</p>
</div>
<div>
<h5>'.$this->l('My payment').'</h5>
<p class="order_total">'.$this->l('Total to pay').' <span class="price price_total">'.Tools::displayPrice($cart->getOrderTotal(TRUE),$currency).'</span></p>
</div>
</div>
</div>
<script>
$(document).ready(function () {
$("#modif_address").click(function(){
url = $(this).data("url");
var p = window.open(url, "Modification SoColissimo", "width=720, height=360, resizable=1, scrollbars=1");
return false;
});
$(\'#summary_id_order\').change(function() {
$.ajax({
url: \''._MODULE_DIR_.'blockordersummary/ajax.php'.'\',
type: \'GET\',
data: \'id_order=\' + $(this).val() + \'&tokenOrder='.$tokenOrders.'&tokenAddress='.Tools::getAdminToken('AdminAddresses'.(int)(Tab::getIdFromClassName('AdminAddresses')).(int)($cookie->id_employee)).'\',
success: function(html) {
$(\'#blockordersummary .content\').empty();
$(\'#blockordersummary .content\').html(html);
},
error: function(xhr) {
console.log(JSON.parse(xhr.responseText));
}
});
});
});
</script>';
}
}
public function getOrderDetail($cart,$id_lang, $order = null){
if(Db::getInstance()->getValue('
SELECT `id_carrier`
FROM `'._DB_PREFIX_.'carrier`
WHERE `id_carrier` = '.(int) $cart->id_carrier.'
AND `name` LIKE "%colissimo%"
')) {
$socol = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
WHERE `id_cart` = '.(int) $cart->id.'
AND `cecountry` IN ("FR","BE","ES")
AND (`pradress1`!= "" OR `pradress2`!= "" OR `pradress3`!= "" OR `pradress4`!= "")
');
if($order == null && (int) $cart->id_carrier == 87) {
$DOM_front = true;
} else {
$DOM_front = false;
}
if($socol && !$DOM_front) {
$order_address = nl2br(preg_replace("/(\r\n){2,}/", "\r\n", implode("\r\n", array(
$socol['cefirstname'].' '.$socol['cename'],
$socol['cecompanyname'],
$socol['prname'],
$socol['prcompladress'],
$socol['pradress1'],
$socol['pradress2'],
$socol['pradress3'],
$socol['pradress4'],
$socol['przipcode'].' '.$socol['prtown'],
$socol['cecountry'],
$socol['cephonenumber'],
!empty($socol['cedoorcode1'])? 'Code porte 1 : '.$socol['cedoorcode1']: '',
!empty($socol['cedoorcode2'])? 'Code porte 2 : '.$socol['cedoorcode2']: '',
$socol['cedeliveryinformation'],
))));
} else {
if($order) {
$order_address = nl2br(AddressFormat::generateAddress(new Address((int) $order->id_address_delivery)));
} else {
$order_address = nl2br(AddressFormat::generateAddress(new Address((int) $cart->id_address_delivery)));
}
}
} elseif(Db::getInstance()->getValue('
SELECT COUNT(*)
FROM `'._DB_PREFIX_.'mr_method`
WHERE `id_carrier` = '.(int) $cart->id_carrier.'
')) {
$mr = Db::getInstance()->getRow('
SELECT mr_s.*
FROM `' . _DB_PREFIX_ . 'mr_selected` mr_s
WHERE `id_cart` = ' . (int) $cart->id . '
');
if($mr) {
$order_address = nl2br(preg_replace("/(\r\n){2,}/", "\r\n", implode("\r\n", array(
$mr['MR_Selected_LgAdr1'],
$mr['MR_Selected_LgAdr2'],
$mr['MR_Selected_LgAdr3'] . ' ' . $mr['MR_Selected_LgAdr4'],
$mr['MR_Selected_CP'] . ' ' . $mr['MR_Selected_Ville'],
'FRANCE',
))));
} else {
if($order) {
$order_address = nl2br(AddressFormat::generateAddress(new Address((int) $order->id_address_delivery)));
} else {
$order_address = nl2br(AddressFormat::generateAddress(new Address((int) $cart->id_address_delivery)));
}
}
} else {
if($order) {
$order_address = nl2br(AddressFormat::generateAddress(new Address((int) $order->id_address_delivery)));
} else {
$order_address = nl2br(AddressFormat::generateAddress(new Address((int) $cart->id_address_delivery)));
}
}
if ($id_lang == 3 && (int)$cart->id_carrier == 87) {
$carrier_name = "SEUR a domicilio";
} elseif ($id_lang == 3 && ((int)$cart->id_carrier == 88 || (int)$cart->id_carrier == 89)) {
$carrier_name = "SEUR puntos de entrega";
} else {
$carrier_name = Db::getInstance()->getValue('
SELECT `name`
FROM `'._DB_PREFIX_.'carrier`
WHERE `id_carrier` = '.(int) $cart->id_carrier.'
');
}
$products_keys = array();
$products_delays = array();
$products = $cart->getProducts();
$i = 0;
foreach($products as $product) {
$products_keys[(int) $product['id_product']] = $i;
$i++;
}
// assign delay to Products
if (Module::isInstalled('privatesales_delay')) {
if (!class_exists('SaleDelay')) {
require_once _PS_ROOT_DIR_.'/modules/privatesales_delay/saledelay.php';
}
$delay_products = SaleDelay::associateDelay($products);
$delays = array_keys($delay_products);
if ($order!=null) {
$date = new DateTime($order->date_add);
} else {
$date = new DateTime();
}
$delivery_date = SaleDelay::getDeliveryDate($delays, null, $date, true);
$delay_name = array();
foreach($delays as $delay) {
$row = Db::getInstance()->getRow('
SELECT l.`name`
FROM `'._DB_PREFIX_.'privatesale_delay_lang` l
WHERE l.`id_lang` = '.(int) $id_lang.'
AND l.`id_delay`='.(int)$delay.'
');
$delay_name[(int)$delay] = $row['name'];
}
}
return array(
'order_address' => $order_address,
'carrier_name' => $carrier_name,
'delay_name' => $delay_name,
'delivery_date' => (isset($delivery_date)?$delivery_date:null)
);
}
}