* @copyright 2018 Sakis Gkiokas * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3 */ if (!defined('_PS_VERSION_')) { exit; } if (!defined('_PS_PRICE_COMPUTE_PRECISION_')) { define('_PS_PRICE_COMPUTE_PRECISION_', _PS_PRICE_DISPLAY_PRECISION_); } //use PrestaShop\PrestaShop\Core\Payment\PaymentOption; include_once _PS_MODULE_DIR_ . 'codwfeeplus/CODwFP.php'; class codwfeeplus extends PaymentModule { private $_html = ''; private $_postErrors = array(); public $_testoutput = ''; public $_testoutput_check = ''; public $_testoutput_applyfee = ''; public $_testoutput_method_active = true; public $_cond_integration = 0; public $_cond_orderstate = 0; public $_cond_taxrule = 0; public $_updatestatus = array( 'res' => '', 'cur_version' => '', 'download_link' => '', 'info_link' => '', 'github_link' => '', ); public $public_name = ''; private $tab_name = ''; private $_integration_general_arr = array(); private $_integration_condition_arr = array(); private $tmp_shop_context_type = Shop::CONTEXT_ALL; private $tmp_shop_context_id = 0; private $_newProductId = 0; public $is17 = false; public function __construct() { if (Tools::version_compare(_PS_VERSION_, '1.7.0', '>=')) { $this->is17 = true; } $this->name = 'codwfeeplus'; $this->tab = 'payments_gateways'; $this->version = '1.1.8'; $this->author = 'Sakis Gkiokas'; $this->need_instance = 1; if ($this->is17) { $this->controllers = array('validation', 'ajax'); } else { $this->controllers = array('validation'); } $this->is_eu_compatible = 1; $this->secure_key = Tools::encrypt($this->name); $this->currencies = true; // $this->currencies_mode = 'radio'; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Cash on delivery with fee (COD) PLUS'); $this->description = $this->l('Accept cash on delivery payments with extra fee and more options'); $this->ps_versions_compliancy = array('min' => '1.6.0.6', 'max' => '1.7.99.99'); $this->public_name = $this->l('Cash on delivery'); $this->tab_name = $this->l('COD with Fee Plus'); $this->_integration_general_arr = array( 0 => 'defined by first successful condition', 1 => 'add to carrier\'s fee', 2 => 'add a COD product to the order', ); $this->_integration_condition_arr = array( 0 => 'add to carrier\'s fee', 1 => 'add a COD product to the order', ); if (!$this->getProductStatus()) { $this->warning = $this->l('COD Product was not found.'); } } public function installTab($parent, $class_name, $name) { // Create new admin tab $tab = new Tab(); $tab->id_parent = (int) Tab::getIdFromClassName($parent); $tab->name = array(); foreach (Language::getLanguages(true) as $lang) { $tab->name[$lang['id_lang']] = $this->getTranslation($name, $lang['iso_code']); } $tab->class_name = $class_name; $tab->module = $this->name; $tab->active = 1; return $tab->add(); } public function uninstallTab($class_name) { // Retrieve Tab ID $id_tab = (int) Tab::getIdFromClassName($class_name); // Load tab $tab = new Tab((int) $id_tab); // Delete it return $tab->delete(); } public function install() { $tab_parent = 'AdminParentModules'; if ($this->is17) { $tab_parent = 'AdminParentPayment'; } if (Shop::isFeatureActive()) { Shop::setContext(Shop::CONTEXT_ALL); } if (!parent::install() or ! $this->createTables() or ! $this->installTab($tab_parent, 'AdminCODwFeePlus', 'COD with Fee Plus') or ! $this->registerHook('payment') or ! $this->registerHook('paymentReturn') or ! $this->registerHook('updateCarrier') or ! $this->registerHook('header') or ! $this->registerHook('PaymentOptions') or ! Configuration::updateValue('SG_CODWFEEPLUS_BEHAVIOUR', 0) or ! Configuration::updateValue('SG_CODWFEEPLUS_KEEPTRANSACTIONS', 1) or ! Configuration::updateValue('SG_CODWFEEPLUS_INTEGRATION_WAY', 0) or ! Configuration::updateValue('SG_CODWFEEPLUS_ORDERSTATE', Configuration::get('PS_OS_PREPARATION')) or ! Configuration::updateValue('SG_CODWFEEPLUS_PRODUCT_ID', 0) or ! Configuration::updateValue('SG_CODWFEEPLUS_PRODUCT_REFERENCE', 'COD') or ! Configuration::updateValue('SG_CODWFEEPLUS_AUTO_UPDATE', 0) or ! Configuration::updateValue('SG_CODWFEEPLUS_INFO_LINK', 'https://sakgiok.gr/programs/codwfeeplus/') or ! Configuration::updateValue('SG_CODWFEEPLUS_GITHUB_LINK', 'https://github.com/sakgiok/codwfeeplus') or ! Configuration::updateValue('SG_CODWFEEPLUS_LOGO_FILENAME_17', 'codwfeeplus_logo_17.png') or ! Configuration::updateValue('SG_CODWFEEPLUS_LOGO_ENABLED', 0) or ! $this->installMultiLangParameters() or ! $this->installCODProduct() ) { return false; } return true; } public function uninstall() { if (Shop::isFeatureActive()) { Shop::setContext(Shop::CONTEXT_ALL); } if (!$this->removeCODProduct() or ! $this->deleteTables() or ! Configuration::deleteByName('SG_CODWFEEPLUS_BEHAVIOUR') or ! Configuration::deleteByName('SG_CODWFEEPLUS_KEEPTRANSACTIONS') or ! Configuration::deleteByName('SG_CODWFEEPLUS_INTEGRATION_WAY') or ! Configuration::deleteByName('SG_CODWFEEPLUS_ORDERSTATE') or ! Configuration::deleteByName('SG_CODWFEEPLUS_PRODUCT_ID') or ! Configuration::deleteByName('SG_CODWFEEPLUS_PRODUCT_TITLE') or ! Configuration::deleteByName('SG_CODWFEEPLUS_PRODUCT_REFERENCE') or ! Configuration::deleteByName('SG_CODWFEEPLUS_AUTO_UPDATE') or ! Configuration::deleteByName('SG_CODWFEEPLUS_INFO_LINK') or ! Configuration::deleteByName('SG_CODWFEEPLUS_GITHUB_LINK') or ! Configuration::deleteByName('SG_CODWFEEPLUS_LOGO_FILENAME_17') or ! Configuration::deleteByName('SG_CODWFEEPLUS_LOGO_ENABLED') or ! $this->uninstallTab('AdminCODwFeePlus') or ! parent::uninstall()) { return false; } return true; } public function getContent() { $link = $this->context->link->getAdminLink('AdminCODwFeePlus', true); Tools::redirectAdmin($link); } public function storeContextShop() { if (Shop::isFeatureActive()) { $this->tmp_shop_context_type = Shop::getContext(); if ($this->tmp_shop_context_type != Shop::CONTEXT_ALL) { if ($this->tmp_shop_context_type == Shop::CONTEXT_GROUP) { $this->tmp_shop_context_id = Shop::getContextShopGroupID(); } else { $this->tmp_shop_context_id = Shop::getContextShopID(); } } } } public function resetContextShop() { if (Shop::isFeatureActive()) { if ($this->tmp_shop_context_type != Shop::CONTEXT_ALL) { Shop::setContext($this->tmp_shop_context_type, $this->tmp_shop_context_id); } else { Shop::setContext($this->tmp_shop_context_type); } } } private function installCODProduct_loop() { $res = true; $p = new Product(null, false, Configuration::get('PS_LANG_DEFAULT')); $p->reference = Configuration::get('SG_CODWFEEPLUS_PRODUCT_REFERENCE'); $p->name = 'cod product'; $p->is_virtual = false; $p->indexed = 0; $p->id_category_default = Configuration::get('PS_HOME_CATEGORY'); $p->link_rewrite = 'pr-codwfeeplus'; $res &= $p->save(); $res &= $p->addToCategories(array(Configuration::get('PS_HOME_CATEGORY'))); $res &= Configuration::updateValue('SG_CODWFEEPLUS_PRODUCT_ID', $p->id); $this->_newProductId = $p->id; return $res; } public function installCODProduct() { $this->removeCODProduct(); $this->storeContextShop(); if (Shop::isFeatureActive()) { Shop::setContext(Shop::CONTEXT_ALL); } $res = true; $res &= $this->installCODProduct_loop(); if (Shop::isFeatureActive()) { $shop_list = Shop::getShops(true, null, true); foreach ($shop_list as $value) { Shop::setContext(Shop::CONTEXT_SHOP, $value); $res &= Configuration::updateValue('SG_CODWFEEPLUS_PRODUCT_ID', $this->_newProductId); $res &= $this->updateCODProduct(1.0); } } else { $res &= $this->updateCODProduct(1.0); } $this->resetContextShop(); return $res; } public function addCODProductToCart($cart) { $cod_product_id = (int) Configuration::get('SG_CODWFEEPLUS_PRODUCT_ID'); $cart->updateQty(1, $cod_product_id); $cart->update(); } public function removeCODProductFromCart($cart) { $cod_product_id = (int) Configuration::get('SG_CODWFEEPLUS_PRODUCT_ID'); $cod_product = $cart->getProducts(false, $cod_product_id); if (!empty($cod_product)) { $q = (int) $cod_product[0]['quantity']; $cart->updateQty($q, $cod_product_id, null, false, 'down'); $cart->update(); } } private function updateCODProduct_Loop($price = null, $id_tax_rules_group = 0) { $ret = true; if ($this->is17) { Configuration::loadConfiguration(); } $p = new Product((int) Configuration::get('SG_CODWFEEPLUS_PRODUCT_ID')); $pname = array(); $plink_rewrite = array(); foreach (Language::getLanguages(true) as $lang) { $pname[$lang['id_lang']] = Configuration::get('SG_CODWFEEPLUS_PRODUCT_TITLE', (int) $lang['id_lang']); $plink_rewrite[$lang['id_lang']] = 'pr-codwfeeplus'; } $p->name = $pname; $p->description = $pname; $p->description_short = $pname; $p->reference = Configuration::get('SG_CODWFEEPLUS_PRODUCT_REFERENCE'); $p->active = false; $p->visibility = 'none'; $p->minimal_quantity = 1; $p->available_for_order = true; $p->link_rewrite = $plink_rewrite; $p->id_tax_rules_group = $id_tax_rules_group; $p->redirect_type = '404'; //Only for a specific customization of a module I made if (isset($p->skroutz_available)) { $p->skroutz_available = 0; } /// if ($price != null) { $tax = ((float) $p->getTaxesRate()) * 0.01; $price_notax = Tools::ps_round((float) $price / (1.0 + $tax), 9); $found = null; if ($this->context->currency->id != Configuration::get('PS_CURRENCY_DEFAULT')) { $sp_array = SpecificPrice::getByProductId($p->id); if ($sp_array && count($sp_array)) { foreach ($sp_array as $value) { if ($value['id_currency'] == $this->context->currency->id) { $found = $value['id_specific_price']; } } } $s = new SpecificPrice($found); $s->price = $price_notax; $s->id_product = $p->id; $s->id_currency = $this->context->currency->id; $s->id_shop = 0; $s->id_country = 0; $s->id_customer = 0; $s->id_group = 0; $s->id_product_attribute = 0; $s->id_shop_group = 0; $s->from_quantity = 1; $s->reduction = 0; $s->reduction_type = 'amount'; $s->from = 0; $s->to = 0; $s->save(); unset($s); } else { $p->price = $price_notax; } } $p->quantity = 100; // if (Shop::isFeatureActive()) { // $p->id_shop_list = Shop::getShops(true, null, true); // } $ret &= $p->save(); if (StockAvailable::getQuantityAvailableByProduct($p->id) < 100) { StockAvailable::setQuantity($p->id, 0, 100); StockAvailable::setProductOutOfStock($p->id, true); } return $ret; } public function updateCODProduct($price = null, $id_tax_rules_group = 0) { if (!((int) Configuration::get('SG_CODWFEEPLUS_PRODUCT_ID'))) { return false; } $ret = true; $ret &= $this->updateCODProduct_Loop($price, $id_tax_rules_group); return $ret; } public function removeCODProduct() { $this->storeContextShop(); $ret = true; if (Shop::isFeatureActive()) { $shop_list = Shop::getShops(true, null, true); foreach ($shop_list as $value) { Shop::setContext(Shop::CONTEXT_SHOP, $value); $cod_product_id = Configuration::get('SG_CODWFEEPLUS_PRODUCT_ID'); if ($cod_product_id != '0') { $p = new Product((int) $cod_product_id); $p->delete(); unset($p); } $ret &= Configuration::updateValue('SG_CODWFEEPLUS_PRODUCT_ID', 0); } Shop::setContext(Shop::CONTEXT_ALL); } $cod_product_id = Configuration::get('SG_CODWFEEPLUS_PRODUCT_ID'); if ($cod_product_id != '0') { $p = new Product((int) $cod_product_id); $p->delete(); unset($p); } $ret &= Configuration::updateValue('SG_CODWFEEPLUS_PRODUCT_ID', 0); $this->resetContextShop(); return $ret; } private function getProductStatus_Loop() { $p_exists = true; $p_id = Configuration::get('SG_CODWFEEPLUS_PRODUCT_ID'); $p = new Product((int) $p_id); $p_exists &= $p->existsInDatabase($p_id, 'product'); if ($p_exists) { foreach (Language::getLanguages(true) as $lang) { if (array_key_exists($lang['id_lang'], $p->name)) { $p_exists &= ($p->name[$lang['id_lang']] == Configuration::get('SG_CODWFEEPLUS_PRODUCT_TITLE', (int) $lang['id_lang'])); } else { $p_exists &= false; } } } // $p_exists &= ($p->reference == Configuration::get('SG_CODWFEEPLUS_PRODUCT_REFERENCE')); return $p_exists; } public function getProductStatus() { if (!((int) Configuration::get('SG_CODWFEEPLUS_PRODUCT_ID'))) { return false; } $ret = true; $ret &= $this->getProductStatus_Loop(); return $ret; } public function installMultiLangParameters() { $ret = true; $title = array(); $desc = array(); $desc_short = array(); foreach (Language::getLanguages(true) as $lang) { if ($lang['iso_code'] == 'el') { $title[$lang['id_lang']] = 'Χρέωση Αντικαταβολής'; } else { $title[$lang['id_lang']] = 'Cash on Delivery Fee'; } } $ret &= Configuration::updateValue('SG_CODWFEEPLUS_PRODUCT_TITLE', $title); return $ret; } public function createTables() { /* Conditions */ $ret = Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'codwfeeplus_conditions` ( `id_codwfeeplus_cond` int(10) unsigned NOT NULL AUTO_INCREMENT, `codwfeeplus_fee` DECIMAL(13, 4) NOT NULL DEFAULT \'0\', `codwfeeplus_fee_min` DECIMAL(13, 4) NOT NULL DEFAULT \'0\', `codwfeeplus_fee_max` DECIMAL(13, 4) NOT NULL DEFAULT \'0\', `codwfeeplus_fee_percent` DECIMAL(13, 4) NOT NULL DEFAULT \'0\', `codwfeeplus_fee_type` int(2) unsigned NOT NULL DEFAULT \'0\', `codwfeeplus_integration` int(2) unsigned NOT NULL DEFAULT \'0\', `codwfeeplus_taxrule_id` int(2) unsigned NOT NULL DEFAULT \'0\', `codwfeeplus_orderstate_id` int(2) unsigned NOT NULL DEFAULT \'0\', `codwfeeplus_active` tinyint(1) unsigned NOT NULL DEFAULT \'0\', `codwfeeplus_condtype` tinyint(1) unsigned NOT NULL DEFAULT \'0\', `codwfeeplus_fee_percent_include_carrier` tinyint(1) unsigned NOT NULL DEFAULT \'0\', `codwfeeplus_cartvalue_include_carrier` tinyint(1) unsigned NOT NULL DEFAULT \'0\', `codwfeeplus_position` int(10) unsigned NOT NULL, `codwfeeplus_countries` TEXT, `codwfeeplus_states` TEXT, `codwfeeplus_carriers` TEXT, `codwfeeplus_zones` TEXT, `codwfeeplus_manufacturers` TEXT, `codwfeeplus_matchall_manufacturers` tinyint(1) unsigned NOT NULL DEFAULT \'0\', `codwfeeplus_suppliers` TEXT, `codwfeeplus_matchall_suppliers` tinyint(1) unsigned NOT NULL DEFAULT \'0\', `codwfeeplus_categories` TEXT, `codwfeeplus_matchall_categories` tinyint(1) unsigned NOT NULL DEFAULT \'0\', `codwfeeplus_groups` TEXT, `codwfeeplus_matchall_groups` tinyint(1) unsigned NOT NULL DEFAULT \'0\', `codwfeeplus_desc` TEXT, `codwfeeplus_cartvalue_sign` int(2) unsigned NOT NULL DEFAULT \'0\', `codwfeeplus_cartvalue` DECIMAL(13, 4) NOT NULL DEFAULT \'0\', `codwfeeplus_shop` int(10) unsigned NOT NULL DEFAULT \'0\', PRIMARY KEY (`id_codwfeeplus_cond`) ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8; '); $ret &= Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'codwfeeplus_transactions` ( `id_codwfeeplus_trans` int(10) unsigned NOT NULL AUTO_INCREMENT, `codwfeeplus_result` TEXT, `codwfeeplus_datetime` DATETIME NOT NULL, `codwfeeplus_customer_id` int(10) NOT NULL DEFAULT \'0\', `codwfeeplus_order_id` int(10) NOT NULL DEFAULT \'0\', `codwfeeplus_fee` DECIMAL(13, 4) NOT NULL DEFAULT \'0\', `codwfeeplus_cart_total` DECIMAL(13, 4) NOT NULL DEFAULT \'0\', `codwfeeplus_shop` int(10) unsigned NOT NULL DEFAULT \'0\', PRIMARY KEY (`id_codwfeeplus_trans`) ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8; '); return $ret; } /** * deletes tables. */ public function deleteTables() { $ret = Db::getInstance()->execute(' DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'codwfeeplus_conditions`; '); $ret &= Db::getInstance()->execute(' DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'codwfeeplus_transactions`; '); return $ret; } public function addTransaction($customer_id, $order_id, $fee, $cart_total, $result) { if (!Configuration::get('SG_CODWFEEPLUS_KEEPTRANSACTIONS')) { return true; } $shop_id = 0; if (Shop::isFeatureActive()) { if (Shop::getContext() == Shop::CONTEXT_SHOP) { $shop_id = Shop::getContextShopID(); } } $date = date('Y-m-d H:i:s'); $ret = Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'codwfeeplus_transactions` (`codwfeeplus_result`,`codwfeeplus_datetime`,`codwfeeplus_customer_id`, `codwfeeplus_order_id`,`codwfeeplus_fee`,`codwfeeplus_cart_total`,`codwfeeplus_shop`) VALUES(' . '\'' . pSQL($result, true) . '\',' . '\'' . $date . '\',' . $customer_id . ',' . $order_id . ',' . $fee . ',' . $cart_total . ',' . $shop_id . ')' ); return $ret; } public function hasProductDownload($cart) { foreach ($cart->getProducts() as $product) { $pd = ProductDownload::getIdFromIdProduct((int) ($product['id_product'])); if ($pd and Validate::isUnsignedInt($pd)) { return true; } } return false; } public function hookUpdateCarrier($params) { $this->updateConditionsAfterCarrierUpdate($params['id_carrier'], $params['carrier']->id); return; } public function hookHeader($params) { if ($this->is17) { $this->context->controller->addCSS($this->_path . 'views/css/style-front_17.css'); $this->context->controller->addJS($this->_path . 'views/js/front.js'); } else { $this->context->controller->addCSS($this->_path . 'views/css/style-front.css'); } $this->context->controller->addJS($this->_path . 'views/js/front-reorder.js'); Media::addJsDef(array( 'codwfeeplus_codproductreference' => Configuration::get('SG_CODWFEEPLUS_PRODUCT_REFERENCE'), 'codwfeeplus_codproductid' => Configuration::get('SG_CODWFEEPLUS_PRODUCT_ID'), 'codwfeeplus_is17' => $this->is17, ) ); } public function updateConditionsAfterCarrierUpdate($old_id, $new_id) { $conds_db = Db::getInstance()->executeS('SELECT * FROM `' . _DB_PREFIX_ . 'codwfeeplus_conditions`'); foreach ($conds_db as $cond) { $cond_id = $cond['id_codwfeeplus_cond']; $C = new CODwFP($cond_id); $carriers_array = $C->getDeliveryArray(); foreach ($carriers_array as &$value) { if ($value == $old_id) { $value = $new_id; } } $C->setDeliveryArray($carriers_array); $C->saveToDB(); unset($C); } return; } public function hookPaymentOptions($params) { if (!$this->active) { return; } $fee = $this->getCost($params); if (!$this->_testoutput_method_active) { return false; } $integration = Configuration::get('SG_CODWFEEPLUS_INTEGRATION_WAY'); $cond_integration = $this->_cond_integration; $integration_product = false; if ($integration == 0) { //By condition if ($cond_integration == 1 && $fee != 0) { $integration_product = true; } } elseif ($integration == 2 && $fee != 0) { $integration_product = true; } $product_valid = $this->getProductStatus(); if (!$product_valid && $integration_product) { return false; } // Check if cart has product download if ($this->hasProductDownload($params['cart'])) { return false; } $link = new Link; $parameters = array("action" => "getCartSummary"); $ajax_link = $link->getModuleLink($this->name, 'ajax', $parameters); $this->context->smarty->assign(array( 'fee' => number_format($fee, 2, '.', ''), 'fee_formatted' => Tools::displayPrice($fee), 'ajax_link' => $ajax_link, )); $payment_options = [$this->getPaymentOptionValue()]; return $payment_options; } public function getPaymentOptionValue() { $pOption = new PrestaShop\PrestaShop\Core\Payment\PaymentOption; $pOption->setModuleName($this->name) ->setCallToActionText($this->l('Pay with Cash on Delivery')) ->setAction($this->context->link->getModuleLink($this->name, 'validation', array(), true)) ->setAdditionalInformation($this->context->smarty->fetch('module:codwfeeplus/views/templates/hook/payment_infos.tpl')); if (Configuration::get('SG_CODWFEEPLUS_LOGO_ENABLED')) { $pOption->setLogo(Media::getMediaPath(_PS_MODULE_DIR_ . '' . $this->name . '/views/img/' . Configuration::get('SG_CODWFEEPLUS_LOGO_FILENAME_17'))); } return $pOption; } public function hookPayment($params) { if (!$this->active) { return; } $fee = $this->getCost($params); if (!$this->_testoutput_method_active) { return false; } $integration = Configuration::get('SG_CODWFEEPLUS_INTEGRATION_WAY'); $cond_integration = $this->_cond_integration; $integration_product = false; if ($integration == 0) { //By condition if ($cond_integration == 1 && $fee != 0) { $integration_product = true; } } elseif ($integration == 2 && $fee != 0) { $integration_product = true; } $product_valid = $this->getProductStatus(); if (!$product_valid && $integration_product) { return false; } // Check if cart has product download if ($this->hasProductDownload($params['cart'])) { return false; } $this->smarty->assign(array( 'fee' => number_format($fee, 2, '.', ''), )); return $this->display(__FILE__, 'payment.tpl'); } private function getCategoriesFromCart($cart_id) { $ret = array(); $cart = new Cart($cart_id); $products = $cart->getProducts(true); foreach ($products as $product) { $cat = Product::getProductCategoriesFull($product['id_product']); foreach ($cat as $value) { if (!in_array($value['id_category'], $ret)) { $ret[] = $value['id_category']; } } } return $ret; } private function getManufacturersFromCart($cart_id) { $ret = array(); $cart = new Cart($cart_id); $products = $cart->getProducts(true); foreach ($products as $product) { if (!in_array($product['id_manufacturer'], $ret)) { $ret[] = $product['id_manufacturer']; } } return $ret; } private function getSuppliersFromCart($cart_id) { $ret = array(); $cart = new Cart($cart_id); $products = $cart->getProducts(true); foreach ($products as $product) { if (!in_array($product['id_supplier'], $ret)) { $ret[] = $product['id_supplier']; } } return $ret; } private function getCarrierName($id_carrier) { $car = new Carrier($id_carrier); return $car->name; } public function getShopName($id_shop) { $shop = new Shop($id_shop); return $shop->name; } private function getCountryName($id_country) { $country = new Country($id_country); return $country->name[(int) Configuration::get('PS_LANG_DEFAULT')]; } private function getStateName($id_state) { $ret = 'No state defined in cart'; if ($id_state > 0) { $state = new State($id_state); $ret = $state->name; } return $ret; } private function getZoneName($id_zone) { $zone = new Zone($id_zone); return $zone->name; } private function getCategoriesNameArray($categories_array) { $ret = array(); foreach ($categories_array as $value) { $cat = new Category($value); $ret[] = $cat->name[(int) Configuration::get('PS_LANG_DEFAULT')]; unset($cat); } return $ret; } private function getGroupNameArray($groups_array) { $ret = array(); foreach ($groups_array as $value) { $g = new Group($value); $ret[] = $g->name[(int) Configuration::get('PS_LANG_DEFAULT')]; unset($g); } return $ret; } private function getManufacturersNameArray($manufacturers_array) { $manuf_empty_label = $this->l('Empty manufacturer'); if ($this->is17) { $manuf_empty_label = $this->l('Empty brand'); } $ret = array(); foreach ($manufacturers_array as $value) { if ($value == '0') { $ret[] = $manuf_empty_label; } else { $g = new Manufacturer($value); $ret[] = $g->name; unset($g); } } return $ret; } private function getSuppliersNameArray($suppliers_array) { $ret = array(); foreach ($suppliers_array as $value) { if ($value == '0') { $ret[] = $this->l('Empty supplier'); } else { $g = new Supplier($value); $ret[] = $g->name; unset($g); } } return $ret; } public function getCost($params) { $id_shop = $params['cart']->id_shop; $id_carrier = $params['cart']->id_carrier; $address = Address::getCountryAndState($params['cart']->id_address_delivery); $id_country = $address['id_country'] ? $address['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT'); $id_zone = Address::getZoneById($params['cart']->id_address_delivery); $id_state = Address::getCountryAndState($params['cart']->id_address_delivery)['id_state']; $cartvalue = (float) $params['cart']->getOrderTotal(true, Cart::ONLY_PRODUCTS); $carriervalue = (float) $params['cart']->getOrderTotal(true, Cart::ONLY_SHIPPING); $cat_array = $this->getCategoriesFromCart($params['cart']->id); $cust_group = array(); if (Group::isFeatureActive()) { $cust_group = Customer::getGroupsStatic((int) $params['cart']->id_customer); } $manufacturers = $this->getManufacturersFromCart($params['cart']->id); $suppliers = $this->getSuppliersFromCart($params['cart']->id); return $this->getCost_common($id_carrier, $id_country, $id_state, $id_zone, $cartvalue, $carriervalue, $cat_array, $cust_group, $manufacturers, $suppliers, $id_shop); } public function getCostFromCart($cart) { $id_shop = $cart->id_shop; $id_carrier = $cart->id_carrier; $address = Address::getCountryAndState($cart->id_address_delivery); $id_country = $address['id_country'] ? $address['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT'); $id_state = Address::getCountryAndState($cart->id_address_delivery)['id_state']; $id_zone = Address::getZoneById($cart->id_address_delivery); $cartvalue = (float) $cart->getOrderTotal(true, Cart::ONLY_PRODUCTS); $carriervalue = (float) $cart->getOrderTotal(true, Cart::ONLY_SHIPPING); $cat_array = $this->getCategoriesFromCart($cart->id); $cust_group = array(); if (Group::isFeatureActive()) { $cust_group = Customer::getGroupsStatic((int) $cart->id_customer); } $manufacturers = $this->getManufacturersFromCart($cart->id); $suppliers = $this->getSuppliersFromCart($cart->id); return $this->getCost_common($id_carrier, $id_country, $id_state, $id_zone, $cartvalue, $carriervalue, $cat_array, $cust_group, $manufacturers, $suppliers, $id_shop); } public function getCost_common($id_carrier, $id_country, $id_state, $id_zone, $cartvalue, $carriervalue, $categories_array, $cust_group, $manufacturers_array, $suppliers_array, $id_shop) { $fee_arr = array(); $ret = 0; $global_integration_way = Configuration::get('SG_CODWFEEPLUS_INTEGRATION_WAY'); $global_orderstate = $this->checkOrderState(Configuration::get('SG_CODWFEEPLUS_ORDERSTATE')); $where_shop = ''; if (Shop::isFeatureActive()) { if (Shop::getContext() == Shop::CONTEXT_SHOP) { $where_shop = ' WHERE `codwfeeplus_shop`=' . Shop::getContextShopID(); } } $this->_testoutput_method_active = true; $conds_db = Db::getInstance()->executeS('SELECT * FROM `' . _DB_PREFIX_ . 'codwfeeplus_conditions`' . $where_shop . ' ORDER BY `codwfeeplus_position`'); $curr = Currency::getDefaultCurrency(); $c = $curr->suffix; unset($curr); $this->_testoutput = '
'; $this->_testoutput .= 'Output from COD with fee PLUS module for Prestasop© by Sakis Gkiokas, version: ' . $this->version . ''; $this->_testoutput .= '
' . '

