chr(2).'m'.' 1911S2611800050P080P040{SHIPPING_NUMBER_C25I} 131110011200180{SHIPPING_NUMBER} 1X1100009400050b0480015000010001 1X1100005500050b0480035000010001 1X1100004100050b0510009000010001 1X1100002940050b0510009000010001 1X1100003450585b0200011000010001 1X1100008370050l04800001 1X1100004500050l05100001 1X1100003370050l05100001 1X1100004050585l02000001 1X1100004100210l00010090 1X1100004100350l00010090 1X1100002940210l00010090 1X1100002940350l00010090 1X1100009400051P001000110870525 1X1100009400525P001000110870051 1911S2410500065P010P010{EXP_COMPANY} 1911S2310200065P008P008{EXP_ADDR1} 1911S2309900065P008P008{EXP_ADDR2} 1911S2309600065P008P008{EXP_POSTCODE} {EXP_CITY} 1911S2408550065P010P010Destinataire 1911S2407940065P010P010{DEST_ADDR1} 1911S2307640065P006P006{DEST_ADDR2} 1911S2307370065P006P006{DEST_ADDR3} 1911S2307100065P006P006{DEST_ADDR4} 1911S2306830065P006P006{DEST_ADDR5} 1911S2406440065P010P010{DEST_POSTCODE} 1911S2306440180P010P010{DEST_CITY} 1911S2306060065P010P010{DEST_PHONE} 1911S2305700065P010P010{DEST_OTHER} 1911S2410100570P025P014{SHIPPING_1} / 1911S2410180700P020P012{SHIPPING_2} 1911S2409200570P025P014AG {SHIPPING_3} 1911S2408400570P020P012N {SHIPPING_4} - A5 1911S2408400710P020P012{SHIPPING_5} A2 1911S2407600570P020P012T {SHIPPING_6} 1911S2406700570P025P014{SHIPPING_7} 1911S2406750850P020P0121/1 1911S2405700570P025P014{SHIPPING_8} 1911S2404650065P007P006N'.chr(248).' exp'.chr(130).'dition 1911S2404650220P007P006Date d\'envoi 1911S2404650360P007P006Agence de collecte 1911S2304220080P007P007{EXPEDITION_NUMBER} 1911S2304220220P007P007{DATE} 1911S2304220420P007P007{AGENCY_CODE} 1911S2404180595P009P009A Encaisser 1911S2403630661P010P0100 '.chr(255).' 1Y0000003240820MONDIALR 1911S2403500080P007P006Poids (kg) 1911S2403500225P007P006Volume (L) 1911S2403500410P007P006N'.chr(248).' Colis 1911S2303060085P007P007{WEIGHT} 1911S2303060265P007P007{VOLUME} 1911S2303060430P007P0071/1 1911S2302400050P007P007{INSTRUCTIONS} '.chr(2).'n ', 'EN' => chr(2).'m'.' 1911S2611800050P080P040{SHIPPING_NUMBER_C25I} 131110011200180{SHIPPING_NUMBER} 1X1100009400050b0480015000010001 1X1100005500050b0480035000010001 1X1100004100050b0510009000010001 1X1100002940050b0510009000010001 1X1100003450585b0200011000010001 1X1100008370050l04800001 1X1100004500050l05100001 1X1100003370050l05100001 1X1100004050585l02000001 1X1100004100210l00010090 1X1100004100350l00010090 1X1100002940210l00010090 1X1100002940350l00010090 1X1100009400051P001000110870525 1X1100009400525P001000110870051 1911S2410500065P010P010{EXP_COMPANY} 1911S2310200065P008P008{EXP_ADDR1} 1911S2309900065P008P008{EXP_ADDR2} 1911S2309600065P008P008{EXP_POSTCODE} {EXP_CITY} 1911S2408550065P010P010Consignee 1911S2407940065P010P010{DEST_ADDR1} 1911S2307640065P006P006{DEST_ADDR2} 1911S2307370065P006P006{DEST_ADDR3} 1911S2307100065P006P006{DEST_ADDR4} 1911S2306830065P006P006{DEST_ADDR5} 1911S2406440065P010P010{DEST_POSTCODE} 1911S2306440180P010P010{DEST_CITY} 1911S2306060065P010P010{DEST_PHONE} 1911S2305700065P010P010{DEST_OTHER} 1911S2410100570P025P014{SHIPPING_1} / 1911S2410180700P020P012{SHIPPING_2} 1911S2409200570P025P014AG {SHIPPING_3} 1911S2408400570P020P012N {SHIPPING_4} - A5 1911S2408400710P020P012{SHIPPING_5} A2 1911S2407600570P020P012T {SHIPPING_6} 1911S2406700570P025P014{SHIPPING_7} 1911S2406750850P020P0121/1 1911S2405700570P025P014{SHIPPING_8} 1911S2404650065P007P006No. Shipment 1911S2404650220P007P006Sending Date 1911S2404650360P007P006Connection Agency 1911S2304220080P007P007{EXPEDITION_NUMBER} 1911S2304220220P007P007{DATE} 1911S2304220420P007P007{AGENCY_CODE} 1911S2404180595P009P009C.O.D. 1911S2403630661P010P0100 '.chr(255).' 1Y0000003240820MONDIALR 1911S2403500080P007P006Weight (kg) 1911S2403500225P007P006Volume (L) 1911S2403500410P007P006No. Parcel 1911S2303060085P007P007{WEIGHT} 1911S2303060265P007P007{VOLUME} 1911S2303060430P007P0071/1 1911S2302400050P007P007{INSTRUCTIONS} '.chr(2).'n ', 'ES' => chr(2).'m'.' 1911S2611800050P080P040{SHIPPING_NUMBER_C25I} 131110011200180{SHIPPING_NUMBER} 1X1100009400050b0480015000010001 1X1100005500050b0480035000010001 1X1100004100050b0510009000010001 1X1100002940050b0510009000010001 1X1100003450585b0200011000010001 1X1100008370050l04800001 1X1100004500050l05100001 1X1100003370050l05100001 1X1100004050585l02000001 1X1100004100210l00010090 1X1100004100350l00010090 1X1100002940210l00010090 1X1100002940350l00010090 1X1100009400051P001000110870525 1X1100009400525P001000110870051 1911S2410500065P010P010{EXP_COMPANY} 1911S2310200065P008P008{EXP_ADDR1} 1911S2309900065P008P008{EXP_ADDR2} 1911S2309600065P008P008{EXP_POSTCODE} {EXP_CITY} 1911S2408550065P010P010Destinario 1911S2407940065P010P010{DEST_ADDR1} 1911S2307640065P006P006{DEST_ADDR2} 1911S2307370065P006P006{DEST_ADDR3} 1911S2307100065P006P006{DEST_ADDR4} 1911S2306830065P006P006{DEST_ADDR5} 1911S2406440065P010P010{DEST_POSTCODE} 1911S2306440180P010P010{DEST_CITY} 1911S2306060065P010P010{DEST_PHONE} 1911S2305700065P010P010{DEST_OTHER} 1911S2410100570P025P014{SHIPPING_1} / 1911S2410180700P020P012{SHIPPING_2} 1911S2409200570P025P014AG {SHIPPING_3} 1911S2408400570P020P012N {SHIPPING_4} - A5 1911S2408400710P020P012{SHIPPING_5} A2 1911S2407600570P020P012T {SHIPPING_6} 1911S2406700570P025P014{SHIPPING_7} 1911S2406750850P020P0121/1 1911S2405700570P025P014{SHIPPING_8} 1911S2404650065P007P006N'.chr(248).' d\'exp'.chr(130).'dicion 1911S2404650220P007P006Fetcha de envio 1911S2404650360P007P006Agencia de Cobros 1911S2304220080P007P007{EXPEDITION_NUMBER} 1911S2304220220P007P007{DATE} 1911S2304220420P007P007{AGENCY_CODE} 1911S2404180595P009P009A Cobrar 1911S2403630661P010P0100 '.chr(255).' 1Y0000003240820MONDIALR 1911S2403500080P007P006Peso (kg) 1911S2403500225P007P006Volumen (L) 1911S2403500410P007P006N'.chr(248).' Paquete 1911S2303060085P007P007{WEIGHT} 1911S2303060265P007P007{VOLUME} 1911S2303060430P007P0071/1 1911S2302400050P007P007{INSTRUCTIONS} '.chr(2).'n ', ); class MondialrelayCarrier { public $displayName = 'Mondial Relay'; public function checkavailability() { return TRUE; } public function __toString() { return $this->displayName; } private function stripaccents($str) { return preg_replace( '~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);~i', '$1', htmlentities($str, ENT_QUOTES, 'UTF-8') ); } public function renderLabel($order, $weight, $shipping_data) { global $cookie, $mondialrelay_formats; $agencies = array( '0637' => 'BRIVE', '0606' => 'BORDEAUX', '0655' => 'CAEN', '0676' => 'CLERMONT-F', '0221' => 'CHAMBERY', '0603' => 'AJACCIO', '0677' => 'DIJON', '0662' => 'HEM', '0688' => 'ST OUEN', '0254' => 'LIEUSAINT', '0300' => 'LILLE', '0715' => 'LYON', '0648' => 'MARSEILLE', '0717' => 'METZ', '0718' => 'MONTPELLIE', '0719' => 'NANTES', '0301' => 'NICE', '0720' => 'MER', '0511' => 'REIMS', '0722' => 'RENNES', '0729' => 'ROUEN', '0737' => 'STRASBOURG', '0743' => 'TOULOUSE', '0749' => 'ORLEANS', '0930' => 'MONTREUIL', '0265' => 'VALENCE', '0975' => 'DOM TOM', '3010' => 'PORTUGAL', '3210' => 'ASM PT', '4010' => 'SPAIN', '4210' => 'ASM ES', '5010' => 'BELGIUM', '5199' => 'MONTREUIL', '5210' => 'BELGIQUE', '5310' => 'BPOST BE', '6610' => 'HERMES DE', '6620' => 'HERMES IT', '6630' => 'HERMES AT', '6640' => 'HERMES UK', '7210' => 'TNT NL', '8210' => 'DINTEC LU', ); $exp_company = Configuration::get('MONDIALRELAY_EXP_COMPANY'); $exp_address1 = Configuration::get('MONDIALRELAY_EXP_ADDR1'); $exp_address2 = Configuration::get('MONDIALRELAY_EXP_ADDR2'); $exp_postal = Configuration::get('MONDIALRELAY_EXP_POSTALCODE'); $exp_city = Configuration::get('MONDIALRELAY_EXP_CITY'); $exp_country = Configuration::get('MONDIALRELAY_EXP_COUNTRY'); $delivery_address = new Address((int) $order->id_address_delivery); if(!Validate::isLoadedObject($delivery_address)) { return FALSE; } $delivery_infos = Db::getInstance()->getRow(' SELECT s.*, m.`dlv_mode` FROM `'._DB_PREFIX_.'mr_selected` s LEFT JOIN `'._DB_PREFIX_.'mr_method` m ON s.`id_method` = m.`id_mr_method` WHERE s.`id_order` = '.(int) $order->id.' '); // Hack 5 numbers relay num if (isset($delivery_infos['MR_Selected_Num']) && $delivery_infos['MR_Selected_Num']) $delivery_infos['MR_Selected_Num'] = substr($delivery_infos['MR_Selected_Num'], -5); if(!$delivery_infos || in_array($delivery_infos['dlv_mode'], array('LDS', 'LD1', 'HOM'))) { $mode = $delivery_infos? $delivery_infos['dlv_mode']: 'LD1'; $shipping = array( $delivery_address->firstname.' '.$delivery_address->lastname, $delivery_address->company, $delivery_address->address1, $delivery_address->address2, $delivery_address->postcode, $delivery_address->city, '', empty($delivery_address->phone)? $delivery_address->phone_mobile: $delivery_address->phone, trim(str_replace('|', ' ', $delivery_address->other)), ); $dest_country = $delivery_address->id_country; } else { $mr_relais = Db::getInstance()->getRow(' SELECT * FROM `'._DB_PREFIX_.'mondialrelay_relais` WHERE 1 AND `direction` = "'.pSQL($delivery_infos['MR_Selected_Num']).'" AND `prpay` = "'.pSQL($delivery_infos['MR_Selected_Pays']).'" '); $mode = $delivery_infos['dlv_mode']; if($mode == '24R') { if($mr_relais['narel'] == 'F') { $mode = '24X'; } elseif($mr_relais['narel'] == 'E') { $mode = '24L'; } else { $mode = '24R'; } } $shipping = array( $delivery_address->firstname.' '.$delivery_address->lastname, $mr_relais['colnom'], $mr_relais['colbat'], str_replace(' AVENUE D', ' AV. D', str_replace(' GENERAL LECLERC', ' GAL LECLERC', $mr_relais['colrue'])), $mr_relais['coldit'], $mr_relais['codpos'], $mr_relais['libbp'], empty($delivery_address->phone_mobile)? $delivery_address->phone: $delivery_address->phone_mobile, '', ); $dest_country = (int) Db::getInstance()->getValue(' SELECT `id_country` FROM `'._DB_PREFIX_.'country` WHERE `iso_code` = "'.pSQL($delivery_infos['MR_Selected_Pays']).'" '); } if(mb_strlen($shipping[2]) > 22 && $shipping[3] == '') { $shipping[3] = mb_substr($shipping[2], 22, 22); $shipping[2] = mb_substr($shipping[2], 0, 22); } $format = str_replace( array( '{SHIPPING_NUMBER_C25I}', '{SHIPPING_NUMBER}', '{EXP_COMPANY}', '{EXP_ADDR1}', '{EXP_ADDR2}', '{EXP_POSTCODE}', '{EXP_CITY}', '{DEST_ADDR1}', '{DEST_ADDR2}', '{DEST_ADDR3}', '{DEST_ADDR4}', '{DEST_ADDR5}', '{DEST_POSTCODE}', '{DEST_CITY}', '{DEST_PHONE}', '{DEST_OTHER}', '{SHIPPING_1}', '{SHIPPING_2}', '{SHIPPING_3}', '{SHIPPING_4}', '{SHIPPING_5}', '{SHIPPING_6}', '{SHIPPING_7}', '{SHIPPING_8}', '{EXPEDITION_NUMBER}', '{DATE}', '{AGENCY_CODE}', '{WEIGHT}', '{VOLUME}', '{INSTRUCTIONS}', ), array( $shipping_data['shipping_number_c25i'], $shipping_data['shipping_number_fmt'], $exp_company, $exp_address1, $exp_address2, $exp_postal, $exp_city, $shipping[0], $shipping[1], $shipping[2], $shipping[3], $shipping[4], $shipping[5], $shipping[6], $shipping[7], $shipping[8], $shipping_data['plantri']['cppay'], $shipping_data['plantri']['nogroup'], $shipping_data['plantri']['modexp'], $shipping_data['plantri']['pretri'], // N ... $shipping_data['plantri']['navette'], $shipping_data['plantri']['direction'], // T ... $shipping_data['mode'], $agencies[$shipping_data['plantri']['modexp']], $shipping_data['expedition_number'], date('d/m/Y'), Db::getInstance()->getValue(' SELECT `modexp` FROM `'._DB_PREFIX_.'mondialrelay_tri` WHERE `cppay` = "'.pSQL(Db::getInstance()->getValue(' SELECT `iso_code` FROM `'._DB_PREFIX_.'country` WHERE `id_country` = '.(int) $exp_country.' ')).'" AND `destex` = "'.pSQL($exp_postal).'" '), number_format((float) $shipping_data['weight'], 2, ',', ''), 'NC', '', ), $mondialrelay_formats[$dest_country == 6? 'ES': (in_array($dest_country, array(3, 8, 12))? 'FR': 'EN')] ); return $format; } public function getShippingNumber($id_order) { Db::getInstance()->Execute('SET AUTOCOMMIT = 0'); Db::getInstance()->Execute('START TRANSACTION'); $res = Db::getInstance()->ExecuteS(' SELECT `value` FROM `'._DB_PREFIX_.'logistics_shipping` WHERE `carrier` = "MONDIALRELAY" FOR UPDATE '); $sequence = (int) $res[0]['value'] + 1; // LOOP SHIPPING SEQUENCE if ($sequence < Configuration::get('MONDIALRELAY_SHIPPINGLOW') || $sequence > Configuration::get('MONDIALRELAY_SHIPPINGHIGH')) $sequence = Configuration::get('MONDIALRELAY_SHIPPINGLOW'); // CHECK UNICITY $last_update = Db::getInstance()->getValue('SELECT DATE_ADD(`date_upd`, INTERVAL 1 YEAR) FROM `' . _DB_PREFIX_ . 'mondialrelay_expedition_numbers` WHERE `sequence` = ' . (int) $sequence); if ($last_update && $last_update > date('Y-m-d H:i:s')){ $content = 'Le numéro d\'expédition ' . $sequence . ' a été affecté il y a moins d\'un an.' . "\n" . 'Impossible d\'affecter un nouveau numéro d\'expédition'; mail('marion@antadis.com', '[BBB MONDIAL RELAY] Numéro d\'expédition', $content, 'Content-Type: text/plain; charset="utf-8"'."\r\n".'From: commande@bebeboutik.com'."\r\n".'Reply-To: marion@antadis.com'."\r\n".'Return-Path: marion@antadis.com'."\r\n"); return false; } Db::getInstance()->execute(' INSERT INTO ' . _DB_PREFIX_ . 'mondialrelay_expedition_numbers (`sequence`, `date_upd`) VALUES (' . (int) $sequence . ', "' . pSQL(date('Y-m-d H:i:s')) . '") ON DUPLICATE KEY UPDATE date_upd="' . pSQL(date('Y-m-d H:i:s')) . '"; '); Db::getInstance()->ExecuteS(' UPDATE `'._DB_PREFIX_.'logistics_shipping` SET `value` = "'.(int) $sequence.'" WHERE `carrier` = "MONDIALRELAY" '); Db::getInstance()->Execute('COMMIT'); Db::getInstance()->Execute('SET AUTOCOMMIT = 1'); return $sequence; } public function registerParcel($order, $products, $weight) { global $cookie; $delivery_infos = Db::getInstance()->getRow(' SELECT s.*, m.`dlv_mode` FROM `'._DB_PREFIX_.'mr_selected` s LEFT JOIN `'._DB_PREFIX_.'mr_method` m ON (s.`id_method` = m.`id_mr_method`) WHERE s.`id_order` = '.(int) $order->id.' '); // Hack 5 numbers relay num if (isset($delivery_infos['MR_Selected_Num']) && $delivery_infos['MR_Selected_Num']) { $delivery_infos['MR_Selected_Num'] = substr($delivery_infos['MR_Selected_Num'], -5); } if(!$delivery_infos || in_array($delivery_infos['dlv_mode'], array('LDS', 'LD1', 'HOM'))) { $mode = $delivery_infos? $delivery_infos['dlv_mode']: 'LD1'; $address = Db::getInstance()->getRow(' SELECT a.`postcode`, UPPER(c.`iso_code`) AS `iso_code` FROM `'._DB_PREFIX_.'address` a LEFT JOIN `'._DB_PREFIX_.'country` c ON a.`id_country` = c.`id_country` WHERE a.`id_address` = '.(int) $order->id_address_delivery.' '); $country = $address['iso_code']; $postcode = $address['postcode']; $mode_tri = $mode == 'LD1' ? 'LDR': $mode; $plantri = Db::getInstance()->getRow(' SELECT * FROM `'._DB_PREFIX_.'mondialrelay_tri` WHERE `destyp` = "CP" AND `destex` = "'.pSQL($postcode).'" AND `cppay` = "'.pSQL($country).'" AND ( `livmod` = "'.pSQL($mode_tri).'" OR `livmod` = "HOM" ) '); if(!$plantri) { $plantri = Db::getInstance()->getRow(' SELECT * FROM `'._DB_PREFIX_.'mondialrelay_tri` WHERE `destyp` = "CP" AND `destex` = "'.pSQL(substr($postcode, 0, 2)).'" AND `cppay` = "'.pSQL($country).'" AND ( `livmod` = "'.pSQL($mode_tri).'" OR `livmod` = "HOM" ) '); } if($plantri) { $mode = $plantri['livmod']; } } else { $mr_relais = Db::getInstance()->getRow(' SELECT * FROM `'._DB_PREFIX_.'mondialrelay_relais` WHERE 1 AND `direction` = "'.pSQL($delivery_infos['MR_Selected_Num']).'" AND `prpay` = "'.pSQL($delivery_infos['MR_Selected_Pays']).'" '); $mode = $delivery_infos['dlv_mode']; if($mode == '24R') { if($mr_relais['narel'] == 'F') { $mode = '24X'; } elseif($mr_relais['narel'] == 'E') { $mode = '24L'; } else { $mode = '24R'; } } $country = $delivery_infos['MR_Selected_Pays']; $postcode = $delivery_infos['MR_Selected_CP']; $plantri = Db::getInstance()->getRow(' SELECT * FROM `'._DB_PREFIX_.'mondialrelay_tri` WHERE `destyp` = "RL" AND `destex` = "'.pSQL($delivery_infos['MR_Selected_Num']).'" AND `cppay` = "'.pSQL($country).'" '); } if(!$plantri) { // TODO: error handling return; } $sequence = $this->getShippingNumber((int) $order->id); if (!$sequence){ return array('

Unicité du numéro d\'expédition non respecté


', array()); } $expedition_number = sprintf('%08d', $sequence); $mr_info = Configuration::get('MR_ACCOUNT_DETAIL'); $mr_info = unserialize($mr_info); // $shipping_number_1 = Configuration::get('MONDIALRELAY_ENSIGN_CODE').$expedition_number.'0101'; $shipping_number_1 = $mr_info['MR_CODE_MARQUE'].$expedition_number.'0101'; $control_number_1 = 11 - ((int) substr($shipping_number_1, 13, 1) * 2 + (int) substr($shipping_number_1, 12, 1) * 3 + (int) substr($shipping_number_1, 11, 1) * 4 + (int) substr($shipping_number_1, 10, 1) * 5 + (int) substr($shipping_number_1, 9, 1) * 6 + (int) substr($shipping_number_1, 8, 1) * 7 + (int) substr($shipping_number_1, 7, 1) * 2 + (int) substr($shipping_number_1, 6, 1) * 3 + (int) substr($shipping_number_1, 5, 1) * 4 + (int) substr($shipping_number_1, 4, 1) * 5 + (int) substr($shipping_number_1, 3, 1) * 6 + (int) substr($shipping_number_1, 2, 1) * 7 + (int) substr($shipping_number_1, 1, 1) * 2 + (int) substr($shipping_number_1, 0, 1) * 3) % 11; if($control_number_1 == 10 || $control_number_1 == 11) { $control_number_1 = 0; } $shipping_number_2 = $plantri['modexp'].$plantri['service'].$plantri['direction']; $control_number_2 = 11 - ((int) substr($shipping_number_2, 9, 1) * 2 + (int) substr($shipping_number_2, 8, 1) * 3 + (int) substr($shipping_number_2, 7, 1) * 4 + (int) substr($shipping_number_2, 6, 1) * 5 + (int) substr($shipping_number_2, 5, 1) * 6 + (int) substr($shipping_number_2, 4, 1) * 7 + (int) substr($shipping_number_2, 3, 1) * 2 + (int) substr($shipping_number_2, 2, 1) * 3 + (int) substr($shipping_number_2, 1, 1) * 4 + (int) substr($shipping_number_2, 0, 1) * 5) % 11; if($control_number_2 == 10 || $control_number_2 == 11) { $control_number_2 = 0; } $shipping_number = $shipping_number_1.$control_number_1.$shipping_number_2.$control_number_2; if($_SERVER['REMOTE_ADDR'] != '109.190.53.175' && $_SERVER['REMOTE_ADDR'] != '78.226.56.137' && $_SERVER['REMOTE_ADDR'] != '88.163.22.223' && $_SERVER['REMOTE_ADDR'] != '90.63.178.63') { $order->shipping_number = $shipping_number; $order->update(); } return array('', array( 'idrelay' => $delivery_infos? $delivery_infos['MR_Selected_Num']: '', 'shipping_number' => $shipping_number, 'shipping_number_fmt' => substr($shipping_number, 0, 2).' '.substr($shipping_number, 2, 8).' '.substr($shipping_number, 10, 4).' '.substr($shipping_number, 14, 1).' '.substr($shipping_number, 15, 4).' '.substr($shipping_number, 19, 1).' '.substr($shipping_number, 20, 5).' '.substr($shipping_number, 25, 1), 'shipping_number_c25i' => $this->isoreplace($this->c25I($shipping_number)), 'weight' => $weight, 'plantri' => $plantri, 'mode' => $mode, 'expedition_number' => $expedition_number, )); } private function c25I($string, $checksum=FALSE) { if(strlen($string) == 0 || strlen($string) % 2 != 0 || !is_numeric($string)) { return ''; } if($checksum) { $i = strlen($string) - 1; $checksum = 0; for($i=strlen($string) - 1; $i >= 0; $i -= 2) { $checksum += (int) substr($string, $i, 1); } $checksum = $checksum * 3; for($i=strlen($string) - 2; $i >= 0; $i -= 2) { $checksum += (int) substr($string, $i, 1); } $string = $string.((10 - ($checksum % 10)) % 10); } $result = ''; for($i=0, $l=strlen($string); $i < $l; $i += 2) { $dummy = (int) substr($string, $i, 2); $dummy += ($dummy < 94? 33: 101); $result .= chr($dummy); } return '«'.$result.'»'; } private function isoreplace($str) { // ISO/CEI 646 return str_replace(array( 'Ç', 'ü', 'é', 'â', 'ä', 'à', 'å', 'ç', 'ê', 'ë', 'è', 'ï', 'î', 'ì', 'Ä', 'Å', 'É', 'æ', 'Æ', 'ô', 'ö', 'ò', 'û', 'ù', 'ÿ', 'Ö', 'Ü', '¢', '£', '¥', '₧', 'ƒ', 'á', 'í', 'ó', 'ú', 'ñ', 'Ñ', 'ª', 'º', '¿', '⌐', '¬', '½', '¼', '¡', '«', '»', '░', '▒', '▓', '│', '┤', '╡', '╢', '╖', '╕', '╣', '║', '╗', '╝', '╜', '╛', '┐', '└', '┴', '┬', '├', '─', '┼', '╞', '╟', '╚', '╔', '╩', '╦', '╠', '═', '╬', '╧', '╨', '╤', '╥', '╙', '╘', '╒', '╓', '╫', '╪', '┘', '┌', '█', '▄', '▌', '▐', '▀', 'α', 'ß', 'Γ', 'π', 'Σ', 'σ', 'µ', 'τ', 'Φ', 'Θ', 'Ω', 'δ', '∞', 'φ', 'ε', '∩', '≡', '±', '≥', '≤', '⌠', '⌡', '÷', '≈', '°', '∙', '·', '√', 'ⁿ', '²', '■', 'Ê', ), array( chr(128), chr(129), chr(130), chr(131), chr(132), chr(133), chr(134), chr(135), chr(136), chr(137), chr(138), chr(139), chr(140), chr(141), chr(142), chr(143), chr(144), chr(145), chr(146), chr(147), chr(148), chr(149), chr(150), chr(151), chr(152), chr(153), chr(154), chr(155), chr(156), chr(157), chr(158), chr(159), chr(160), chr(161), chr(162), chr(163), chr(164), chr(165), chr(166), chr(167), chr(165), chr(166), chr(167), chr(168), chr(169), chr(170), chr(174), chr(175), chr(173), chr(174), chr(175), chr(176), chr(177), chr(178), chr(179), chr(180), chr(181), chr(182), chr(183), chr(184), chr(185), chr(186), chr(187), chr(188), chr(189), chr(190), chr(191), chr(192), chr(193), chr(194), chr(195), chr(196), chr(197), chr(198), chr(199), chr(200), chr(201), chr(202), chr(203), chr(204), chr(205), chr(206), chr(207), chr(208), chr(209), chr(210), chr(211), chr(209), chr(210), chr(211), chr(212), chr(213), chr(214), chr(215), chr(216), chr(217), chr(218), chr(219), chr(220), chr(221), chr(222), chr(223), chr(224), chr(225), chr(226), chr(227), chr(228), chr(229), chr(230), chr(231), chr(232), chr(233), chr(234), chr(235), chr(236), chr(237), chr(238), chr(239), chr(240), chr(241), chr(242), chr(243), chr(244), chr(245), chr(246), chr(247), chr(248), chr(249), chr(250), chr(251), chr(252), chr(253), chr(254), chr(210), ), $str); } public function logParcel($shipping_data, $products) { global $cookie; foreach($products as $id_order_detail => $qty) { if($qty > 0) { Db::getInstance()->ExecuteS(' INSERT INTO `'._DB_PREFIX_.'mondialrelay_parcel` VALUES ( '.(int) $id_order_detail.', '.(int) $cookie->id_employee.', '.(int) $qty.', "'.pSQL($shipping_data['shipping_number']).'", "'.pSQL($shipping_data['idrelay']).'", "'.pSQL($shipping_data['plantri']['cppay']).'", "'.pSQL($shipping_data['plantri']['nogroup']).'", "'.pSQL($shipping_data['plantri']['modexp']).'", "'.pSQL($shipping_data['plantri']['pretri']).'", "'.pSQL($shipping_data['plantri']['navette']).'", "'.pSQL($shipping_data['plantri']['direction']).'", "'.pSQL($shipping_data['mode']).'", "'.pSQL($shipping_data['expedition_number']).'", '.(float) $shipping_data['weight'].', NOW(), "0000-00-00 00:00:00" ) '); } } } public function __addOrderHistory($shipping_data, $order, $products_sent) { } public function addOrderHistory($shipping_data, $order, $products_sent) { global $cookie; // $MONDIALRELAY_carrier_id = unserialize(Configuration::get('MONDIALRELAY_CARRIERS')); // $MONDIALRELAY_carrier_id = (int) array_pop($exapaq_carrier_id); $id_carrier = (int) $order->id_carrier; $mr_carriers = array(); foreach (Db::getInstance()->executeS(' SELECT `id_carrier` FROM `' . _DB_PREFIX_ . 'mr_method` ORDER BY `is_deleted` ASC') as $carrier) { $mr_carriers = (int) $carrier['id_carrier']; } if (!in_array($id_carrier, $mr_carriers)) $id_carrier = $mr_carriers[0]; $carrier = new Carrier($id_carrier, (int) $order->id_lang); $customer = new Customer((int) $order->id_customer); if((int) $order->id_lang == 3) { $content_html = 'Contenido del paquete:'; $content_txt = 'Contenido del paquete:'; } elseif((int) $order->id_lang == 5) { $content_html = 'Contenuto del package:'; $content_txt = 'Contenuto del package:'; } else { $content_html = 'Contenu du colis :'; $content_txt = 'Contenu du colis :'; } $templateVars = array( '{followup}' => str_replace('@', $shipping_data['shipping_number'], $carrier->url), '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{id_order}' => (int) $order->id, '{product_list}' => !empty($products_sent)? $content_html.$products_sent: '', '{product_list_txt}' => !empty($products_sent)? $content_txt.strip_tags($products_sent): '', ); $history = new OrderHistory(); $history->id_order = (int) $order->id; $fully_sent = FALSE; $products_sent = array(); $order_details = array(); foreach(Db::getInstance()->ExecuteS(' SELECT `id_order_detail` FROM `'._DB_PREFIX_.'order_detail` WHERE `id_order` = '.(int) $order->id.' ') as $row) { $order_details[] = (int) $row['id_order_detail']; } foreach(Db::getInstance()->ExecuteS(' SELECT d.`id_order_detail`, IF( (d.`product_quantity` - IF( d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded` ) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0 ) AS `remain` FROM `'._DB_PREFIX_.'order_detail` d LEFT OUTER JOIN `'._DB_PREFIX_.'lapostews` s ON s.`id_order_detail` = d.`id_order_detail` WHERE d.`id_order` = '.(int) $order->id.' GROUP BY d.`id_order_detail` ') as $quantity_remain) { if((int) $quantity_remain['remain'] == 0) { $products_sent[] = (int) $quantity_remain['id_order_detail']; } } foreach(Db::getInstance()->ExecuteS(' SELECT d.`id_order_detail`, IF( (d.`product_quantity` - IF( d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded` ) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0 ) AS `remain` FROM `'._DB_PREFIX_.'order_detail` d LEFT OUTER JOIN `'._DB_PREFIX_.'exapaqws` s ON s.`id_order_detail` = d.`id_order_detail` WHERE d.`id_order` = '.(int) $order->id.' GROUP BY d.`id_order_detail` ') as $quantity_remain) { if((int) $quantity_remain['remain'] == 0) { $products_sent[] = (int) $quantity_remain['id_order_detail']; } } foreach(Db::getInstance()->ExecuteS(' SELECT d.`id_order_detail`, IF( (d.`product_quantity` - IF( d.`product_quantity_return` > 0, d.`product_quantity_return`, d.`product_quantity_refunded` ) - IFNULL(SUM(s.`quantity`), 0)) > 0, 1, 0 ) AS `remain` FROM `'._DB_PREFIX_.'order_detail` d LEFT OUTER JOIN `'._DB_PREFIX_.'mondialrelay_parcel` s ON s.`id_order_detail` = d.`id_order_detail` WHERE d.`id_order` = '.(int) $order->id.' GROUP BY d.`id_order_detail` ') as $quantity_remain) { if((int) $quantity_remain['remain'] == 0) { $products_sent[] = (int) $quantity_remain['id_order_detail']; } } $remaining = array(); foreach($order_details as $d) { if(!in_array($d, $products_sent)) { $remaining[] = (int) $d; } } if(count($remaining) == 0) { $fully_sent = TRUE; } else { $id_sales = array(); foreach(Db::getInstance()->ExecuteS(' SELECT DISTINCT c.`id_sale` FROM `'._DB_PREFIX_.'product_ps_cache` c LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON c.`id_product` = d.`product_id` WHERE d.`id_order_detail` IN ('.implode(', ', $remaining).') ') as $row) { $id_sales[] = (int) $row['id_sale']; } $sent_sales = array(); foreach(Db::getInstance()->ExecuteS(' SELECT DISTINCT `id_sale` FROM `'._DB_PREFIX_.'shipping_history` WHERE `id_order` = '.(int) $order->id.' AND `id_sale` IN ('.implode(', ', $id_sales).') ') as $row) { $sent_sales[] = (int) $row['id_sale']; } $remaining = array(); foreach($id_sales as $s) { if(!in_array($s, $sent_sales)) { $remaining[] = (int) $s; break; } } $fully_sent = (count($remaining) == 0); } $history->changeIdOrderState(($fully_sent? Configuration::get('PS_OS_SHIPPING'): 17), (int) $order->id); $history->id_employee = (int) $cookie->id_employee; $history->addWithemail(TRUE, $templateVars); global $_LANGMAIL; // $subject = 'Package in transit'; // Mail::Send( // intval($order->id_lang), // 'in_transit', // ( // (is_array($_LANGMAIL) && key_exists($subject, $_LANGMAIL)) // ? $_LANGMAIL[$subject] // : $subject // ), // $templateVars, // $customer->email, // $customer->firstname.' '.$customer->lastname // ); } }