* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7541 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ include_once('envoimoinscher.php'); class AdminEnvoiMoinsCher extends AdminTab { public $packaging = array('Pli' => 'Pli', 'Colis' => 'Colis', 'Encombrant' => 'Objet lourd', 'Palette' => 'Palette'); public function __construct() { parent::__construct(); } public function display() { global $cookie; $emc = new Envoimoinscher(); echo '

'.$emc->lang('List of orders to export').'

'; if (Tools::isSubmit('submitExport')) { $orderToExport = array(); $idsOrdersToExport = Tools::getValue('ordersBox'); if (!empty($idsOrdersToExport)) { foreach($idsOrdersToExport as $id) { $orderToExport[] = self::getOrderDetails((int)($id)); } echo '
'; self::inputMaker($orderToExport); echo '
'; } else echo '
nok '.$emc->lang('No order to export').'

Retour

'; } else { if (Configuration::get('EMC_ORDER_STATE') AND Configuration::get('EMC_CARRIER') AND Configuration::get('EMC_FIRST_NAME') AND Configuration::get('EMC_LAST_NAME') AND Configuration::get('EMC_ADDRESS') AND Configuration::get('EMC_ZIP_CODE') AND Configuration::get('EMC_CITY') AND Configuration::get('EMC_COUNTRY') AND Configuration::get('EMC_PHONE') AND Configuration::get('EMC_EMAIL') AND Configuration::get('EMC_LOGIN')) { echo '
'; $orders = self::getOrders(); self::displayOrders($orders); echo '

'; } else echo '

'.$emc->lang('Please configure this module in order').'

'; } echo '

' . $emc->lang('Change configuration') . '

'; } private function getOrders() { $id_order_state = (int)(Configuration::get('EMC_ORDER_STATE')); $id_carrier = (int)(Configuration::get('EMC_CARRIER')); $sql = ' SELECT o.id_order as id_order, o.`id_customer` as id_customer, CONCAT(c.`firstname`, \' \', c.`lastname`) AS `customer`, o.total_paid_real as total, o.total_shipping as shipping, o.date_add as date, o.id_currency as id_currency, o.id_lang as id_lang, SUM(od.product_weight * od.product_quantity) as weight FROM `'._DB_PREFIX_.'orders` o LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (o.`id_order` = od.`id_order`) LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = o.`id_customer`) LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = o.`id_order`) LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = oh.`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 (SELECT moh.`id_order_state` FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = o.`id_order` ORDER BY moh.date_add DESC LIMIT 1) = '.$id_order_state.' AND o.id_carrier = '.pSQL($id_carrier).' GROUP BY o.`id_order`, od.`id_order` ORDER BY o.`date_add` ASC'; return Db::getInstance()->ExecuteS($sql); } private function displayOrders($orders) { global $cookie; echo ''; if (!empty($orders)) { foreach($orders as $order) { $customer = new Customer((int)($order['id_customer'])); echo ''; } } else echo ''; echo '
'.$emc->lang('ID').' '.$emc->lang('Name').' '.$emc->lang('Total Cost').' '.$emc->lang('Total shipment').' '.$emc->lang('Date').' '.$emc->lang('Packaging').' '.$emc->lang('Nature of contents').' '.$emc->lang('Detail').'
'.(int)($order['id_order']).' '.htmlentities($customer->lastname, ENT_COMPAT, 'UTF-8').' '.htmlentities($customer->firstname, ENT_COMPAT, 'UTF-8').' '.Tools::displayPrice($order['total'], new Currency((int)($order['id_currency']))).' '.Tools::displayPrice($order['shipping'], new Currency((int)($order['id_currency']))).' '.Tools::displayDate($order['date'], (int)($order['id_lang'])).' '.envoimoinscher::selectNature(Configuration::get('EMC_CONTENT'),(int)($order['id_order'])).' '.$emc->lang('View').'
'.$emc->lang('No order to export').'
'; } private function getOrderDetails($id_order) { global $cookie; $confs = Configuration::getMultiple(array('EMC_LOGIN', 'PS_SHOP_NAME', 'EMC_GENDER', 'EMC_FIRST_NAME', 'EMC_LAST_NAME', 'EMC_ADDRESS', 'EMC_ZIP_CODE', 'EMC_CITY', 'EMC_COUNTRY', 'EMC_PHONE', 'EMC_EMAIL', 'EMC_EMAILS')); $orderDetails = array(); $order = new Order((int)($id_order)); $customer = new Customer((int)($order->id_customer)); $adresseDelivery = new Address((int)($order->id_address_delivery)); $genderTab = array(1 => 'M.', 2 => 'Mme', 9 => ''); $orderDetails['url_suivi'] = Tools::getProtocol().htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/envoimoinscher/tracking.php?token='.$customer->secure_key; $orderDetails['infoexterne'] = str_replace('.','_',str_replace('www.','',$_SERVER['HTTP_HOST'])).'_'.(int)($id_order); $orderDetails['packaging'] = Tools::getValue('packaging_'.(int)($id_order)); $orderDetails['type_objet'] = Tools::getValue('type_objet_'.(int)($id_order)); $orderDetails['envoi_emailsconf'] = (int)($confs['EMC_EMAILS']); //products infos $productsDetails = $order->getProductsDetail(); $tabDetails = array(); foreach($productsDetails as $details) { $features = self::getFeatures((int)($details['product_id'])); $tabDetailsProduct = array(); $tabDetailsProduct['id'] = (int)($details['product_id']); $tabDetailsProduct['nb'] = (int)($details['product_quantity']); $tabDetailsProduct['poids'] = (float)($details['product_weight']); $tabDetailsProduct['description'] = htmlspecialchars($details['product_name'], ENT_COMPAT, 'UTF-8'); foreach($features as $key => $value) $tabDetailsProduct[$key] = $value; $tabDetails[] = $tabDetailsProduct; } $orderDetails['products'] = $tabDetails; //sending infos $orderExpediteur['civilite'] = htmlspecialchars($genderTab[$confs['EMC_GENDER']], ENT_COMPAT, 'UTF-8'); $orderExpediteur['collecte_type'] = 'entreprise'; $orderExpediteur['societe'] = htmlspecialchars($confs['PS_SHOP_NAME'], ENT_COMPAT, 'UTF-8'); $orderExpediteur['nom'] = htmlspecialchars($confs['EMC_LAST_NAME'], ENT_COMPAT, 'UTF-8'); $orderExpediteur['prenom'] = htmlspecialchars($confs['EMC_FIRST_NAME'], ENT_COMPAT, 'UTF-8'); $orderExpediteur['adresse'] = htmlspecialchars($confs['EMC_ADDRESS'], ENT_COMPAT, 'UTF-8'); $orderExpediteur['codepostal'] = htmlspecialchars($confs['EMC_ZIP_CODE'], ENT_COMPAT, 'UTF-8'); $orderExpediteur['ville'] = htmlspecialchars($confs['EMC_CITY'], ENT_COMPAT, 'UTF-8'); $orderExpediteur['pz_id'] = htmlspecialchars($confs['EMC_COUNTRY'], ENT_COMPAT, 'UTF-8'); $orderExpediteur['tel'] = htmlspecialchars($confs['EMC_PHONE'], ENT_COMPAT, 'UTF-8'); $orderExpediteur['email'] = htmlspecialchars($confs['EMC_EMAIL'], ENT_COMPAT, 'UTF-8'); $orderDetails['expediteur'] = $orderExpediteur; //delivery infos $orderDelivery['civilite'] = $genderTab[(int)($customer->id_gender)]; if (isset($adresseDelivery->company)) $orderDelivery['collecte_type'] = 'particulier'; $orderDelivery['societe'] = htmlspecialchars($adresseDelivery->company, ENT_COMPAT, 'UTF-8'); $orderDelivery['prenom'] = htmlspecialchars($adresseDelivery->firstname, ENT_COMPAT, 'UTF-8'); $orderDelivery['nom'] = htmlspecialchars($adresseDelivery->lastname, ENT_COMPAT, 'UTF-8'); $orderDelivery['adresse'] = htmlspecialchars($adresseDelivery->address1, ENT_COMPAT, 'UTF-8'); $orderDelivery['codepostal'] = htmlspecialchars($adresseDelivery->postcode, ENT_COMPAT, 'UTF-8'); $orderDelivery['ville'] = htmlspecialchars($adresseDelivery->city, ENT_COMPAT, 'UTF-8'); $orderDelivery['pz_id'] = Country::getIsoById(Country::getIdByName((int)($cookie->id_lang),$adresseDelivery->country)); if (isset($adresseDelivery->phone)) $orderDelivery['tel'] = htmlspecialchars($adresseDelivery->phone, ENT_COMPAT, 'UTF-8'); else $orderDelivery['tel'] = htmlspecialchars($adresseDelivery->phone_mobile, ENT_COMPAT, 'UTF-8'); $orderDelivery['email'] = htmlspecialchars($customer->email, ENT_COMPAT, 'UTF-8'); $orderDetails['destinataire'] = $orderDelivery; //d($orderDetails); return $orderDetails; } private function getFeatures($id) { global $cookie; $featuresTab = array(); $confs = Configuration::getMultiple(array('EMC_WIDTH', 'EMC_HEIGHT', 'EMC_DEPTH')); $features = Product::getFeaturesStatic((int)$id); foreach($features as $feature) { switch ($feature['id_feature']) { case $confs['EMC_WIDTH'] : $featureValue = new FeatureValue((int)($feature['id_feature_value'])); $featuresTab['largeur'] = $featureValue->value[(int)($cookie->id_lang)]; break; case $confs['EMC_HEIGHT'] : $featureValue = new FeatureValue((int)($feature['id_feature_value'])); $featuresTab['hauteur'] = $featureValue->value[(int)($cookie->id_lang)]; break; case $confs['EMC_DEPTH'] : $featureValue = new FeatureValue((int)($feature['id_feature_value'])); $featuresTab['longueur'] = $featureValue->value[(int)($cookie->id_lang)]; break; } } return $featuresTab; } private function inputMaker($orderDetails) { $nbrOrder = count($orderDetails)-1; foreach($orderDetails as $details) { foreach($details as $detail => $values) { if ($detail == 'products') { if (count($values) > 1) { $weight = 0; foreach($values as $key => $features) { $weight += (float)($features['poids']*$features['nb']); } echo ''; } elseif ($values[0]['nb'] > 1) { echo ''; echo ''; } else { echo ''; echo ''; echo ''; echo ''; echo ''; } } elseif ($detail == 'packaging') echo ''; elseif ($detail == 'infoexterne') echo ''; elseif ($detail == 'url_suivi') echo ''; elseif ($detail == 'infoexterne') echo ''; elseif ($detail == 'envoi_emailsconf') echo ''; elseif ($detail == 'type_objet') echo ''; else { foreach($values as $key => $value) echo ''; } } $nbrOrder -=1 ; } } }