Integration way is ' . $this->_integration_general_arr[$global_integration_way] . '.

' . '

Default order status is ' . $this->_getOrderstateText($global_orderstate) . '.

' . '

Started checking with these parameters:

' . '
'; if ($conds_db) { foreach ($conds_db as $cond) { $c = new CODwFP($cond['id_codwfeeplus_cond']); $c->validateConditionValues(); $cond_type_fee = true; $cond_type_txt = 'Type: FEE CALCULATION'; if ($c->codwfeeplus_condtype != 0) { $cond_type_fee = false; $cond_type_txt = 'Type: PAYMENT METHOD DEACTIVATION'; } $cond_valid = $this->checkCondValid($c, $id_carrier, $id_country, $id_state, $id_zone, $categories_array, $cartvalue, $carriervalue, $cust_group, $manufacturers_array, $suppliers_array, $id_shop); $this->_testoutput .= '
' . '

Checking condition with id# ' . $c->id_codwfeeplus_cond . '. ' . $cond_type_txt . '

'; $this->_testoutput .= $this->_testoutput_check; if ($cond_valid) { if ($cond_type_fee) { $this->_testoutput .= '

Condition passed validation. Calculating fee...

'; $fee = $this->getConditionFee($c, $cartvalue, $carriervalue); $this->_testoutput .= $this->_testoutput_applyfee; $this->_testoutput .= '

