public function add() { $db = JFactory::getDBO(); $context = JeproshopContext::getContext(); $input = JRequest::get('post'); $inputData = $input['jform']; $selectedCountries = array(); $app = JFactory::getApplication(); $taxId = isset($inputData['tax_id']) ? $inputData['tax_id'] : $app->input->get('tax_id', 0); $taxRuleId = isset($inputData['tax_rule_id']) ? $inputData['tax_rule_id'] : $app->input->get('tax_rule_id', 0); $zipCode = $inputData['zipcode']; $behavior = $inputData['behavior']; $description = $inputData['description']; $country_id = $inputData['country_id']; if ($country_id == 0) { $countries = JeproshopCountryModelCountry::getStaticCountries($context->language->lang_id); foreach ($countries as $country) { $selectedCountries[] = $country->country_id; } } else { $selectedCountries[] = $country_id; } $selectedStates = array(); $state_id = $inputData['state_id']; if ($state_id != 0) { $selectedStates[] = $state_id; } else { $selectedStates[] = 0; } $taxRulesGroupId = (int) $app->input->get('tax_rules_group_id'); echo $taxRulesGroupId; $taxRuleGroup = new JeproshopTaxRulesGroupModelTaxRulesGroup($taxRulesGroupId); foreach ($selectedCountries as $country_id) { $first = true; foreach ($selectedStates as $state_id) { if ($taxRuleGroup->hasUniqueTaxRuleForCountry($country_id, $state_id, $taxRuleId)) { JError::raiseWarning(500, JText::_('COM_JEPROSHOP_A_TAX_ALREADY_EXISTS_FOR_THIS_COUNTRY_STATE_WITH_TAX_ONLY_BEHAVIOR_LABEL')); continue; } $taxRule = new JeproshopTaxRuleModelTaxRule(); // update or creation? if (isset($taxRuleId) && $first) { $taxRule->tax_rule_id = $taxRuleId; $first = false; } $taxRule->tax_id = $taxId; $taxRule->tax_rules_group_id = (int) $taxRulesGroupId; $taxRule->country_id = $country_id; $taxRule->state_id = (int) $state_id; list($taxRule->zipcode_from, $taxRule->zipcode_to) = $taxRule->breakDownZipCode($zipCode); $country = new JeproshopCountryModelCountry((int) $country_id, (int) $context->language->lang_id); if ($zipCode && $country->need_zip_code) { if ($country->zip_code_format) { foreach (array($taxRule->zipcode_from, $taxRule->zipcode_to) as $zip_code) { if ($zip_code) { if (!$country->checkZipCode($zip_code)) { JError::raiseError(500, JText::_('COM_JEPROSHOP_THE_ZIP_POSTAL_CODE_IS_INVALID_AND_MUST_BE_TYPED_AS_FOLLOWS_MESSAGE') . JText::_('COM_JEPROSHOP_FOR_LABEL')); } } } } } $taxRule->behavior = $behavior; $taxRule->description = $description; $query = "INSERT INTO " . $db->quoteName('#__jeproshop_tax_rule') . "(" . $db->quoteName('tax_rules_group_id') . ", " . $db->quoteName('country_id') . ", " . $db->quoteName('state_id') . ", " . $db->quoteName('zipcode_from') . ", "; $query .= $db->quoteName('zipcode_to') . ", " . $db->quoteName('tax_id') . ", " . $db->quoteName('behavior') . ", " . $db->quoteName('description') . ") VALUES (" . (int) $taxRulesGroupId . ", " . (int) $country_id . ", " . (int) $state_id; $query .= ", " . $db->quote($taxRule->zipcode_from) . ", " . $db->quote($taxRule->zipcode_to) . ", " . (int) $taxId . ", " . (int) $behavior . ", " . $db->quote($description) . ")"; $db->setQuery($query); $link = 'index.php?option=com_jeproshop&view=tax&task='; if ($db->query()) { $link .= 'edit_rules_group&tax_rules_group_id=' . (int) $taxRulesGroupId . '&' . JeproshopTools::getTaxToken() . '=1'; } else { $link .= ''; } $app->redirect($link); } } }