code = 'ot_cod_fee'; $this->title = $aLang['module_order_total_cod_title']; $this->description = $aLang['module_order_total_cod_description']; $this->enabled = ((MODULE_ORDER_TOTAL_COD_STATUS == 'true') ? true : false); $this->sort_order = MODULE_ORDER_TOTAL_COD_SORT_ORDER; $this->output = array(); } function process() { global $order, $oCurrencies, $cod_cost, $cod_country; if (MODULE_ORDER_TOTAL_COD_STATUS == 'true') { //Will become true, if cod can be processed. $cod_country = false; //check if payment method is cod. If yes, check if cod is possible. if ($_SESSION['payment'] == 'cod') { //process installed shipping modules $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_FLAT); if ($_SESSION['shipping']['id'] == 'flat_flat') $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_FLAT); if ($_SESSION['shipping']['id'] == 'item_item') $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_ITEM); if ($_SESSION['shipping']['id'] == 'table_table') $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_TABLE); if ($_SESSION['shipping']['id'] == 'zones_zones') $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_ZONES); if ($_SESSION['shipping']['id'] == 'ap_ap') $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_AP); if ($_SESSION['shipping']['id'] == 'dp_dp') $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_DP); if ($_SESSION['shipping']['id'] == 'chp_ECO') $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_CHP); if ($_SESSION['shipping']['id'] == 'chp_PRI') $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_CHP); if ($_SESSION['shipping']['id'] == 'chp_URG') $cod_zones = split("[:,]", MODULE_ORDER_TOTAL_COD_FEE_CHP); for ($i = 0; $i < count($cod_zones); $i++) { if ($cod_zones[$i] == $order->billing['country']['iso_code_2']) { $cod_cost = $cod_zones[$i + 1]; $cod_country = true; //print('match' . $i . ': ' . $cod_cost); break; } elseif ($cod_zones[$i] == '00') { $cod_cost = $cod_zones[$i + 1]; $cod_country = true; //print('match' . $i . ': ' . $cod_cost); break; } else { //print('no match'); } $i++; } } else { //COD selected, but no shipping module which offers COD } if ($cod_country) { if (MODULE_ORDER_TOTAL_COD_TAX_CLASS > 0) { $cod_tax = oos_get_tax_rate(MODULE_ORDER_TOTAL_COD_TAX_CLASS, $order->billing['country']['id'], $order->billing['zone_id']); // $cod_tax_description = oos_get_tax_description(MODULE_ORDER_TOTAL_COD_TAX_CLASS, $order->billing['country']['id'], $order->billing['zone_id']); $cod_tax_description = oos_get_tax_rate(MODULE_ORDER_TOTAL_COD_TAX_CLASS, $order->billing['country']['id'], $order->billing['zone_id']); $order->info['tax'] += oos_calculate_tax($cod_cost, $cod_tax); $order->info['tax_groups']["$cod_tax_description"] += oos_calculate_tax($cod_cost, $cod_tax); $order->info['total'] += $cod_cost + oos_calculate_tax($cod_cost, $cod_tax); $this->output[] = array('title' => $this->title . ':', 'text' => $oCurrencies->format(oos_add_tax($cod_cost, $cod_tax), true, $order->info['currency'], $order->info['currency_value']), 'value' => oos_add_tax($cod_cost, $cod_tax)); } else { $order->info['total'] += $cod_cost; $this->output[] = array('title' => $this->title . ':', 'text' => $oCurrencies->format($cod_cost, true, $order->info['currency'], $order->info['currency_value']), 'value' => $cod_cost); } } else { //Following code should be improved if we can't get the shipping modules disabled, who don't allow COD // as well as countries who do not have cod // $this->output[] = array('title' => $this->title . ':', // 'text' => 'No COD for this module.', // 'value' => ''); } } } function check() { if (!isset($this->_check)) { $db =& oosDBGetConn(); $oosDBTable = oosDBGetTables(); $check_result = $db->Execute("SELECT configuration_value FROM " . $oosDBTable['configuration'] . " WHERE configuration_key = 'MODULE_ORDER_TOTAL_COD_STATUS'"); $this->_check = $check_result->RecordCount(); } return $this->_check; } function keys() { return array('MODULE_ORDER_TOTAL_COD_STATUS', 'MODULE_ORDER_TOTAL_COD_SORT_ORDER', 'MODULE_ORDER_TOTAL_COD_FEE_FLAT', 'MODULE_ORDER_TOTAL_COD_FEE_ITEM', 'MODULE_ORDER_TOTAL_COD_FEE_TABLE', 'MODULE_ORDER_TOTAL_COD_FEE_ZONES', 'MODULE_ORDER_TOTAL_COD_FEE_AP', 'MODULE_ORDER_TOTAL_COD_FEE_DP', 'MODULE_ORDER_TOTAL_COD_TAX_CLASS'); } function install() { $db =& oosDBGetConn(); $oosDBTable = oosDBGetTables(); $db->Execute("INSERT INTO " . $oosDBTable['configuration'] . " (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) VALUES ('MODULE_ORDER_TOTAL_COD_STATUS', 'true', '6', '0','oosCfgSelectOption(array(\'true\', \'false\'), ', now())"); $db->Execute("INSERT INTO " . $oosDBTable['configuration'] . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) VALUES ('MODULE_ORDER_TOTAL_COD_SORT_ORDER', '6', '6', '0', now())"); $db->Execute("INSERT INTO " . $oosDBTable['configuration'] . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) VALUES ('MODULE_ORDER_TOTAL_COD_FEE_FLAT', 'AT:3.00,DE:3.58,00:9.99', '6', '0', now())"); $db->Execute("INSERT INTO " . $oosDBTable['configuration'] . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) VALUES ('MODULE_ORDER_TOTAL_COD_FEE_ITEM', 'AT:3.00,DE:3.58,00:9.99', '6', '0', now())"); $db->Execute("INSERT INTO " . $oosDBTable['configuration'] . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) VALUES ('MODULE_ORDER_TOTAL_COD_FEE_TABLE', 'AT:3.00,DE:3.58,00:9.99', '6', '0', now())"); $db->Execute("INSERT INTO " . $oosDBTable['configuration'] . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) VALUES ('MODULE_ORDER_TOTAL_COD_FEE_ZONES', 'CA:4.50,US:3.00,00:9.99', '6', '0', now())"); $db->Execute("INSERT INTO " . $oosDBTable['configuration'] . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) VALUES ('MODULE_ORDER_TOTAL_COD_FEE_AP', 'AT:3.63,00:9.99', '6', '0', now())"); $db->Execute("INSERT INTO " . $oosDBTable['configuration'] . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) VALUES ('MODULE_ORDER_TOTAL_COD_FEE_DP', 'DE:3.58,00:9.99', '6', '0', now())"); $db->Execute("INSERT INTO " . $oosDBTable['configuration'] . " (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) VALUES ('MODULE_ORDER_TOTAL_COD_FEE_CHP', 'CH:15.00,00:15.00', '6', '0', now())"); $db->Execute("INSERT INTO " . $oosDBTable['configuration'] . " (configuration_key, configuration_value, configuration_group_id, sort_order, use_function, set_function, date_added) VALUES ('MODULE_ORDER_TOTAL_COD_TAX_CLASS', '0', '6', '0', 'oosCfgGetTaxClassTitle', 'oosCfgPullDownTaxClasses(', now())"); } function remove() { $db =& oosDBGetConn(); $oosDBTable = oosDBGetTables(); $db->Execute("DELETE FROM " . $oosDBTable['configuration'] . " WHERE configuration_key in ('" . implode("', '", $this->keys()) . "')"); } } ?>