Fee calculated from this condition: ' . Tools::displayPrice($fee) . '

'; $fee_arr[] = array( 'fee' => $fee, 'id' => $c->id_codwfeeplus_cond, 'integration' => $c->codwfeeplus_integration, 'taxrule_id' => $c->codwfeeplus_taxrule_id, 'orderstate' => $c->codwfeeplus_orderstate_id, ); } else { $this->_testoutput .= '

Condition passed validation. Payment method will be unavailable...

'; $this->_testoutput_method_active = false; } } else { if ($cond_type_fee) { $this->_testoutput .= '

Condition did not pass validation.

'; } else { $this->_testoutput .= '

Condition did not pass validation. Payment method will be available...

'; } } $this->_testoutput .= '
'; unset($c); } } else { $this->_testoutput .= '
' . 'There are no conditions defined' . '
'; } if ($this->_testoutput_method_active) { $this->_testoutput .= '

Calculating final fee to apply...

'; if (Configuration::get('SG_CODWFEEPLUS_BEHAVIOUR') == 0) { //First fee in the list $this->_testoutput .= '

Applying the first condition that succeeded validation.

'; if (count($fee_arr)) { $ret = $fee_arr[0]['fee']; $this->_testoutput .= '

Condition with id ' . $fee_arr[0]['id'] . ' is used with fee ' . Tools::displayPrice($ret) . '.

