private static function getInstance() { if (!self::$instance instanceof DpdGroupSearch) { self::$instance = new DpdGroupSearch(); } return self::$instance; }
public function calculate($id_method, $id_address, $parcels, Order $order = null, $extra_params = array()) { require_once _DPDGROUP_CLASSES_DIR_ . 'PostcodeSearch.php'; $address = new Address($id_address); $country = new Country($address->id_country); $street = $address->address1 . ($address->address2 ? ' ' . $address->address2 : ''); $postcode_search = new DpdGroupPostcodeSearch(); $postcode = $postcode_search->extractPostCodeForShippingRequest($address); $params = array('receiverName' => $address->firstname . ' ' . $address->lastname, 'receiverFirmName' => $address->company, 'receiverCountryCode' => $country->iso_code, 'receiverZipCode' => $address->postcode, 'receiverCity' => $address->city, 'receiverStreet' => Tools::substr($street, 0, _DPDGROUP_MAX_ADDRESS_LENGTH_ - 1), 'receiverHouseNo' => '', 'receiverPhoneNo' => $address->phone_mobile ? $address->phone_mobile : $address->phone, 'mainServiceCode' => (int) $id_method, 'shipmentReferenceNumber' => '', 'payerId' => $this->config->payer_id, 'senderAddressId' => $this->config->sender_id); if ($postcode) { $params['receiverZipCode'] = $postcode; } $params['parcels'] = $parcels; if ($order !== null) { $cod_method = Configuration::get(DpdGroupConfiguration::COD_MODULE); if ($cod_method !== null && $order->module == $cod_method) { $currency = new Currency((int) $order->id_currency); $params['additionalServices'] = array('cod' => array('amount' => $this->ps_14 ? (double) $order->total_paid : (double) $order->total_paid_tax_incl, 'currency' => $currency->iso_code, 'paymentType' => self::PAYMENT_TYPE, 'referenceNumber' => $this->ps_14 ? $order->secure_key : self::getOrderReference((int) $order->id))); } } if (!empty($extra_params['cod'])) { $params['additionalServices']['cod'] = array('amount' => (double) $extra_params['cod']['total_paid'], 'currency' => $extra_params['cod']['currency_iso_code'], 'paymentType' => self::PAYMENT_TYPE, 'referenceNumber' => $extra_params['cod']['reference']); } if (!empty($extra_params['highInsurance'])) { $params['additionalServices']['highInsurance'] = array('goodsValue' => (double) $extra_params['highInsurance']['total_paid'], 'currency' => $extra_params['highInsurance']['currency_iso_code'], 'content' => $extra_params['highInsurance']['content']); } $result = $this->calculatePrice('shipmentList', $params); if (isset($result['result'])) { $result = $result['result']; } if (!reset(self::$errors) && !reset(self::$notices)) { if ($id_currency = Currency::getIdByIsoCode($result['priceList']['price']['currency'], $this->context->shop->id)) { return array('price' => (double) $result['priceList']['price']['totalAmount'], 'id_currency' => (int) $id_currency); } else { self::$errors[] = sprintf($this->l('Currency %s is not installed, price cannot be calculated'), $result['priceList']['price']['currency']); return false; } } return false; }
', '<br />', $shipment_errors)))); } if (Tools::isSubmit('downloadModuleCSVSettings')) { include_once dirname(__FILE__) . '/controllers/Csv.controller.php'; $controller = new DpdGroupCSVController(); $controller->generateCSV(); } if (Tools::getValue('action') == 'postcode-recommendation') { require_once _DPDGROUP_CLASSES_DIR_ . 'PostcodeSearch.php'; require_once _DPDGROUP_CLASSES_DIR_ . 'Address.php'; require_once _DPDGROUP_CLASSES_DIR_ . 'Mysql.php'; require_once _DPDGROUP_CLASSES_DIR_ . 'CachedData.php'; require_once _DPDGROUP_CLASSES_DIR_ . 'PostcodeSearch.php'; $data = array(); $address = array('city' => Tools::getValue('city'), 'country_id' => Tools::getValue('id_country'), 'region_id' => Tools::getValue('id_state'), 'lang_id' => (int) Context::getContext()->language->id, 'address' => Tools::getValue('address1') . ' ' . Tools::getValue('address2')); $postcode_search = new DpdGroupPostcodeSearch(); $results = $postcode_search->findAllSimilarAddressesForAddress($address); if (!$results) { die(Tools::jsonEncode($data)); } foreach ((array) $results as $address) { $data[] = array('label' => ($address['address'] ? $address['address'] . ', ' : '') . $address['city'] . ', ' . $address['region'], 'postcode' => $address['postcode']); } die(Tools::jsonEncode($data)); } if (Tools::getValue('action') == 'validate_postcode') { $psotcode = Tools::getValue('dpdpostcode'); $result = true; require_once _DPDGROUP_CLASSES_DIR_ . 'Mysql.php'; $model = new DpdGroupDpdPostcodeMysql(); if (!DpdGroupDpdPostcodeMysql::postcodeExistsInDB($psotcode)) {