2016-07-08 17:51:48 +02:00
< ? 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' );
}
2016-10-14 18:30:05 +02:00
private $hooks = array (
'rightColumnSav' => array ( 'BO SAV right column' , 'Allow to add information in right column of SAV message thread' ),
);
2016-07-08 17:51:48 +02:00
public function install () {
2016-10-14 18:30:05 +02:00
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' );
2016-07-08 17:51:48 +02:00
}
public function hookLeftColumn ( $params ) {
global $cookie , $smarty , $cart ;
if (( $step = ( int ) Tools :: getValue ( 'step' )) && ( $step == 3 || $step == 4 )) {
2016-10-14 18:30:05 +02:00
$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' );
}
}
2016-07-08 17:51:48 +02:00
2016-10-14 18:30:05 +02:00
public function hookRightColumn ( $params ) {
return $this -> hookLeftColumn ( $params );
}
2016-07-08 17:51:48 +02:00
2016-10-14 18:30:05 +02:00
public function hookRightColumnSav ( $params ) {
2016-10-26 16:54:52 +02:00
global $cookie ;
2016-10-17 17:29:37 +02:00
if ( isset ( $params [ 'order' ])) {
$cart = new Cart (( int ) $params [ 'order' ] -> id_cart );
2016-10-26 16:54:52 +02:00
$data = $this -> getOrderDetail ( $cart ,( int ) $cart -> id_lang , $params [ 'order' ]);
2016-10-17 17:29:37 +02:00
echo " <style type='text/css'>
#blockordersummary {
width : 300 px ;
background : #fff;
padding - bottom : 5 px ;
margin - bottom : 20 px ;
- moz - box - shadow : 1 px 1 px 2 px 2 px #cccccc;
- webkit - box - shadow : 1 px 1 px 2 px 2 px #ccc;
- ms - box - shadow : 1 px 1 px 2 px 2 px #cccccc;
- o - box - shadow : 1 px 1 px 2 px 2 px #cccccc;
box - shadow : 1 px 1 px 2 px 2 px #ccc;
clear : both ;
}
#blockordersummary .content {
padding : 5 px ;
}
#blockordersummary .content div{
color : #1e1633;
margin : 0 px 5 px ;
font - size : 12 px ;
padding : 8 px 0 px 5 px ;
border - top : 1 px dashed #ccc;
line - height : 1.4 em ;
}
2016-10-26 16:54:52 +02:00
#blockordersummary .content div.order-info{
2016-10-17 17:29:37 +02:00
border - top : 1 px solid #ccc;
}
#blockordersummary h4{
display : block ;
font - size : 18 px ;
color : #796dc7;
font - weight : normal ;
margin : 0 px 5 px 2 px ;
padding : 12 px 0 px 10 px ;
border - bottom : 1 px solid #ccc;
}
#blockordersummary h5 {
color : #444d52;
font - family : georgia , times new roman , serif ;
margin - bottom : 10 px ;
font - weight : 600 ;
font - size : 13 px ;
}
#blockordersummary ul {
margin : 0 px 0 px 7 px ;
padding : 0 px ;
list - style : none ;
border - bottom : 1 px solid #999;
}
#blockordersummary li {
padding - bottom : 5 px ;
}
#blockordersummary p {
margin - bottom : 5 px ;
}
#blockordersummary p.carrier-info:after{
content : '' ;
display : block ;
clear : both ;
}
#blockordersummary span.carrier-name {
float : left ;
max - width : 130 px ;
}
#blockordersummary p.delivery-delay {
color : #e36ea2;
font - weight : 600 ;
}
#blockordersummary p.delivery-date strong{
font - size : 11 px ;
}
#blockordersummary .price {
float : right ;
}
#blockordersummary .price.price_total {
color : #e36ea2;
font - weight : bold ;
}
#blockordersummary .address {
color : #1e1633;
}
#blockordersummary .order_total {
color : #e36ea2;
padding : 15 px ;
font - size : 14 px ;
font - weight : bold ;
background : rgba ( 226 , 110 , 162 , 0.2 ) ;
}
</ style > " ;
2016-11-04 12:50:34 +01:00
$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' ),
8 => array ( 'anticon-blocked' , 'text-rose' ),
17 => array ( 'anticon-truck' , 'text-orange' ),
18 => array ( 'anticon-warning' , 'text-orange' ),
19 => array ( 'anticon-pause' , 'text-orange' ),
);
2016-10-24 14:27:50 +02:00
$currency = new Currency (( int )( Configuration :: get ( 'PS_CURRENCY_DEFAULT' )));
2016-10-26 16:54:52 +02:00
$currentState = OrderHistory :: getLastOrderState (( int ) $params [ 'order' ] -> id );
$tokenOrders = Tools :: getAdminToken ( 'AdminOrders' . ( int )( Tab :: getIdFromClassName ( 'AdminOrders' )) . ( int )( $cookie -> id_employee ));
2016-11-04 12:50:34 +01:00
$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 = array(38,40,45);// local
2016-11-04 12:54:57 +01:00
//$carrier_socol = array(45,47,48);// dev
$carrier_socol = array ( 87 , 88 , 89 ); // prod
2016-11-04 12:50:34 +01:00
echo ' < script type = " text/javascript " src = " http://maps.google.com/maps/api/js?sensor=false " ></ script >
< div id = " blockordersummary " >
2016-10-17 17:29:37 +02:00
< div class = " content " >
2016-10-26 16:54:52 +02:00
< 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 >
2016-11-04 12:50:34 +01:00
< 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 ' </ div >
2016-10-17 17:29:37 +02:00
< div class = " my-cart " >
2016-10-26 15:11:40 +02:00
< h5 > '.$this->l(' My Cart ').' </ h5 >
2016-10-17 17:29:37 +02:00
< ul > ' ;
foreach ( $cart -> getProducts () as $key => $product ) {
2016-10-25 12:03:06 +02:00
echo '<li>' . $product [ 'quantity' ] . ' x ' . mb_strimwidth ( $product [ 'name' ], 0 , 35 , " ... " ) . ' <span class="price">' . Tools :: displayPrice ( $product [ 'total_wt' ], $currency ) . '</span></li>' ;
2016-10-17 17:29:37 +02:00
}
echo ' </ ul >
2016-10-24 14:27:50 +02:00
< p > '.$this->l(' Products total ').' < span class = " price price_total " > '.Tools::displayPrice($cart->getOrderTotal(TRUE,1),$currency).' </ span ></ p > ' ;
2016-10-17 17:29:37 +02:00
if ( $cart -> getOrderTotal ( TRUE , 2 ) != 0 ){
2016-10-24 14:27:50 +02:00
echo '<p>' . $this -> l ( 'Discounts total' ) . ' <span class="price price_total">' . Tools :: displayPrice ( $cart -> getOrderTotal ( TRUE , 2 ), $currency ) . '</span></p>' ;
2016-10-17 17:29:37 +02:00
}
echo ' </ div >
< div >
< h5 > '.$this->l(' Shipping ').' </ h5 >
2016-10-24 14:27:50 +02:00
< 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 >
2016-10-17 17:29:37 +02:00
</ div >
< div >
< h5 > '.$this->l(' Delivery delays ').' </ h5 >
< p class = " delivery-delay " > '.$data[' delay_name '].' </ p > ' ;
if ( isset ( $data [ 'delivery_date' ])){
foreach ( $data [ 'delivery_date' ] as $k => $date ) {
if ( $k == 1 ) {
echo ' < p class = " delivery-date " >
2016-10-26 16:54:52 +02:00
'.$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 >
2016-10-17 17:29:37 +02:00
</ p > ' ;
} elseif ( $k == 5 ){
echo '<p class="delivery-date">' . $this -> l ( 'Livraison prévue avant le' ) . ' <strong>' . $this -> l ( '24/12' ) . '</strong></p>' ;
}
2016-10-14 18:30:05 +02:00
}
}
2016-10-17 17:29:37 +02:00
echo ' </ div >
< div >
2016-11-04 12:50:34 +01:00
< h5 > '.$this->l(' My shipping address ').' ' .
(
( $currentState -> id != 8 && $currentState -> id != 18 && in_array (( int ) $cart -> 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 ) $cart -> 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 >
2016-10-17 17:29:37 +02:00
< p class = " address " > '.$data[' order_address '].' </ p >
</ div >
< div >
< h5 > '.$this->l(' My payment ').' </ h5 >
2016-10-24 14:27:50 +02:00
< p class = " order_total " > '.$this->l(' Total to pay ').' < span class = " price price_total " > '.Tools::displayPrice($cart->getOrderTotal(TRUE),$currency).' </ span ></ p >
2016-10-17 17:29:37 +02:00
</ div >
2016-10-14 18:30:05 +02:00
</ div >
2016-11-04 12:50:34 +01:00
</ 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 ;
});
});
</ script > ' ;
2016-10-17 17:29:37 +02:00
}
2016-10-14 18:30:05 +02:00
}
2016-10-26 16:54:52 +02:00
public function getOrderDetail ( $cart , $id_lang , $order = null ){
2016-10-14 18:30:05 +02:00
if ( Db :: getInstance () -> getValue ( '
SELECT `id_carrier`
FROM `'._DB_PREFIX_.'carrier`
WHERE `id_carrier` = '.(int) $cart->id_carrier.'
2016-11-04 12:50:34 +01:00
AND `name` LIKE " %colissimo% "
2016-10-14 18:30:05 +02:00
' )) {
$socol = Db :: getInstance () -> getRow ( '
SELECT *
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
WHERE `id_cart` = '.(int) $cart->id.'
' );
2016-11-04 13:03:15 +01:00
if ( $order == null && ( int ) $cart -> id_carrier == 87 ) {
$DOM_front = true ;
} else {
$DOM_front = false ;
}
2016-11-04 13:05:25 +01:00
if ( $socol && ! $DOM_front ) {
2016-10-14 18:30:05 +02:00
$order_address = nl2br ( preg_replace ( " /( \r \n ) { 2,}/ " , " \r \n " , implode ( " \r \n " , array (
$socol [ 'cefirstname' ] . ' ' . $socol [ 'cename' ],
$socol [ 'cecompanyname' ],
2016-11-04 13:08:00 +01:00
$socol [ 'prname' ],
2016-10-14 18:30:05 +02:00
$socol [ 'prcompladress' ],
$socol [ 'pradress1' ],
$socol [ 'pradress2' ],
$socol [ 'pradress3' ],
$socol [ 'pradress4' ],
$socol [ 'przipcode' ] . ' ' . $socol [ 'prtown' ],
'FRANCE' ,
$socol [ 'cephonenumber' ],
! empty ( $socol [ 'cedoorcode1' ]) ? 'Code porte 1 : ' . $socol [ 'cedoorcode1' ] : '' ,
! empty ( $socol [ 'cedoorcode2' ]) ? 'Code porte 2 : ' . $socol [ 'cedoorcode2' ] : '' ,
$socol [ 'cedeliveryinformation' ],
))));
2016-07-08 17:51:48 +02:00
} else {
$order_address = nl2br ( AddressFormat :: generateAddress ( new Address (( int ) $cart -> id_address_delivery )));
}
2016-10-14 18:30:05 +02:00
} else {
$order_address = nl2br ( AddressFormat :: generateAddress ( new Address (( int ) $cart -> id_address_delivery )));
}
2016-07-08 17:51:48 +02:00
2016-10-14 18:30:05 +02:00
if ( $id_lang == 3 && ( int ) $cart -> id_carrier == 87 ) {
$carrier_name = " SEUR a domicilio " ;
} else {
$carrier_name = Db :: getInstance () -> getValue ( '
SELECT `name`
FROM `'._DB_PREFIX_.'carrier`
WHERE `id_carrier` = '.(int) $cart->id_carrier.'
' );
}
2016-07-08 17:51:48 +02:00
2016-10-14 18:30:05 +02:00
$products_keys = array ();
$products_delays = array ();
2016-07-08 17:51:48 +02:00
2016-10-14 18:30:05 +02:00
$products = $cart -> getProducts ();
$i = 0 ;
foreach ( $products as $product ) {
$products_keys [( int ) $product [ 'id_product' ]] = $i ;
$i ++ ;
}
2016-07-08 17:51:48 +02:00
2016-10-14 18:30:05 +02:00
// 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 );
2016-10-26 16:54:52 +02:00
if ( $order != null ) {
$date = new DateTime ( $order -> date_add );
} else {
$date = new DateTime ();
}
2016-10-14 18:30:05 +02:00
$delivery_date = SaleDelay :: getDeliveryDate ( $delays , null , $date , true );
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 = $row [ 'name' ];
break ;
2016-07-08 17:51:48 +02:00
}
}
2016-10-14 18:30:05 +02:00
return array (
'order_address' => $order_address ,
'carrier_name' => $carrier_name ,
'delay_name' => $delay_name ,
'delivery_date' => ( isset ( $delivery_date ) ? $delivery_date : null )
);
2016-07-08 17:51:48 +02:00
}
}