'; } else { $this->_testoutput .= '

No condition passed validation so fee is ' . Tools::displayPrice('0') . '.

'; } $this->_testoutput .= '
'; } else { $this->_testoutput .= '

Adding all the fees returned from conditions that succeeded validation.

'; if (count($fee_arr)) { $this->_testoutput .= '
    '; foreach ($fee_arr as $value) { $ret += $value['fee']; $this->_testoutput .= '
  • Added resulting fee of ' . Tools::displayPrice($value['fee']) . ' from condition with id ' . $value['id'] . '.
  • '; } $this->_testoutput .= '
'; $this->_testoutput .= '

Final fee is ' . Tools::displayPrice($ret) . '.

'; } else { $this->_testoutput .= '

No condition passed validation so fee is ' . Tools::displayPrice('0') . '.

'; } $this->_testoutput .= '
'; } $this->_testoutput .= '
'; if ($ret == 0) { $this->_cond_integration = 0; $this->_testoutput .= '

Calculated fee value is ' . Tools::displayPrice('0') . ' so integration way is not applied.

'; } else { if ($global_integration_way != 0) { //not defined by condition $this->_cond_integration = $global_integration_way - 1; $this->_testoutput .= '

Integration way is defined globally as ' . $this->_integration_general_arr[$global_integration_way] . '.

