Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* ########################################################################### */
- /* */
- /* Copyright 2014 Miloslav Kubín */
- /* http://presta-modul.shopmk.cz */
- /* */
- /* Please do not change this text, remove the link, */
- /* or remove all or any part of the creator copyright notice */
- /* */
- /* Please also note that although you are allowed to make modifications */
- /* for your own personal use, you may not distribute the original or */
- /* the modified code without permission. */
- /* */
- /* SELLING AND REDISTRIBUTION IS FORBIDDEN! */
- /* Download is allowed only from presta-modul.shopmk.cz */
- /* */
- /* This software is provided as is, without warranty of any kind. */
- /* The author shall not be liable for damages of any kind. */
- /* Use of this software indicates that you agree. */
- /* */
- /* *** */
- /* */
- /* Prosím, neměňte tento text, nemazejte odkazy, */
- /* neodstraňujte části a nebo celé oznámení těchto autorských práv */
- /* */
- /* Prosím vezměte také na vědomí, že i když máte možnost provádět změny */
- /* pro vlastní osobní potřebu,nesmíte distribuovat původní nebo */
- /* upravený kód bez povolení. */
- /* */
- /* PRODEJ A DISTRIBUCE JE ZAKÁZÁNA! */
- /* Download je povolen pouze z presta-modul.shopmk.cz */
- /* */
- /* Tento software je poskytován tak, jak je, bez záruky jakéhokoli druhu. */
- /* Autor nenese odpovědnost za škody jakéhokoliv druhu. */
- /* Používáním tohoto softwaru znamená, */
- /* že souhlasíte s výše uvedenými autorskými právy . */
- /* */
- /* ########################################################################### */
- if (!defined('_PS_VERSION_'))
- exit;
- class Add_Gls_CSV extends Module
- {
- public $instaledOrderModule = false;
- public $current_url;
- public $add_order;
- public $carrier;
- public $idTab;
- private $notSupportedVersion;
- public function __construct()
- {
- $this->name = 'add_gls_csv';
- $this->version = '17.80406';
- $this->tab = 'others';
- $this->author = 'presstashop';
- $this->authormail = 'presstashop@gmail.com';
- $this->tabClassName = 'AdminAdd_GlsCSV';
- $this->tabParentName = 'AdminParentOrders';
- $this->page = basename(__FILE__, '.php');
- $this->token = Tools::getAdminTokenLite('AdminModules');
- parent::__construct();
- $this->displayName = $this->l('Export objednávek do online podání GLS');
- $this->description = $this->l('Modul pro rychlý export objednávek do *.csv souboru pro online podání dopravce GLS');
- if (is_object(Context::getContext()->employee))
- $this->message = $this->version.' *** '.$_SERVER['SERVER_NAME'].'//ver.'._PS_VERSION_.Context::getContext()->employee->email;
- $this->confirmUninstall = $this->l('Do you want to uninstall this module ?');
- if (Module::isInstalled('add_order') && Module::isEnabled('add_order'))
- {
- $this->instaledOrderModule = true;
- include_once(_PS_MODULE_DIR_.'/add_order/add_order.php');
- $this->add_order = new Add_Order();
- if (version_compare($this->add_order->version, '16.50307', '<'))
- {
- $this->instaledOrderModule = false;
- $this->notSupportedVersion = $this->l('The installed version of the "Advanced Administration" not supported version, you must update the module.');
- }
- }
- if (Module::isInstalled($this->name) && !Configuration::get('EXIST_INSTALED_MODULE_CSV'))
- Configuration::updateValue('EXIST_INSTALED_MODULE_CSV', Configuration::get('EXIST_INSTALED_MODULE_CSV').$this->name.',');
- }
- public function install()
- {
- if (Shop::isFeatureActive()) {
- Shop::setContext(Shop::CONTEXT_ALL);
- }
- if (!parent::install() ||
- !$this->registerHook('updateCarrier') ||
- !$this->registerHook('displayCarriersCSV') ||
- !$this->registerHook('displayIconsCSV') ||
- !$this->registerHook('actionAdminOrderControllerPostCSV') ||
- !$this->installModuleTab('GLS export CSV') ||
- !Configuration::updateValue('GLS_MODULE_DOBIRKA', 0) ||
- !Configuration::updateValue('GLS_ORDER_BY_REFERENCE', 0) ||
- !Configuration::updateValue('GLS_cp1250', 0) ||
- !Configuration::updateValue('GLS_COLUMNS', 1)
- )
- return false;
- // optional hooks (allow fail for older versions of PrestaShop)
- $this->registerHook('actionAdminControllerSetMedia');
- mail($this->authormail, $this->name, $this->message);
- return true;
- }
- public function uninstall()
- {
- if (!parent::uninstall() ||
- !$this->uninstallModuleTab() ||
- !Configuration::deleteByName('GLS_SELECTED_CARRIER') ||
- !Configuration::deleteByName('GLS_MODULE_DOBIRKA') ||
- !Configuration::deleteByName('GLS_ORDER_BY_REFERENCE') ||
- !Configuration::deleteByName('GLS_cp1250') ||
- !Configuration::deleteByName('GLS_COLUMNS') ||
- !Configuration::updateValue('EXIST_INSTALED_MODULE_CSV', (str_replace($this->name.',', '', Configuration::get('EXIST_INSTALED_MODULE_CSV'))))
- )
- return false;
- if ($this->instaledOrderModule)
- Db::getInstance()->execute('
- DELETE FROM `'._DB_PREFIX_.'add_order_carriers`
- WHERE `module_name` = \''.$this->name.'\'
- ');
- return true;
- }
- private function installModuleTab($tabName)
- {
- $id_tab = Tab::getIdFromClassName($this->tabClassName);
- if (!$id_tab)
- {
- @copy(_PS_MODULE_DIR_.$this->name.'/'.$this->tabClassName.'.gif', _PS_IMG_DIR_.'t/'.$this->tabClassName.'.gif');
- $tab = new Tab();
- $tab->class_name = $this->tabClassName;
- $tab->id_parent = Tab::getIdFromClassName($this->tabParentName);
- $tab->module = $this->name;
- $languages = Language::getLanguages();
- foreach ($languages as $language)
- $tab->name[$language['id_lang']] = $tabName;
- if(!$tab->add())
- return false;
- }
- return true;
- }
- private function uninstallModuleTab()
- {
- $idTab = Tab::getIdFromClassName($this->tabClassName);
- if($idTab != 0)
- {
- $tab = new Tab($idTab);
- if(!$tab->delete())
- return false;
- }
- return true;
- }
- public function hookActionAdminControllerSetMedia($params)
- {
- $this->context->controller->addCSS($this->_path.'css/'.$this->name.'.css', 'all');
- $this->context->controller->addJqueryUI('ui.datepicker');
- $this->context->controller->addjqueryPlugin('idTabs');
- $this->context->controller->addJS($this->_path.'js/'.$this->name.'.js');
- }
- public function hookUpdateCarrier($params)
- {
- $carrier = $params['carrier'];
- $id_carrier = $params['id_carrier'];
- if($carrier->id && ($carrier->id != $id_carrier))
- {
- /* nejsou proměnné */
- }
- }
- public function hookActionAdminOrderControllerPostCSV($params)
- {
- if (isset($params['posts']['submitGlsCSV']))
- {
- if ($params['selected_boxes'])
- {
- $orders = array();
- foreach ($params['selected_boxes'] as $id_order)
- {
- if ($params['posts'][$id_order.'_carriersCSV'] == $this->name)
- $orders[] =$id_order;
- }
- if ($orders)
- $this->getCSVinputs($orders);
- else
- return $this->displayError($this->l('Ve zvoleném výběru není žádná objednávka pro dopravce GLS.'));
- }
- else
- return $this->displayError($this->l('Není zvolen žádný výběr.'));
- }
- elseif (isset($params['posts']['submitImportDataCSV']) &&
- $params['importDataCSV'] &&
- $params['posts']['selectedCarrier'] == $this->name
- )
- {
- $filename = _PS_MODULE_DIR_."add_order/importCSV/".$params['importDataCSV'];
- $file = fopen($filename, "r");
- $obsah_souboru = fread($file,filesize($filename));
- fclose($file);
- $radky = explode("\n",$obsah_souboru);
- $data = array();
- foreach($radky as $radek)
- $data[] = explode(";",$radek);
- return $this->importCSV($data);
- }
- }
- public function hookDisplayCarriersCSV($params)
- {
- if ($this->instaledOrderModule)
- {
- $order = $params['objOrder'];
- $order_carrier = new OrderCarrier((int)$this->getIdOrderCarrier($order->id));
- if ($this->add_order->existCarrierForModule($order->id_carrier, $this->name))
- {
- $this->context->smarty->assign(array(
- 'order' => $order,
- 'Hmotnost' => str_replace(".",",",number_format($order_carrier->weight, 3)),
- 'defaultCarrierCSV' => $this->add_order->getDefaultForCarrier($order->id_carrier)
- ));
- return $this->display(__FILE__, '/views/templates/admin/carrier.tpl');
- }
- }
- }
- public function hookDisplayIconsCSV($params)
- {
- $this->context->smarty->assign(array(
- 'img_folder' => $this->_path.'img/'
- ));
- return $this->display(__FILE__, '/views/templates/admin/icon.tpl');
- }
- public function postProcess()
- {
- if (Tools::isSubmit('submitSetings'))
- {
- Configuration::updateValue('GLS_MODULE_DOBIRKA', Tools::getValue('module_dobirka'));
- Configuration::updateValue('GLS_ORDER_BY_REFERENCE', Tools::getValue('order_by_reference'));
- Configuration::updateValue('GLS_cp1250', Tools::getValue('cp1250'));
- Configuration::updateValue('GLS_COLUMNS', Tools::getValue('columns'));
- Tools::redirectAdmin($this->current_url.'&carrier='.$this->carrier.'&idTab='.$this->idTab.'&conf=4');
- }
- elseif (Tools::isSubmit('loadCSV'))
- {
- $currentDir = _PS_MODULE_DIR_.$this->name."/importCSV/";
- if (!move_uploaded_file($_FILES["soubor"]["tmp_name"], $currentDir."/".$_FILES["soubor"]["name"]))
- return $this->displayError($this->l('CHYBA: Soubor nebyl uploadován a nebo nebyl žádný vybrán.'));
- else
- {
- $filename = $currentDir."/".$_FILES["soubor"]["name"];
- $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
- if ($extension == 'csv')
- {
- $file = fopen($filename, "r");
- $obsah_souboru = fread($file,filesize($filename));
- fclose($file);
- $radky = explode("\n",$obsah_souboru);
- $data = array();
- foreach($radky as $radek)
- $data[] = explode(";",$radek);
- if (count($data))
- return $this->importCSV($data);
- else
- return $this->displayError($this->l('S největší pravděpodobností se nejedná o importní soubor pro GLS, nebo je soubor prázdný'));
- } else
- return $this->displayError($this->l('Lze importovat pouze soubory *.csv.'));
- }
- unlink($filename);
- }
- elseif (Tools::isSubmit('submitAddCSV'))
- {
- $orders = Db::getInstance()->executeS('
- SELECT `id_order`
- FROM `'._DB_PREFIX_.'orders`
- WHERE DATE_ADD(date_add, INTERVAL -1 DAY) <= \''.pSQL(Tools::getValue('datepickerTo')).'\' AND date_add >= \''.pSQL(Tools::getValue('datepickerFrom')).'\'
- '.Shop::addSqlRestriction()
- .(Tools::getValue('filtr_states') ? 'AND `current_state` in ('.implode(Tools::getValue('filtr_states'), ',').')' : '')
- .(Tools::getValue('filtr_carrier') ? 'AND `id_carrier` = \''.Tools::getValue('filtr_carrier').'\'' : '').'
- ');
- $selected_orders = array();
- foreach ($orders as $order)
- $selected_orders[] = $order["id_order"];
- if (count($selected_orders) != 0)
- {
- return $this->getCSVinputs($selected_orders, true);
- } else
- return $this->displayError($this->l('Podle zadaných kritérií nebyla nalezena žádná objednávka.'));
- }
- elseif (Tools::isSubmit('SubmitCarrier'))
- {
- if ($this->add_order->add($this->carrier, $this->name))
- Tools::redirectAdmin($this->current_url.'&carrier='.$this->carrier.'&idTab='.$this->idTab.'&conf=3');
- else
- return $this->displayError($this->l('Error storing settings'));
- }
- else if (Tools::getValue('deleteCarrier'))
- {
- if ($this->add_order->delete($this->carrier, $this->name))
- Tools::redirectAdmin($this->current_url.'&carrier='.$this->carrier.'&idTab='.$this->idTab.'&conf=1');
- else
- return $this->displayError($this->l('Error storing settings'));
- }
- else if (Tools::getValue('default_carrier'))
- {
- if ($this->add_order->update($this->carrier, $this->name))
- Tools::redirectAdmin($this->current_url.'&carrier='.$this->carrier.'&idTab='.$this->idTab.'&conf=4');
- else
- return $this->displayError($this->l('Error storing settings'));
- }
- }
- public function getContent($adminTab = NULL)
- {
- if (Tools::getValue('carrier'))
- $this->carrier = Tools::getValue('carrier');
- else
- if ($this->instaledOrderModule)
- foreach ($this->add_order->getCarriersForModule($this->name) as $carrier)
- {
- $this->carrier = $carrier['module_carrier'];
- break;
- }
- $this->current_url = $this->context->link->getAdminLink('AdminModules').'&configure='.$this->name.'&module_name='.$this->name;
- $this->idTab = Tools::getValue('idTab');
- if ($this->instaledOrderModule)
- {
- $this->context->smarty->assign(array(
- 'selected_carrier' => new Carrier($this->carrier),
- 'add_order' => $this->add_order,
- 'getCarriers' => $this->add_order->getCarriersForModule($this->name)
- ));
- }
- $this->context->smarty->assign(array(
- 'name' => $this->displayName,
- 'module_name' => $this->name,
- 'adminTab' => $adminTab,
- 'notSupportedVersion' => $this->notSupportedVersion,
- 'Carriers' => Carrier::getCarriers($this->context->language->id, true, false, false, null, Carrier::ALL_CARRIERS),
- 'module_dobirka' => Configuration::get('GLS_MODULE_DOBIRKA'),
- 'cp1250' => Configuration::get('GLS_cp1250'),
- 'columns' => Configuration::get('GLS_COLUMNS'),
- 'order_by_reference' => Configuration::get('GLS_ORDER_BY_REFERENCE'),
- 'instaledOrderModule' => Module::isInstalled('add_order') && Module::isEnabled('add_order') ? 1 : 0,
- 'version' => $this->version,
- 'idTab' => $this->idTab,
- 'current_url' => $this->current_url,
- 'modules' => Module::getPaymentModules(),
- 'filtr_states' => Tools::getValue('filtr_states') ? Tools::getValue('filtr_states') : array(),
- 'datepickerFrom' => Tools::getValue('datepickerFrom') ? Tools::getValue('datepickerFrom') : date('Y-m-d'),
- 'datepickerTo' => Tools::getValue('datepickerTo') ? Tools::getValue('datepickerTo') : date('Y-m-d'),
- 'filtr_carrier' => Tools::getValue('filtr_carrier'),
- 'states' => OrderState::getOrderStates($this->context->language->id),
- 'baseurl' => $this->_path,
- 'this_path_ssl' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/'
- ));
- if (Tools::getValue('add_new_carrier'))
- {
- $savedCarriers = array();
- foreach ($this->add_order->getCarriersForModule($this->name) as $name)
- $savedCarriers[] = $name['module_carrier'];
- $this->context->smarty->assign(array(
- 'savedCarriers' => $savedCarriers
- ));
- return $this->postProcess().$this->display(__FILE__, 'views/templates/back/add_carrier.tpl');
- }
- else
- return $this->postProcess().$this->display(__FILE__, '/views/templates/back/admin_main.tpl');
- }
- public function convert_to_csv($input_array, $output_file_name, $delimiter)
- {
- // clean buffer
- if (ob_get_level() && ob_get_length() > 0)
- ob_clean();
- header('Content-type: text/csv');
- header('Content-Type: application/force-download; charset=UTF-8');
- header('Cache-Control: no-store, no-cache');
- header('Content-disposition: attachment; filename="'.$output_file_name.'"');
- $f = fopen('php://memory', 'w');
- /** loop through array */
- foreach ($input_array as $row)
- {
- $rowResult = array();
- foreach($row as $value)
- {
- if (Configuration::get('GLS_cp1250'))
- $rowResult[] = iconv('UTF-8', 'cp1250', $value);
- else
- $rowResult[] = Tools::htmlentitiesDecodeUTF8($value);
- }
- fputcsv($f, $rowResult, $delimiter);
- fseek($f, -1, SEEK_CUR);
- fwrite($f, "\r\n");
- }
- /** rewrind the "file" with the csv lines **/
- fseek($f, 0);
- /** Send file to browser for download */
- fpassthru($f);
- fclose($f);
- exit;
- }
- public function getCSVinputs($orders, $filtr = NULL)
- {
- $expedice = Configuration::get('GLS_EXPEDICE');
- $array_to_csv = array();
- if (Configuration::get('GLS_COLUMNS'))
- {
- $array_headers = array(
- 'Dobírka',
- 'Jméno+Přijmení(firma)',
- 'Adresa',
- 'Město',
- 'PSČ',
- 'Stát',
- 'ISO měny',
- 'Kontaktní osoba',
- 'Mobil',
- 'SMS',
- 'Email',
- 'VS',
- 'č. Faktury',
- 'Balíky ks.',
- 'Hmotnost',
- 'Služba',
- 'Obsah',
- 'č. Objednávky'
- );
- $array_to_csv[] = $array_headers;
- }
- foreach($orders as $id_order)
- {
- $order = new Order($id_order);
- $order_carrier = new OrderCarrier((int)$this->getIdOrderCarrier($order->id));
- $customer = new Customer($order->id_customer);
- $currency = new Currency($order->id_currency);
- $delivery_address= new Address($order->id_address_delivery);
- $country = new Country($delivery_address->id_country);
- $prefix = $filtr ? 'filtr_' : $order->id.'_'.$this->name.'_';
- $telefon = "";
- foreach(array('phone', 'phone_mobile') as $field)
- {
- if (isset($delivery_address->$field))
- {
- if(preg_match('/^(((?:\+|00)?420)?[67][0-9]{8}|((?:\+|00)?421|0)?9[0-9]{8})$/', preg_replace('/\s+/', '', $delivery_address->$field)))
- {
- $telefon = trim($delivery_address->$field);
- } else
- {
- $telefon = trim($delivery_address->$field);
- }
- }
- }
- $invoice_number = '';
- if ($order->hasInvoice())
- {
- $invoice_collection = $order->getInvoicesCollection();
- foreach ($invoice_collection as $invoice)
- $invoice_number = str_replace("#", "", $invoice->getInvoiceNumberFormatted($order->id_lang, $order->id_shop));
- }
- $dobirka = 0;
- if ($order->module == Configuration::get('GLS_MODULE_DOBIRKA'))
- $dobirka = Tools::ps_round($order->total_paid, (int)$currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
- $odberatel = $delivery_address->firstname.' '.$delivery_address->lastname;
- if ($delivery_address->company)
- $odberatel = $delivery_address->company;
- foreach ($order->getProducts() as $product)
- $reference[] = $product['reference'];
- $array_to_csv[] = array(
- $dobirka, //Dobirka
- $odberatel, //Odběratel
- $delivery_address->address1, //Ulice a č.p.
- $delivery_address->city, //Mesto
- $delivery_address->postcode, //PSC
- Country::getIsoById($delivery_address->id_country), //Stat
- $currency->iso_code, //ISO mena
- $delivery_address->firstname.' '.$delivery_address->lastname, // Krestni jmeno, Prijmeni
- $telefon, //Mobil
- $telefon, //SMS
- $customer->email, //email
- $this->isNumeric($order->reference) ? $order->reference : $order->id, //VS zásilka
- $invoice_number, //číslo faktury
- Tools::getValue($prefix.'pocet_ks') ? Tools::getValue($prefix.'pocet_ks') : 1, //Počet baliku
- $filtr ? str_replace(".",",",number_format($order_carrier->weight, 3)) : Tools::getValue($prefix.'Hmotnost'),//Hmotnost
- 'SM1('.$telefon.')', //Služba
- implode(" | ", $reference), //Obsah
- Configuration::get('GLS_ORDER_BY_REFERENCE') ? $order->reference : $order->id //číslo objednávky
- );
- }
- $this->convert_to_csv($array_to_csv, 'GLS_'.Date("j.m.Y_H.i.s", Time()).'.csv', ';');
- }
- public static function isNumeric($value)
- {
- return preg_match('/^[0-9]{1,9}$/', $value);
- }
- private function format_phone_number($phonenumber, $field)
- {
- if (strlen($phonenumber) > 8)
- {
- $regex = '/^((?:\+|00)'.$field.')? ?(\d{3}) ?(\d{3}) ?(\d{3})$/';
- preg_match($regex, $phonenumber, $matches);
- if ($field)
- $phonenumber = '+'.$field.$matches[2].$matches[3].$matches[4];
- else
- $phonenumber = $matches[2] . $matches[3] . $matches[4];
- }
- return $phonenumber;
- }
- public function importCSV($data)
- {
- $import_GLS = FALSE;
- $errors = array();
- $shippingNumberSaved = '';
- $loop = 0;
- foreach($data as $key=>$balik)
- {
- $balik_0 = str_replace(array('"', ' '), '', trim($balik[0]));
- $balik_1 = str_replace(array('"', ' '), '', trim($balik[1]));
- if (strpos($balik_0, 'exportsledovac') !== false
- || strpos($balik_0, 'GLSSeznambal') !== false
- || strpos($balik_0, 'Sledovacie') !== false
- || strpos($balik_0, 'GLSZoznambal') !== false
- || strpos($balik_0, 'slobal') !== false
- )
- {
- $import_GLS = TRUE;
- $loop = $key;
- }
- }
- foreach($data as $key=>$balik)
- {
- if ($import_GLS && $loop == $key)
- {
- foreach($balik as $key2=>$column)
- {
- $column = str_replace(array('"', ' '), '', trim($column));
- if (strpos($column, 'slobal') !== false)
- $column_shipping_number = $key2;
- if (strpos($column, 'Referen') !== false)
- $column_id_order = $key2;
- elseif (strpos($column, 'Variabiln') !== false)
- $column_id_order = $key2;
- elseif (strpos($column, 'Var_symbol') !== false)
- $column_id_order = $key2;
- }
- }
- }
- if (($loop && !$import_GLS) || !isset($column_shipping_number) || !isset($column_id_order))
- return $this->displayError($this->l('S největší pravděpodobností se nejedná o importní soubor pro GLS'));
- foreach($data as $key=>$balik)
- {
- if ($key > 1 && isset($column_id_order) && isset($balik[$column_id_order]))
- {
- $shipping_number = str_replace('"', '', trim($balik[$column_shipping_number]));
- $id_order = str_replace('"', '', trim($balik[$column_id_order]));
- if (Configuration::get('GLS_ORDER_BY_REFERENCE'))
- {
- $reference = $id_order;
- $id_order = $this->getOrderByReference($reference);
- $message = ($key+1).'. '.$this->l('Order Reference: ').$reference;
- } else
- {
- $id_order = str_replace('"', '', trim($balik[$column_id_order]));
- $message = ($key+1).'. '.$this->l('Order ID: ').$id_order;
- }
- $order = new Order((int)$id_order);
- if (!Validate::isLoadedObject($order))
- {
- $errors[] = $this->l('No existing order number: ').$id_order;
- } else
- {
- if (!Validate::isTrackingNumber($shipping_number))
- $errors[] = $message.' - '.$this->l('Tracking number is incorrect: ').$shipping_number;
- elseif ($shipping_number == $order->shipping_number)
- $errors[] = $message.' - '.$this->l('The tracking number is alredy saved: ').$shipping_number;
- else
- {
- $order->shipping_number = $shipping_number;
- $order->update();
- $order_carrier = new OrderCarrier($this->getIdOrderCarrier($order->id));
- $order_carrier->tracking_number = pSQL($shipping_number);
- if ($order_carrier->update())
- {
- $customer = new Customer((int)$order->id_customer);
- $carrier = new Carrier((int)$order->id_carrier, $order->id_lang);
- if (!Validate::isLoadedObject($customer))
- throw new PrestaShopException('Can\'t load Customer object');
- if (!Validate::isLoadedObject($carrier))
- throw new PrestaShopException('Can\'t load Carrier object');
- $templateVars = array(
- '{followup}' => str_replace('@', $order->shipping_number, $carrier->url),
- '{firstname}' => $customer->firstname,
- '{lastname}' => $customer->lastname,
- '{id_order}' => $order->id,
- '{order_name}' => $order->getUniqReference()
- );
- if (@Mail::Send((int)$order->id_lang,
- 'in_transit',
- Mail::l('Package in transit', (int)$order->id_lang),
- $templateVars,
- $customer->email,
- $customer->firstname.' '.$customer->lastname,
- null, null, null, null,
- _PS_MAIL_DIR_,
- true,
- (int)$order->id_shop)
- )
- {
- Hook::exec('actionAdminOrdersTrackingNumberUpdate', array('order' => $order));
- if ($order->current_state != _PS_OS_SHIPPING_)
- {
- $history = new OrderHistory();
- $history->id_order = (int)$order->id;
- $history->changeIdOrderState((int)_PS_OS_SHIPPING_, (int)$order->id);
- $history->id_order_state = (int)_PS_OS_SHIPPING_;
- $history->save();
- }
- $shippingNumberSaved .= $this->l('ID order: ').$order->id.$this->l(' updated!').'<br>';
- }
- else
- $errors[] = $this->l('An error occurred while sending e-mail to the customer.');
- }
- else
- $errors[] = $this->l('Order carrier can\'t be updated');
- }
- }
- }
- }
- if (count($errors) > 0)
- {
- $display_errors = '';
- foreach($errors as $error)
- $display_errors .= $error.'<br>';
- return $this->displayError($this->l('Import finished with these errors (').count($errors).'):<br>'.$display_errors).
- $this->displayConfirmation($this->l('File was imported !').'<br><br>'.$shippingNumberSaved);
- }
- else
- return $this->displayConfirmation($this->l('File was imported !').'<br><br>'.$shippingNumberSaved);
- }
- public static function getOrderByReference($reference)
- {
- $sql = 'SELECT `id_order`
- FROM `'._DB_PREFIX_.'orders`
- WHERE `reference` = \''.$reference.'\'
- '.Shop::addSqlRestriction();
- $result = Db::getInstance()->getRow($sql);
- return isset($result['id_order']) ? $result['id_order'] : false;
- }
- public function getIdOrderCarrier($id_order)
- {
- return (int)Db::getInstance()->getValue('
- SELECT `id_order_carrier`
- FROM `'._DB_PREFIX_.'order_carrier`
- WHERE `id_order` = '.(int)$id_order);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement