public static function getExpeditions($expedition_data = null) { $response = false; try { $sc_options = array('connection_timeout' => 30); $soap_client = new SoapClient((string) Configuration::get('SEUR_URLWS_E'), $sc_options); if (!isset($expedition_data['start_date']) || !isset($expedition_data['end_date'])) { $new_date = strtotime('-15 days', strtotime(date('Y-m-d'))); } $data = array('in0' => 'S', 'in1' => isset($expedition_data['expedition_number']) ? $expedition_data['expedition_number'] : '', 'in2' => '', 'in3' => isset($expedition_data['reference_number']) ? $expedition_data['reference_number'] : '', 'in4' => SeurLib::getMerchantField('ccc') . '-' . SeurLib::getMerchantField('franchise'), 'in5' => !isset($expedition_data['start_date']) ? date('d-m-Y', $new_date) : $expedition_data['start_date'], 'in6' => !isset($expedition_data['end_date']) ? date('d-m-Y') : $expedition_data['end_date'], 'in7' => isset($expedition_data['order_state']) ? $expedition_data['order_state'] : '', 'in8' => '', 'in9' => '', 'in10' => '', 'in11' => '0', 'in12' => Configuration::get('SEUR_WS_USERNAME'), 'in13' => Configuration::get('SEUR_WS_PASSWORD'), 'in14' => 'N'); $response = $soap_client->consultaListadoExpedicionesStr($data); if (empty($response->out)) { return false; } } catch (PrestaShopException $e) { $e->displayMessage(); } return $response; }
public function hookAdminOrder($params) { $versionSpecialClass = ''; if (!file_exists(_PS_MODULE_DIR_ . 'seur/img/logonew_32.png') && file_exists(_PS_MODULE_DIR_ . 'seur/img/logonew.png')) { ImageManager::resize(_PS_MODULE_DIR_ . 'seur/img/logonew.png', _PS_MODULE_DIR_ . 'seur/img/logonew_32.png', 32, 32, 'png'); } if (version_compare(_PS_VERSION_, '1.5', '<')) { $versionSpecialClass = 'ver14'; } $this->displayWarning(); if (Configuration::get('SEUR_Configured') == 1) { $cookie = $this->context->cookie; $token = Tools::getValue('token'); $back = Tools::safeOutput($_SERVER['REQUEST_URI']); $seur_carriers = SeurLib::getSeurCarriers(false); $ids_seur_carriers = array(); foreach ($seur_carriers as $value) { $ids_seur_carriers[] = (int) $value['id']; } $order = new Order((int) $params['id_order']); $address_saved = DB::getInstance()->getValue(' SELECT `id_address_delivery` FROM `' . _DB_PREFIX_ . 'seur_order` WHERE `id_order` = "' . (int) $order->id . '" '); if ($address_saved === '0') { $this->context->smarty->assign('pickup_point_warning', true); } if (!Validate::isLoadedObject($order)) { return false; } $delivery_price = $order_weigth = 0; $products = $order->getProductsDetail(); foreach ($products as $product) { $order_weigth += (double) $product['product_weight'] * (double) $product['product_quantity']; } $order_weigth = $order_weigth < 1.0 ? 1.0 : (double) $order_weigth; $customer = new Customer((int) $order->id_customer); $address_delivery = new Address((int) $order->id_address_delivery, (int) $cookie->id_lang); if (!Validate::isLoadedObject($address_delivery)) { return false; } $iso_country = Country::getIsoById((int) $address_delivery->id_country); if ($iso_country == 'PT') { $post_code = explode(' ', $address_delivery->postcode); $post_code = $post_code[0]; } else { $post_code = $address_delivery->postcode; } $international_orders = SeurLib::getConfigurationField('international_orders'); $date_calculate = strtotime('-14 day', strtotime(date('Y-m-d'))); $date_display = date('Y-m-d H:m:i', $date_calculate); if (strtotime($order->date_add) > strtotime($date_display) && in_array((int) $order->id_carrier, $ids_seur_carriers)) { if (!$international_orders && ($iso_country == 'ES' || $iso_country == 'PT' || $iso_country == 'AD') || $international_orders) { if (!SeurLib::getSeurOrder((int) $order->id)) { SeurLib::setSeurOrder((int) $order->id, 1, $order_weigth, null); } elseif (Tools::getValue('numBultos') && Tools::getValue('pesoBultos')) { SeurLib::setSeurOrder((int) $order->id, (int) Tools::getValue('numBultos'), str_replace(',', '.', Tools::getValue('pesoBultos')), null); } $order_data = SeurLib::getSeurOrder((int) $order->id); $response_post_code = Town::getTowns($post_code); $order_weigth = (double) $order_weigth != $order_data['peso_bultos'] ? (double) $order_data['peso_bultos'] : (double) $order_weigth; if (is_object($response_post_code)) { $towns = array(); $num = (int) $response_post_code->attributes()->NUM[0]; for ($i = 1; $i <= $num; $i++) { $name = 'REG' . $i; $towns[] = utf8_decode((string) $response_post_code->{$name}->NOM_POBLACION); } } $name = $address_delivery->firstname . ' ' . $address_delivery->lastname; $direccion = $address_delivery->address1 . ' ' . $address_delivery->address2; $newcountry = new Country((int) $address_delivery->id_country, (int) $cookie->id_lang); $iso_merchant = SeurLib::getMerchantField('country'); $rate_data = array('town' => $address_delivery->city, 'peso' => (double) $order_weigth, 'post_code' => $post_code, 'bultos' => $order_data['numero_bultos'], 'ccc' => SeurLib::getMerchantField('ccc'), 'franchise' => SeurLib::getMerchantField('franchise'), 'iso' => $newcountry->iso_code, 'iso_merchant' => $iso_merchant, 'id_employee' => $cookie->id_employee, 'token' => Tools::getAdminTokenLite('AdminOrders'), 'back' => $back); $order_messages_str = ''; $info_adicional_str = $address_delivery->other; $order_messages = Message::getMessagesByOrderId((int) $params['id_order']); if (is_array($order_messages)) { foreach ($order_messages as $order_messag_tmp) { $order_messages_str .= "\n" . $order_messag_tmp['message']; } if (substr_count($order_messages_str, "\n") > 5) { $order_messages_str = str_replace(array("\r", "\n"), ' | ', $order_messages_str); } if (Tools::strlen($order_messages_str) > 250) { $order_messages_str = Tools::substr($order_messages_str, 0, 247) . '...'; } $order_messages_str = trim($order_messages_str); } if (!empty($order_messages_str)) { $info_adicional_str = $order_messages_str; } $label_data = array('pedido' => sprintf('%06d', (int) $order->id), 'total_bultos' => $order_data['numero_bultos'], 'total_kilos' => (double) $order_weigth, 'direccion_consignatario' => $direccion, 'consignee_town' => $address_delivery->city, 'codPostal_consignatario' => $post_code, 'telefono_consignatario' => !empty($address_delivery->phone_mobile) ? $address_delivery->phone_mobile : $address_delivery->phone, 'movil' => $address_delivery->phone_mobile, 'name' => $name, 'companyia' => !empty($address_delivery->company) ? $address_delivery->company : '', 'email_consignatario' => Validate::isLoadedObject($customer) ? $customer->email : '', 'dni' => $address_delivery->dni, 'info_adicional' => $info_adicional_str, 'country' => $newcountry->name, 'iso' => $newcountry->iso_code, 'iso_merchant' => $iso_merchant, 'admin_dir' => utf8_encode(_PS_ADMIN_DIR_), 'id_employee' => $cookie->id_employee, 'token' => Tools::getAdminTokenLite('AdminOrders'), 'back' => $back); if (strcmp($order->module, 'seurcashondelivery') == 0) { $rate_data['reembolso'] = (double) $order->total_paid; $label_data['reembolso'] = (double) $order->total_paid; } $carrier_pos = SeurLib::getSeurCarrier('SEP'); $datospos = ''; if ((int) $order->id_carrier == $carrier_pos['id']) { $datospos = SeurLib::getOrderPos((int) $order->id_cart); if (!empty($datospos)) { $label_data = array('pedido' => sprintf('%06d', (int) $order->id), 'total_bultos' => $order_data['numero_bultos'], 'total_kilos' => (double) $order_weigth, 'direccion_consignatario' => $direccion, 'consignee_town' => $datospos['city'], 'codPostal_consignatario' => $datospos['postal_code'], 'telefono_consignatario' => !empty($address_delivery->phone_mobile) ? $address_delivery->phone_mobile : $address_delivery->phone, 'movil' => $address_delivery->phone_mobile, 'name' => $name, 'companyia' => $datospos['company'], 'email_consignatario' => Validate::isLoadedObject($customer) ? $customer->email : '', 'dni' => $address_delivery->dni, 'info_adicional' => $info_adicional_str, 'country' => $newcountry->name, 'iso' => $newcountry->iso_code, 'cod_centro' => $datospos['id_seur_pos'], 'iso_merchant' => $iso_merchant); $rate_data['cod_centro'] = $datospos['id_seur_pos']; } } if ($iso_country == 'ES' || $iso_country == 'PT' || $iso_country == 'AD') { $xml = Rate::getPrivateRate($rate_data); if (is_object($xml)) { foreach ($xml as $tarifa) { $delivery_price += (double) $tarifa->VALOR; } } } if (Tools::getValue('submitLabel')) { if ($this->isPrinted((int) $order->id)) { $success = true; } else { $success = Label::createLabels($label_data, 'pdf'); } if ($success === true) { if (!$this->setAsPrinted((int) $order->id)) { $this->context->smarty->assign('error', $this->l('Could not set printed value for this order')); } else { $this->printLabel((int) $order->id, 'pdf'); } } else { $this->context->smarty->assign('error', $success); } } if (Tools::getValue('submitPrint')) { if ($this->isPrinted((int) $order->id, true)) { $success = true; } else { $success = Label::createLabels($label_data, 'zebra'); } if ($success === true) { if (!$this->setAsPrinted((int) $order->id, true)) { $this->context->smarty->assign('error', $this->l('Could not set printed value for this order')); } else { $this->printLabel((int) $order->id, 'txt'); } } else { $this->context->smarty->assign('error', $success); } } $seur_carriers = SeurLib::getSeurCarriers(false); $pickup = Pickup::getLastPickup(); if (!empty($pickup)) { $pickup_date = explode(' ', $pickup['date']); $pickup_date = $pickup_date[0]; } $address_error = 0; if (!empty($towns) && !in_array(mb_strtoupper($this->replaceAccentedChars($address_delivery->city), 'UTF-8'), $towns)) { $address_error = 1; } $pickup_s = 0; if ($pickup && strtotime(date('Y-m-d')) == strtotime($pickup_date)) { $pickup_s = 1; } $state = Expedition::getExpeditions(array('reference_number' => sprintf('%06d', (int) $order->id))); $is_empty_state = false; $xml_s = false; if (!empty($state->out)) { $is_empty_state = true; } else { $string_xml = htmlspecialchars_decode($state->out); $string_xml = str_replace('&', '& ', $string_xml); $xml_s = simplexml_load_string($string_xml); } $rate_data_ajax = Tools::jsonEncode($rate_data); $path = '../modules/seur/js/'; $file = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/seur/files/deliveries_labels/' . sprintf('%06d', (int) $order->id) . '.txt'; $filePath = _PS_MODULE_DIR_ . 'seur/files/deliveries_labels/' . sprintf('%06d', (int) $order->id) . '.txt'; $label_data['file'] = $file; $this->context->smarty->assign(array('path' => $this->_path, 'request_uri' => $_SERVER['REQUEST_URI'], 'module_instance' => $this, 'address_error' => $address_error, 'address_error_message' => $this->l('Addressess error, please check the customer address.'), 'pickup_s' => $pickup_s, 'pickup' => $pickup, 'isEmptyState' => $is_empty_state, 'xml' => $xml_s, 'order_data' => $order_data, 'iso_country' => $iso_country, 'order_weigth' => $order_weigth, 'delivery_price' => $delivery_price, 'rate_data_ajax' => $rate_data_ajax, 'js_path' => $path, 'token' => $token, 'order' => $order, 'label_data' => $label_data, 'fileExists' => file_exists($filePath), 'file' => $file, 'datospos' => $datospos, 'versionSpecialClass' => $versionSpecialClass, 'configured' => (int) Configuration::get('SEUR_Configured'), 'printed' => (bool) ($this->isPrinted((int) $order->id) || $this->isPrinted((int) $order->id, true)))); return $this->display(__FILE__, 'views/templates/admin/orders.tpl'); } } } else { $this->context->smarty->assign(array('configured' => Configuration::get('SEUR_Configured'), 'path' => $this->_path, 'configuration_warning_message' => $this->l('Please, first configure your SEUR module as a merchant.'))); return $this->display(__FILE__, 'views/templates/admin/orders.tpl'); } }
private static function createStates() { $ps_state_iso_code_max_length = 7; if (version_compare(_PS_VERSION_, '1.5', '<')) { $ps_state_iso_code_max_length = 4; } foreach (SeurLib::$baleares_states as $iso_code => $state_name) { if (Tools::strlen($iso_code) > $ps_state_iso_code_max_length) { $tmpArray = explode('-', $iso_code); $iso_code = $tmpArray[0]; if (count($tmpArray) > 0) { $iso_code = 'E' . $tmpArray[1]; } } $exists_id = State::getIdByIso($iso_code); if (isset($exists_id) && !empty($exists_id)) { $state = new State($exists_id); $state->active = true; $state->id_zone = self::$baleares->id; if (!$state->update()) { return false; } } else { $state = new State(); $state->name = $state_name; $state->id_country = self::$spain->id; $state->id_zone = self::$baleares->id; $state->iso_code = $iso_code; $state->active = true; if (!$state->save()) { return false; } } } foreach (SeurLib::$canarias_states as $iso_code => $state_name) { if (Tools::strlen($iso_code) > $ps_state_iso_code_max_length) { $tmpArray = explode('-', $iso_code); $iso_code = $tmpArray[0]; if (count($tmpArray) > 0) { $iso_code = 'E' . $tmpArray[1]; } } $exists_id = State::getIdByIso($iso_code); if (isset($exists_id) && !empty($exists_id)) { $state = new State($exists_id); $state->active = true; $state->id_zone = self::$canarias->id; if (!$state->update()) { return false; } } else { $state = new State(); $state->name = $state_name; $state->id_country = self::$spain->id; $state->id_zone = self::$canarias->id; $state->iso_code = $iso_code; $state->active = true; if (!$state->save()) { return false; } } } foreach (SeurLib::$ceuta_melilla_states as $iso_code => $state_name) { if (Tools::strlen($iso_code) > $ps_state_iso_code_max_length) { $tmpArray = explode('-', $iso_code); $iso_code = $tmpArray[0]; if (count($tmpArray) > 0) { $iso_code = 'E' . $tmpArray[1]; } } $exists_id = State::getIdByIso($iso_code); if (isset($exists_id) && !empty($exists_id)) { $state = new State($exists_id); $state->id_zone = self::$ceuta_melilla->id; $state->active = true; if (!$state->update()) { return false; } } else { $state = new State(); $state->name = $state_name; $state->id_country = self::$spain->id; $state->id_zone = self::$ceuta_melilla->id; $state->iso_code = $iso_code; $state->active = true; if (!$state->save()) { return false; } } } foreach (SeurLib::$spain_states as $iso_code => $state_name) { if (Tools::strlen($iso_code) > $ps_state_iso_code_max_length) { $tmpArray = explode('-', $iso_code); $iso_code = $tmpArray[0]; if (count($tmpArray) > 0) { $iso_code = 'E' . $tmpArray[1]; } } $exists_id = State::getIdByIso($iso_code); if (isset($exists_id) && !empty($exists_id)) { $state = new State($exists_id); $state->active = true; if (Tools::strtoupper($state_name) == Tools::strtoupper(SeurLib::getMerchantField('state'))) { $state->id_zone = self::$provincia->id; } else { $state->id_zone = self::$peninsula->id; } if (!$state->update()) { return false; } } else { $state = new State(); $state->name = $state_name; $state->id_country = self::$spain->id; if (Tools::strtoupper($state_name) == Tools::strtoupper(SeurLib::getMerchantField('state'))) { $state->id_zone = self::$provincia->id; } else { $state->id_zone = self::$peninsula->id; } $state->iso_code = $iso_code; $state->active = true; if (!$state->save()) { return false; } } } return true; }