'; } else { if (count($fee_arr)) { $this->_cond_integration = $fee_arr[0]['integration']; $this->_testoutput .= '

Integration way is defined from the first successful condition (' . $this->_integration_condition_arr[$fee_arr[0]['integration']] . ' from condition with id ' . $fee_arr[0]['id'] . ').

'; } else { $this->_cond_integration = 0; $this->_testoutput .= '

No conditions passed validation so integration way is not applied.

'; } } } $this->_testoutput .= '
'; $this->_testoutput .= '
'; if (count($fee_arr)) { if ($fee_arr[0]['orderstate'] == 0) { $this->_cond_orderstate = $global_orderstate; $this->_testoutput .= '

Order status is defined from the first successful condition (with id ' . $fee_arr[0]['id'] . ') which is set to default value (' . $this->_getOrderstateText($this->_cond_orderstate) . ').

'; } else { $this->_cond_orderstate = $fee_arr[0]['orderstate']; $this->_testoutput .= '

Order status is defined from the first successful condition (' . $this->_getOrderstateText($fee_arr[0]['orderstate']) . ' from condition with id ' . $fee_arr[0]['id'] . ').

'; } } else { $this->_cond_orderstate = $global_orderstate; $this->_testoutput .= '

No conditions passed validation so order status is the default (' . $this->_getOrderstateText($this->_cond_orderstate) . ').

'; } $this->_testoutput .= '
'; if ($this->_cond_integration == 1) { $this->_testoutput .= '
'; $this->_cond_taxrule = $fee_arr[0]['taxrule_id']; $rule_name = $this->getTaxRuleNameFromID($this->_cond_taxrule); $this->_testoutput .= '

Tax for COD product is defined from the first successful condition (' . $rule_name . ' from condition with id ' . $fee_arr[0]['id'] . ').

'; $this->_testoutput .= '
'; } $this->_testoutput .= '
'; $this->_testoutput .= '
'; } else { $this->_testoutput .= '
'; $this->_testoutput .= '

Payment method will be unavailable...

'; $this->_testoutput .= '
'; } return Tools::ps_round((float) $ret, _PS_PRICE_COMPUTE_PRECISION_); } /** * Gets the final tax once a carrier and address exists * * @param int $carrier_id * @param int $address_id * @return float */ public function getCODFeeTax($carrier_id, $address_id) { $car = new Carrier($carrier_id); $address = Address::initialize((int) $address_id); $carrier_tax = ((float) $car->getTaxesRate($address)) * 0.01; $product_tax = 0; $CODfee_tax = 0; if ($this->_cond_taxrule != 0) { $p = new Product(); $p->id_tax_rules_group = $this->_cond_taxrule; $product_tax = ((float) $p->getTaxesRate($address)) * 0.01; unset($p); } if ($this->_cond_integration == 0) { $CODfee_tax = $carrier_tax; } else { $CODfee_tax = $product_tax; } return $CODfee_tax; } private function checkCondValid(CODwFP $c, $id_carrier, $id_country, $id_state, $id_zone, $categories_array, $cartvalue, $carriervalue, $cust_group, $manufacturers_array, $suppliers_array, $id_shop) { $this->_testoutput_check = '
'; return $apply_cond; } private function getConditionFee(CODwFP $c, $cartvalue, $carriervalue) { /* @var $cur Currency */ $cur = $this->context->currency; $def_cur = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $this->_testoutput_applyfee = '
'; $this->_testoutput_applyfee .= '

Contition\'s integration way is ' . $this->_integration_condition_arr[$c->codwfeeplus_integration] . '.

'; $rule_name = $this->getTaxRuleNameFromID($c->codwfeeplus_taxrule_id); $this->_testoutput_applyfee .= '

Contition\'s tax for COD product is ' . $rule_name . '.

'; $this->_testoutput_applyfee .= '

Contition\'s order status is ' . $this->_getOrderstateText($c->codwfeeplus_orderstate_id) . '.

'; $this->_testoutput_applyfee .= '
'; return $fee; } private function countriesArrToText($inliststr) { $ret = ''; $i = 0; $inArr = explode('|', $inliststr); foreach ($inArr as $value) { $c = new Country($value); $ret .= ($i > 0 ? ' ,' : '') . $c->name[(int) Configuration::get('PS_LANG_DEFAULT')]; unset($c); ++$i; } return $ret; } private function statesArrToText($inliststr) { $ret = ''; $i = 0; $inArr = explode('|', $inliststr); foreach ($inArr as $value) { $c = new State($value); $ret .= ($i > 0 ? ' ,' : '') . $c->name; unset($c); ++$i; } return $ret; } private function carriersArrToText($inliststr) { $ret = ''; $i = 0; $inArr = explode('|', $inliststr); foreach ($inArr as $value) { $c = new Carrier($value); $ret .= ($i > 0 ? ' ,' : '') . $c->name; unset($c); ++$i; } return $ret; } private function zonesArrToText($inliststr) { $ret = ''; $i = 0; $inArr = explode('|', $inliststr); foreach ($inArr as $value) { $c = new Zone($value); $ret .= ($i > 0 ? ' ,' : '') . $c->name; unset($c); ++$i; } return $ret; } private function manufacturersArrToText($inliststr) { $manuf_empty_label = $this->l('Empty manufacturer'); if ($this->is17) { $manuf_empty_label = $this->l('Empty brand'); } $ret = ''; $i = 0; $inArr = explode('|', $inliststr); foreach ($inArr as $value) { if ($value == '0') { $ret .= ($i > 0 ? ' ,' : '') . $manuf_empty_label; } else { $c = new Manufacturer($value); $ret .= ($i > 0 ? ' ,' : '') . $c->name; unset($c); } ++$i; } return $ret; } private function suppliersArrToText($inliststr) { $ret = ''; $i = 0; $inArr = explode('|', $inliststr); foreach ($inArr as $value) { if ($value == '0') { $ret .= ($i > 0 ? ' ,' : '') . $this->l('Empty supplier'); } else { $c = new Supplier($value); $ret .= ($i > 0 ? ' ,' : '') . $c->name; unset($c); } ++$i; } return $ret; } private function shopsArrToText($inliststr) { $ret = ''; $i = 0; $inArr = explode('|', $inliststr); foreach ($inArr as $value) { $c = new Shop($value); $ret .= ($i > 0 ? ' ,' : '') . $c->name; unset($c); ++$i; } return $ret; } private function groupsArrToText($inliststr) { $ret = ''; $i = 0; $inArr = explode('|', $inliststr); foreach ($inArr as $value) { $c = new Group($value); $ret .= ($i > 0 ? ' ,' : '') . $c->name[(int) Configuration::get('PS_LANG_DEFAULT')]; unset($c); ++$i; } return $ret; } private function categoriesArrToText($inliststr) { $ret = ''; $i = 0; $inArr = explode('|', $inliststr); foreach ($inArr as $value) { $c = new Category($value); $ret .= ($i > 0 ? ' ,' : '') . $c->name[(int) Configuration::get('PS_LANG_DEFAULT')]; unset($c); ++$i; } return $ret; } private function firstGreaterorEqualtoSecond($first, $second) { $ret = false; if ($first >= $second) { $ret = true; } return $ret; } private function firstLesserorEqualtoSecond($first, $second) { $ret = false; if ($first <= $second) { $ret = true; } return $ret; } private function checkMultipleValuesListID($inliststr, $inid_arr, $match_all) { $res_cond = false; if (count($inid_arr) > 0) { $res_cond = $match_all; foreach ($inid_arr as $value) { if ($match_all) { $res_cond &= $this->checkListID($inliststr, $value); } else { $res_cond |= $this->checkListID($inliststr, $value); } } } return $res_cond; } private function checkListID($inliststr, $inid) { $res = true; $arr = explode('|', $inliststr); $res &= in_array($inid, $arr); return $res; } public function hookPaymentReturn($params) { if (!$this->active) { return; } if (!$this->is17) { return $this->display(__FILE__, 'confirmation.tpl'); } else { $this->smarty->assign( array( 'shop_name' => $this->context->shop->name, )); return $this->fetch('module:codwfeeplus/views/templates/hook/confirmation_17.tpl'); } } public function getTranslation($string, $lang_iso, $js = false, $name = null, $source = null) { $ret = ''; $_MODULES = null; $_MODULE = null; if ($name == null) { $name = $this->name; } if ($source == null) { $source = $this->name; } $files_by_priority = array( // Translations in theme _PS_THEME_DIR_ . 'modules/' . $name . '/translations/' . $lang_iso . '.php', _PS_THEME_DIR_ . 'modules/' . $name . '/' . $lang_iso . '.php', // PrestaShop 1.5 translations _PS_MODULE_DIR_ . $name . '/translations/' . $lang_iso . '.php', ); foreach ($files_by_priority as $file) { if (file_exists($file)) { include $file; $_MODULES = !empty($_MODULES) ? $_MODULES + $_MODULE : $_MODULE; //we use "+" instead of array_merge() because array merge erase existing values. } } $string = preg_replace("/\\\*'/", "\'", $string); $key = md5($string); if ($_MODULES == null) { return str_replace('"', '"', $string); } $current_key = Tools::strtolower('<{' . $name . '}' . _THEME_NAME_ . '>' . $source) . '_' . $key; $default_key = Tools::strtolower('<{' . $name . '}prestashop>' . $source) . '_' . $key; if ('controller' == Tools::substr($source, -10, 10)) { $file = Tools::substr($source, 0, -10); $current_key_file = Tools::strtolower('<{' . $name . '}' . _THEME_NAME_ . '>' . $file) . '_' . $key; $default_key_file = Tools::strtolower('<{' . $name . '}prestashop>' . $file) . '_' . $key; } if (isset($current_key_file) && !empty($_MODULES[$current_key_file])) { $ret = Tools::stripslashes($_MODULES[$current_key_file]); } elseif (isset($default_key_file) && !empty($_MODULES[$default_key_file])) { $ret = Tools::stripslashes($_MODULES[$default_key_file]); } elseif (!empty($_MODULES[$current_key])) { $ret = Tools::stripslashes($_MODULES[$current_key]); } elseif (!empty($_MODULES[$default_key])) { $ret = Tools::stripslashes($_MODULES[$default_key]); } else { $ret = Tools::stripslashes($string); } if ($js) { $ret = addslashes($ret); } else { $ret = htmlspecialchars($ret, ENT_COMPAT, 'UTF-8'); } return $ret; } public function getTaxRuleNameFromID($taxrule_id) { if ($taxrule_id == 0) { return 'No Tax'; } $taxrules = TaxRulesGroup::getTaxRulesGroups(); foreach ($taxrules as $value) { if ($value['id_tax_rules_group'] == $taxrule_id) { return $value['name']; } } } public function getUpdateStatus() { $ret = ''; $version_arr = explode('.', $this->version); $Maj = (int) $version_arr[0]; $Min = (int) $version_arr[1]; $Rev = (int) $version_arr[2]; $P = base64_encode(_PS_BASE_URL_ . __PS_BASE_URI__); $base_url = 'http://programs.sakgiok.gr/'; $url = $base_url . $this->name . '/version.php?Maj=' . $Maj . '&Min=' . $Min . '&Rev=' . $Rev . '&P=' . $P; $response = Tools::file_get_contents($url); if ($response) { $arr = json_decode($response, true); if (isset($arr['res'])) { if ($arr['res'] == 'update') { $this->_updatestatus['res'] = $arr['res']; $this->_updatestatus['cur_version'] = $arr['cur_version']; $this->_updatestatus['download_link'] = $arr['download_link']; $this->_updatestatus['info_link'] = $arr['info_link']; $this->_updatestatus['github_link'] = $arr['github_link']; $ret = 'update'; $this->updateValueAllShops('SG_CODWFEEPLUS_INFO_LINK', $this->_updatestatus['info_link']); $this->updateValueAllShops('SG_CODWFEEPLUS_GITHUB_LINK', $this->_updatestatus['github_link']); } elseif ($arr['res'] == 'current') { $this->_updatestatus['res'] = $arr['res']; $this->_updatestatus['cur_version'] = $arr['cur_version']; $this->_updatestatus['download_link'] = $arr['download_link']; $this->_updatestatus['info_link'] = $arr['info_link']; $this->_updatestatus['github_link'] = $arr['github_link']; $this->updateValueAllShops('SG_CODWFEEPLUS_INFO_LINK', $this->_updatestatus['info_link']); $this->updateValueAllShops('SG_CODWFEEPLUS_GITHUB_LINK', $this->_updatestatus['github_link']); $ret = 'current'; } else { $ret = 'error_res'; } } else { $ret = 'error_resp'; } } else { $ret = 'error_url'; } return $ret; } public function updateValueAllShops($key, $value) { $this->storeContextShop(); if (Shop::isFeatureActive()) { Shop::setContext(Shop::CONTEXT_ALL); } $res = true; if (Shop::isFeatureActive()) { $shop_list = Shop::getShops(true, null, true); foreach ($shop_list as $shop) { Shop::setContext(Shop::CONTEXT_SHOP, $shop); $res &= Configuration::updateValue($key, $value); } } else { $res &= Configuration::updateValue($key, $value); } $this->resetContextShop(); } private function _getOrderstateText($orderstate_id) { $ret = ''; if ($orderstate_id == 0) { $ret = 'Default value'; } else { $os = OrderState::getOrderStates(Configuration::get('PS_LANG_DEFAULT')); foreach ($os as $value) { if ($value['id_order_state'] == $orderstate_id) { $ret = $value['id_order_state'] . ' - ' . $value['name']; } } } return $ret; } //validate functions public function runCorrect_validateOrder($fee, $id_cart, $id_order_state, $amount_paid, $payment_method = 'Unknown', $message = null, $extra_vars = array(), $currency_special = null, $dont_touch_amount = false, $secure_key = false, Shop $shop = null) { if ($this->is17) { if (Tools::version_compare(_PS_VERSION_, '1.7.0.2', '<=')) { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/17002.php'; } elseif (Tools::version_compare(_PS_VERSION_, '1.7.0.6', '<=')) { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/17006.php'; } elseif (Tools::version_compare(_PS_VERSION_, '1.7.1.2', '<=')) { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/17102.php'; } elseif (Tools::version_compare(_PS_VERSION_, '1.7.2.0', '<=')) { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/17200.php'; } elseif (Tools::version_compare(_PS_VERSION_, '1.7.2.2', '<=')) { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/17202.php'; } elseif (Tools::version_compare(_PS_VERSION_, '1.7.3.0', '<=')) { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/17300.php'; } elseif (Tools::version_compare(_PS_VERSION_, '1.7.5.2', '<=')) { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/17500.php'; } elseif (Tools::version_compare(_PS_VERSION_, '1.7.6.0', '<=')) { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/17600.php'; } else { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/17600.php'; } } else { if (Tools::version_compare(_PS_VERSION_, '1.6.0.6', '<=')) { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/16006.php'; } elseif (Tools::version_compare(_PS_VERSION_, '1.6.0.9', '<=')) { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/16009.php'; } elseif (Tools::version_compare(_PS_VERSION_, '1.6.0.10', '<=')) { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/16010.php'; } elseif (Tools::version_compare(_PS_VERSION_, '1.6.0.11', '<=')) { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/16011.php'; } elseif (Tools::version_compare(_PS_VERSION_, '1.6.0.14', '<=')) { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/16014.php'; } elseif (Tools::version_compare(_PS_VERSION_, '1.6.1.1', '<=')) { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/16101.php'; } elseif (Tools::version_compare(_PS_VERSION_, '1.6.1.4', '<=')) { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/16104.php'; } elseif (Tools::version_compare(_PS_VERSION_, '1.6.1.24', '<=')) { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/16123.php'; } else { include _PS_MODULE_DIR_ . 'codwfeeplus/validate_functions/16123.php'; } } } public function checkOrderState($in_order_state) { $ret = $in_order_state; $lang_id = (int) Configuration::get('PS_LANG_DEFAULT'); $os = OrderState::getOrderStates($lang_id); if (array_search($in_order_state, array_column($os, 'id_order_state')) === false) { $ret = Configuration::get('PS_OS_PREPARATION'); } return $ret; } }