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['order'])) { $cart = new Cart((int)$params['order']->id_cart); $data = $this->getOrderDetail($cart,(int)$cart->id_lang,$params['order']); echo ""; $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'), ); $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 = array(38,40,45);// local //$carrier_socol = array(45,47,48);// dev $carrier_socol = array(87,88,89);// prod echo '

'.$this->l('Summary of my order' ).' (#'.(int)$params['order']->id.')

'.$this->l('Order Status').'

'.$currentState->name.'

'; if(count($shipping_numbers) > 0 || count($shipping_numbers2) > 0) { echo '
'.$this->l('Shipping numbers').'
'; if(count($shipping_numbers) > 0){ foreach ($shipping_numbers as $key => $number) { $date = new DateTime($number['date_add']); echo '

'. $number['shipping_number'] .' ajouté le '. $date->format('d/m/Y') .'

'; } } if(count($shipping_numbers2) > 0){ foreach ($shipping_numbers2 as $key => $number) { $date = new DateTime($number['date_add']); echo '

'. $number['shipping_number'] .' ajouté le '. $date->format('d/m/Y') .'

'; } } } echo '
'.$this->l('My Cart').'
    '; foreach ($cart->getProducts() as $key => $product) { echo '
  • '.$product['quantity'].' x '.mb_strimwidth($product['name'], 0, 35, "...").' '.Tools::displayPrice($product['total_wt'],$currency).'
  • '; } echo '

'.$this->l('Products total').' '.Tools::displayPrice($cart->getOrderTotal(TRUE,1),$currency).'

'; if ($cart->getOrderTotal(TRUE, 2) != 0){ echo '

'.$this->l('Discounts total').' '.Tools::displayPrice($cart->getOrderTotal(TRUE,2),$currency).'

'; } echo '
'.$this->l('Shipping').'

'.$data['carrier_name'].' '.Tools::displayPrice($cart->getOrderTotal(TRUE, 5),$currency).'

'.$this->l('Delivery delays').'

'.$data['delay_name'].'

'; if(isset($data['delivery_date'])){ foreach($data['delivery_date'] as $k => $date) { if($k == 1) { echo '

'.$this->l('Date de réception prévue entre le').' '.$date['date_start']->format('d/m/Y').' '.$this->l('et le').' '.$date['date_end']->format('d/m/Y').'

'; } elseif ($k == 5){ echo '

'.$this->l('Livraison prévue avant le').' '.$this->l('24/12').'

'; } } } echo '
'.$this->l('My shipping address').' '. ( ($currentState->id != 8 && $currentState->id != 18 && in_array((int)$cart->id_carrier, $carrier_socol)) ?'' :( ($currentState->id != 8 && $currentState->id != 18 && !in_array((int)$cart->id_carrier, $carrier_socol)) ?'' :'' ) ). '

'.$data['order_address'].'

'.$this->l('My payment').'

'.$this->l('Total to pay').' '.Tools::displayPrice($cart->getOrderTotal(TRUE),$currency).'

'; } } 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.' '); 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'], 'FRANCE', $socol['cephonenumber'], !empty($socol['cedoorcode1'])? 'Code porte 1 : '.$socol['cedoorcode1']: '', !empty($socol['cedoorcode2'])? 'Code porte 2 : '.$socol['cedoorcode2']: '', $socol['cedeliveryinformation'], )))); } else { $order_address = nl2br(AddressFormat::generateAddress(new Address((int) $cart->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"; } 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); 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; } } return array( 'order_address' => $order_address, 'carrier_name' => $carrier_name, 'delay_name' => $delay_name, 'delivery_date' => (isset($delivery_date)?$delivery_date:null) ); } }