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 ""; $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)); echo '

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

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

'.($currentState->id == 8?'':($currentState->id == 18?'':'')).' '.$currentState->name.'

'.$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').'

'.$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 "%so colissimo%" ')) { $socol = Db::getInstance()->getRow(' SELECT * FROM `'._DB_PREFIX_.'socolissimo_delivery_info` WHERE `id_cart` = '.(int) $cart->id.' '); if($socol) { $order_address = nl2br(preg_replace("/(\r\n){2,}/", "\r\n", implode("\r\n", array( $socol['cefirstname'].' '.$socol['cename'], $socol['cecompanyname'], $socol['prfirstname'].' '.$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) ); } }