private function getPriceByWebServicesCalculationType(Cart $cart, $is_cod_method, $order_total_price, $id_method, $id_address_delivery, $additional_shipping_cost, $handling_charges, DpdGroupConfiguration $configuration, $price_rule, $products) { $shipment = new DpdGroupShipment(); $cart_products = empty($products) ? $cart->getProducts() : $products; if (!self::$parcels) { self::$parcels = $shipment->putProductsToParcels($cart_products); } $extra_params = array(); if ($is_cod_method) { $extra_params['cod'] = array('total_paid' => $order_total_price, 'currency_iso_code' => $this->context->currency->iso_code, 'reference' => (int) $this->context->cart->id); } $product_names = ''; if (count($cart_products)) { foreach ($cart_products as $product) { $product_names .= '|' . $product['name']; } } $extra_params['highInsurance'] = array('total_paid' => $order_total_price, 'currency_iso_code' => $this->context->currency->iso_code, 'content' => $product_names); $result = $shipment->calculate($id_method, $id_address_delivery, self::$parcels, null, $extra_params); if ($result === false || !isset($result['price']) || !isset($result['id_currency'])) { return false; } $result_price_in_default_currency = Tools::convertPrice($result['price'], new Currency((int) $result['id_currency']), false); $result['price'] = Tools::convertPrice($result_price_in_default_currency); $result['price'] += $additional_shipping_cost + $handling_charges; if (!empty($price_rule)) { if ($price_rule['shipping_price_percentage'] !== '') { $surcharge = $result['price'] * $price_rule['shipping_price_percentage'] / 100; $result['price'] += $surcharge; } if ($is_cod_method && $price_rule['cod_surcharge'] !== '') { $result['price'] += $this->convertPriceByCurrency($price_rule['cod_surcharge'], $price_rule['currency']); } elseif ($is_cod_method && $price_rule['cod_surcharge_percentage'] !== '') { $percentage_starting_price = $configuration->cod_percentage_calculation == DpdGroupConfiguration::COD_PERCENTAGE_CALCULATION_CART ? $order_total_price : $order_total_price + $result['price']; $result['price'] += $this->calculateCODSurchargePercentage($percentage_starting_price, $price_rule['cod_surcharge_percentage'], $price_rule['cod_min_surcharge'], $price_rule['currency']); } } return $result['price']; }
private function deleteCSV() { if (DpdGroupCSV::deleteAllData()) { DpdGroup::addFlashMessage($this->l('Price rules deleted successfully')); Tools::redirectAdmin($this->module_instance->module_url . '&menu=csv'); } else { DpdGroup::addFlashError($this->l('Price rules could not be deleted')); } }
public static function saveConfiguration() { $settings_data = self::getSettingsData(); $success = true; foreach (array_keys($settings_data) as $name) { $success &= Configuration::updateValue($name, Tools::getValue($name)); } $payment_module_selected = ''; foreach (DpdGroup::getPaymentModules() as $payment_module) { if (Tools::getValue($payment_module['name'])) { $payment_module_selected = $payment_module['name']; } } $success &= Configuration::updateValue(self::COD_MODULE, $payment_module_selected); return $success; }
public function getShipmentList() { $keys_array = array('id_shipment', 'date_shipped', 'id_order', 'date_add', 'carrier', 'customer', 'quantity', 'manifest', 'label', 'date_pickup'); if (Tools::isSubmit('submitFilterButtonShipments')) { foreach ($_POST as $key => $value) { if (strpos($key, 'ShipmentsFilter_') !== false) { if (is_array($value)) { $this->context->cookie->{$key} = Tools::jsonEncode($value); } else { $this->context->cookie->{$key} = $value; } } } } if (Tools::isSubmit('submitResetShipments')) { foreach ($keys_array as $key) { if ($this->context->cookie->__isset('ShipmentsFilter_' . $key)) { $this->context->cookie->__unset('ShipmentsFilter_' . $key); unset($_POST['ShipmentsFilter_' . $key]); } } } $page = (int) Tools::getValue('submitFilterShipments'); if (!$page) { $page = 1; } $selected_pagination = (int) Tools::getValue('pagination', $this->pagination[0]); $start = $selected_pagination * $page - $selected_pagination; $order_by = Tools::getValue('ShipmentOrderBy', self::DEFAULT_ORDER_BY); $order_way = Tools::getValue('ShipmentOrderWay', self::DEFAULT_ORDER_WAY); $filter = $this->getFilterQuery($keys_array, 'Shipments'); $shipment = new DpdGroupShipment(); $shipments = $shipment->getShipmentList($order_by, $order_way, $filter, $start, $selected_pagination); $list_total = count($shipment->getShipmentList($order_by, $order_way, $filter, null, null)); $total_pages = ceil($list_total / $selected_pagination); if (!$total_pages) { $total_pages = 1; } $shipments_count = count($shipments); for ($i = 0; $i < $shipments_count; $i++) { $order = new Order((int) $shipments[$i]['id_order']); $carrier = new Carrier((int) $order->id_carrier, $order->id_lang); $shipments[$i]['carrier_url'] = $carrier->url; } $this->context->smarty->assign(array('full_url' => $this->module_instance->module_url . '&menu=shipment_list&ShipmentOrderBy=' . $order_by . '&ShipmentOrderWay=' . $order_way, 'employee' => $this->context->employee, 'shipments' => $shipments, 'page' => $page, 'selected_pagination' => $selected_pagination, 'pagination' => $this->pagination, 'total_pages' => $total_pages, 'list_total' => $list_total, 'order_by' => $order_by, 'order_way' => $order_way, 'order_link' => DpdGroup::getAdminOrderLink())); $template_filename = version_compare(_PS_VERSION_, '1.6', '>=') ? 'shipment_list_16' : 'shipment_list'; return $this->context->smarty->fetch(_DPDGROUP_TPL_DIR_ . 'admin/' . $template_filename . '.tpl'); }
private function saveSettings() { if (DpdGroupConfiguration::saveConfiguration()) { DpdGroup::addFlashMessage($this->l('Settings saved successfully')); Tools::redirectAdmin($this->module_instance->module_url . '&menu=configuration'); } else { DpdGroup::addFlashError($this->l('Could not save settings')); } }
public static function init() { $controller = new DpdGroupPostcodeController(); if (Tools::isSubmit(DpdGroupPostcodeController::SETTINGS_SAVE_POSTCODE_ACTION)) { $csv_data = $controller->readCSVData(); if ($csv_data === false) { DpdGroup::addFlashError($controller->l('Wrong CSV file')); Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode'); } $message = $controller->validatePostcodeData($csv_data); if ($message !== true) { return $controller->module_instance->outputHTML($controller->module_instance->displayError(implode('<br />', $message))); } if ($controller->saveCSVData($csv_data)) { DpdGroup::addFlashMessage($controller->l('CSV data was successfully saved')); Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode'); } else { DpdGroup::addFlashError($controller->l('CSV data could not be saved')); Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode'); } } if (Tools::isSubmit(DpdGroupPostcodeController::SETTINGS_DOWNLOAD_POSTCODE_ACTION)) { $controller->generateCSV(); } if (Tools::isSubmit('submitBulkdeletepostcode')) { $postcodes_ids = Tools::getValue('postcodeBox'); if (empty($postcodes_ids)) { DpdGroup::addFlashError($controller->l('No postcodes selected')); Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode'); } $errors = array(); foreach ($postcodes_ids as $id_postcode) { $postcode = new DpdGroupPostcode((int) $id_postcode); if (!$postcode->delete()) { $errors[] = $controller->l('Could not delete postcode, #') . (int) $id_postcode; } } if (empty($errors)) { DpdGroup::addFlashMessage($controller->l('Selected postcodes deleted successfully')); Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode'); } else { DpdGroup::addFlashError(implode('<br />', $errors)); Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode'); } } if (Tools::isSubmit('delete_postcode')) { $postcode = new DpdGroupPostcode((int) Tools::getValue('id_postcode')); if ($postcode->delete()) { DpdGroup::addFlashMessage($controller->l('Postcode was deleted successfully')); Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode'); } else { DpdGroup::addFlashError($controller->l('Could not delete postcode')); Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode'); } } if (Tools::isSubmit(self::SETTINGS_DELETE_POSTCODE_ACTION)) { $postcode = new DpdGroupPostcode(); if ($postcode->deleteAllData()) { DpdGroup::addFlashMessage($controller->l('All postcodes deleted successfully')); Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode'); } else { DpdGroup::addFlashError($controller->l('Could not delete all postcodes')); Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode'); } } if (Tools::isSubmit(self::SETTINGS_RESTORE_POSTCODE_ACTION)) { $postcode = new DpdGroupPostcode(); if (!$postcode->deleteAllData()) { DpdGroup::addFlashError($controller->l('Could not delete all postcodes')); Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode'); } $sql = array(); $postcodes = Tools::file_get_contents(_DPDGROUP_SQL_DIR_ . 'data.sql'); $postcodes = str_replace('zitec_dpd_postcodes', _DB_PREFIX_ . _DPDGROUP_POSTCODE_DB_, $postcodes); $postcodes = explode(';', $postcodes); foreach ($postcodes as $query) { if ($query) { $sql[] = $query . ';'; } } foreach ($sql as $query) { if (Db::getInstance()->execute($query) == false) { DpdGroup::addFlashError($controller->l('Could not restore default postcodes data')); Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode'); } } DpdGroup::addFlashMessage($controller->l('Default postcodes data restored successfully')); Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode'); } return null; }