public function processSave()
 {
     if (Tools::getValue('submitFormAjax')) {
         $this->redirect_after = false;
     }
     // Transform e-mail in id_customer for parent processing
     if (Validate::isEmail(Tools::getValue('email'))) {
         $customer = new Customer();
         $customer->getByEmail(Tools::getValue('email'), null, false);
         if (Validate::isLoadedObject($customer)) {
             $_POST['id_customer'] = $customer->id;
         } else {
             $this->errors[] = Tools::displayError('This email address is not registered.');
         }
     } else {
         if ($id_customer = Tools::getValue('id_customer')) {
             $customer = new Customer((int) $id_customer);
             if (Validate::isLoadedObject($customer)) {
                 $_POST['id_customer'] = $customer->id;
             } else {
                 $this->errors[] = Tools::displayError('Unknown customer');
             }
         } else {
             $this->errors[] = Tools::displayError('Unknown customer');
         }
     }
     if (Country::isNeedDniByCountryId(Tools::getValue('id_country')) && !Tools::getValue('dni')) {
         $this->errors[] = Tools::displayError('The identification number is incorrect or has already been used.');
     }
     /* If the selected country does not contain states */
     $id_state = (int) Tools::getValue('id_state');
     $id_country = (int) Tools::getValue('id_country');
     $country = new Country((int) $id_country);
     if ($country && !(int) $country->contains_states && $id_state) {
         $this->errors[] = Tools::displayError('You have selected a state for a country that does not contain states.');
     }
     /* If the selected country contains states, then a state have to be selected */
     if ((int) $country->contains_states && !$id_state) {
         $this->errors[] = Tools::displayError('An address located in a country containing states must have a state selected.');
     }
     $postcode = Tools::getValue('postcode');
     /* Check zip code format */
     if ($country->zip_code_format && !$country->checkZipCode($postcode)) {
         $this->errors[] = Tools::displayError('Your Zip/postal code is incorrect.') . '<br />' . Tools::displayError('It must be entered as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
     } elseif (empty($postcode) && $country->need_zip_code) {
         $this->errors[] = Tools::displayError('A Zip/postal code is required.');
     } elseif ($postcode && !Validate::isPostCode($postcode)) {
         $this->errors[] = Tools::displayError('The Zip/postal code is invalid.');
     }
     if (Configuration::get('PS_ONE_PHONE_AT_LEAST') && !Tools::getValue('phone') && !Tools::getValue('phone_mobile')) {
         $this->errors[] = Tools::displayError('You must register at least one phone number.');
     }
     /* If this address come from order's edition and is the same as the other one (invoice or delivery one)
      ** we delete its id_address to force the creation of a new one */
     if ((int) Tools::getValue('id_order')) {
         $this->_redirect = false;
         if (isset($_POST['address_type'])) {
             $_POST['id_address'] = '';
         }
     }
     // Check the requires fields which are settings in the BO
     $address = new Address();
     $this->errors = array_merge($this->errors, $address->validateFieldsRequiredDatabase());
     if (empty($this->errors)) {
         return parent::processSave();
     } else {
         // if we have errors, we stay on the form instead of going back to the list
         $this->display = 'edit';
     }
     /* Reassignation of the order's new (invoice or delivery) address */
     $address_type = (int) Tools::getValue('address_type') == 2 ? 'invoice' : ((int) Tools::getValue('address_type') == 1 ? 'delivery' : '');
     if ($this->action == 'save' && ($id_order = (int) Tools::getValue('id_order')) && !count($this->errors) && !empty($address_type)) {
         if (!Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . 'orders SET `id_address_' . $address_type . '` = ' . Db::getInstance()->Insert_ID() . ' WHERE `id_order` = ' . $id_order)) {
             $this->errors[] = Tools::displayError('An error occurred while linking this address to its order.');
         } else {
             Tools::redirectAdmin(Tools::getValue('back') . '&conf=4');
         }
     }
 }
 public function postProcess()
 {
     if (isset($_POST['submitAdd' . $this->table])) {
         /* Cleaning fields */
         foreach ($_POST as $kp => $vp) {
             if (!in_array($kp, array('checkBoxShopGroupAsso_store', 'checkBoxShopAsso_store'))) {
                 $_POST[$kp] = trim($vp);
             }
         }
         /* Rewrite latitude and longitude to 8 digits */
         $_POST['latitude'] = number_format((double) $_POST['latitude'], 8);
         $_POST['longitude'] = number_format((double) $_POST['longitude'], 8);
         /* If the selected country does not contain states */
         $id_state = (int) Tools::getValue('id_state');
         $id_country = (int) Tools::getValue('id_country');
         $country = new Country((int) $id_country);
         if ($id_country && $country && !(int) $country->contains_states && $id_state) {
             $this->errors[] = Tools::displayError('You\'ve selected a state for a country that does not contain states.');
         }
         /* If the selected country contains states, then a state have to be selected */
         if ((int) $country->contains_states && !$id_state) {
             $this->errors[] = Tools::displayError('An address located in a country containing states must have a state selected.');
         }
         $latitude = (double) Tools::getValue('latitude');
         $longitude = (double) Tools::getValue('longitude');
         if (empty($latitude) || empty($longitude)) {
             $this->errors[] = Tools::displayError('Latitude and longitude are required.');
         }
         $postcode = Tools::getValue('postcode');
         /* Check zip code format */
         if ($country->zip_code_format && !$country->checkZipCode($postcode)) {
             $this->errors[] = Tools::displayError('Your Zip/postal code is incorrect.') . '<br />' . Tools::displayError('It must be entered as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
         } elseif (empty($postcode) && $country->need_zip_code) {
             $this->errors[] = Tools::displayError('A Zip/postal code is required.');
         } elseif ($postcode && !Validate::isPostCode($postcode)) {
             $this->errors[] = Tools::displayError('The Zip/postal code is invalid.');
         }
         /* Store hours */
         $_POST['hours'] = array();
         for ($i = 1; $i < 8; $i++) {
             $_POST['hours'][] .= Tools::getValue('hours_' . (int) $i);
         }
         $_POST['hours'] = serialize($_POST['hours']);
     }
     if (!count($this->errors)) {
         parent::postProcess();
     } else {
         $this->display = 'add';
     }
 }
 protected function processCreateRule()
 {
     $zip_code = Tools::getValue('zipcode');
     $id_rule = (int) Tools::getValue('id_tax_rule');
     $id_tax = (int) Tools::getValue('id_tax');
     $id_tax_rules_group = (int) Tools::getValue('id_tax_rules_group');
     $behavior = (int) Tools::getValue('behavior');
     $description = pSQL(Tools::getValue('description'));
     if ((int) ($id_country = Tools::getValue('country')) == 0) {
         $countries = Country::getCountries($this->context->language->id);
         $this->selected_countries = array();
         foreach ($countries as $country) {
             $this->selected_countries[] = (int) $country['id_country'];
         }
     } else {
         $this->selected_countries = array($id_country);
     }
     $this->selected_states = Tools::getValue('states');
     if (empty($this->selected_states) || count($this->selected_states) == 0) {
         $this->selected_states = array(0);
     }
     $tax_rules_group = new TaxRulesGroup((int) $id_tax_rules_group);
     foreach ($this->selected_countries as $id_country) {
         $first = true;
         foreach ($this->selected_states as $id_state) {
             if ($tax_rules_group->hasUniqueTaxRuleForCountry($id_country, $id_state, $id_rule)) {
                 $this->errors[] = Tools::displayError('A tax rule already exists for this country/state with tax only behavior.');
                 continue;
             }
             $tr = new TaxRule();
             // update or creation?
             if (isset($id_rule) && $first) {
                 $tr->id = $id_rule;
                 $first = false;
             }
             $tr->id_tax = $id_tax;
             $tax_rules_group = new TaxRulesGroup((int) $id_tax_rules_group);
             $tr->id_tax_rules_group = (int) $tax_rules_group->id;
             $tr->id_country = (int) $id_country;
             $tr->id_state = (int) $id_state;
             list($tr->zipcode_from, $tr->zipcode_to) = $tr->breakDownZipCode($zip_code);
             // Construct Object Country
             $country = new Country((int) $id_country, (int) $this->context->language->id);
             if ($zip_code && $country->need_zip_code) {
                 if ($country->zip_code_format) {
                     foreach (array($tr->zipcode_from, $tr->zipcode_to) as $zip_code) {
                         if ($zip_code) {
                             if (!$country->checkZipCode($zip_code)) {
                                 $this->errors[] = sprintf(Tools::displayError('The Zip/postal code is invalid. It must be typed as follows: %s for %s.'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))), $country->name);
                             }
                         }
                     }
                 }
             }
             $tr->behavior = (int) $behavior;
             $tr->description = $description;
             $this->tax_rule = $tr;
             $_POST['id_state'] = $tr->id_state;
             $this->errors = array_merge($this->errors, $this->validateTaxRule($tr));
             if (count($this->errors) == 0) {
                 $tax_rules_group = $this->updateTaxRulesGroup($tax_rules_group);
                 $tr->id = (int) $tax_rules_group->getIdTaxRuleGroupFromHistorizedId((int) $tr->id);
                 $tr->id_tax_rules_group = (int) $tax_rules_group->id;
                 if (!$tr->save()) {
                     $this->errors[] = Tools::displayError('An error has occurred: Cannot save the current tax rule.');
                 }
             }
         }
     }
     if (count($this->errors) == 0) {
         Tools::redirectAdmin(self::$currentIndex . '&' . $this->identifier . '=' . (int) $tax_rules_group->id . '&conf=4&update' . $this->table . '&token=' . $this->token);
     } else {
         $this->display = 'edit';
     }
 }
示例#4
0
 protected function processSubmitAccount()
 {
     if (!$this->isOpcModuleActive()) {
         return parent::processSubmitAccount();
     }
     // Entire override is here just because of rigid address set-up. Original PS do not expect
     // address being set to cart prior to processSubmitAccount call and thus always creates new Address
     $inv_first_on = Configuration::get('OPC_INVOICE_FIRST') == "1";
     Hook::exec('actionBeforeSubmitAccount');
     $this->create_account = true;
     if (Tools::isSubmit('submitAccount')) {
         $this->context->smarty->assign('email_create', 1);
     }
     // New Guest customer
     if (!Tools::getValue('is_new_customer', 1) && !Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) {
         $this->errors[] = Tools::displayError('You cannot create a guest account.');
     }
     // Customer (not-guest) checkout, password field is hidden and password is automatically generated
     if ((!Tools::getIsset('passwd') || trim($_POST['passwd']) == "") && trim(Tools::getValue('email')) != "" && Configuration::get('OPC_CREATE_CUSTOMER_PASSWORD') && !CustomerCore::customerExists(Tools::getValue('email'))) {
         $_POST['is_new_customer'] = 1;
         $_POST['passwd'] = Tools::passwdGen(5);
     } elseif (!Tools::getValue('is_new_customer', 1)) {
         $_POST['passwd'] = md5(time() . _COOKIE_KEY_);
     }
     if (Tools::getIsset('guest_email') && $_POST['guest_email']) {
         $_POST['email'] = $_POST['guest_email'];
     }
     // Checked the user address in case he changed his email address
     if (Validate::isEmail($email = Tools::getValue('email')) && !empty($email)) {
         if (Customer::customerExists($email)) {
             $this->errors[] = Tools::displayError('An account is already registered with this e-mail.', false);
         }
     }
     // Preparing customer
     $customer = new Customer();
     $_POST['lastname'] = Tools::getValue('customer_lastname');
     $_POST['firstname'] = Tools::getValue('customer_firstname');
     //        if (Configuration::get('PS_ONE_PHONE_AT_LEAST') && !Tools::getValue('phone') && !Tools::getValue('phone_mobile') &&
     //            (Configuration::get('PS_REGISTRATION_PROCESS_TYPE') || Configuration::get('PS_GUEST_CHECKOUT_ENABLED')))
     //            $this->errors[] = Tools::displayError('You must register at least one phone number');
     $error_phone = false;
     if (Configuration::get('PS_ONE_PHONE_AT_LEAST')) {
         $inv_suffix = $inv_first_on ? "_invoice" : "";
         if (Tools::isSubmit('submitGuestAccount') || !Tools::getValue('is_new_customer')) {
             if (!Tools::getValue('phone' . $inv_suffix) && !Tools::getValue('phone_mobile' . $inv_suffix)) {
                 $error_phone = true;
             }
         } elseif ((Configuration::get('PS_REGISTRATION_PROCESS_TYPE') || Configuration::get('PS_ORDER_PROCESS_TYPE')) && (Configuration::get('PS_ORDER_PROCESS_TYPE') && !Tools::getValue('email_create')) && (!Tools::getValue('phone' . $inv_suffix) && !Tools::getValue('phone_mobile' . $inv_suffix))) {
             $error_phone = true;
         } elseif (Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && Configuration::get('PS_ORDER_PROCESS_TYPE') && Tools::getValue('email_create') && (!Tools::getValue('phone' . $inv_suffix) && !Tools::getValue('phone_mobile' . $inv_suffix))) {
             $error_phone = true;
         }
     }
     if ($error_phone) {
         $this->errors[] = Tools::displayError('You must register at least one phone number.');
     }
     $this->errors = array_unique(array_merge($this->errors, $customer->validateController()));
     // Check the requires fields which are settings in the BO
     $this->errors = array_merge($this->errors, $customer->validateFieldsRequiredDatabase());
     if (!Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && !$this->ajax && !Tools::isSubmit('submitGuestAccount')) {
         if (!count($this->errors)) {
             if (Tools::isSubmit('newsletter')) {
                 $this->processCustomerNewsletter($customer);
             }
             $customer->birthday = empty($_POST['years']) ? '' : (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
             if (!Validate::isBirthDate($customer->birthday)) {
                 $this->errors[] = Tools::displayError('Invalid birthday.');
             }
             $customer->active = 1;
             // New Guest customer
             if (Tools::isSubmit('is_new_customer')) {
                 $customer->is_guest = !Tools::getValue('is_new_customer', 1);
             } else {
                 $customer->is_guest = 0;
             }
             if (!count($this->errors)) {
                 if (!$customer->add()) {
                     $this->errors[] = Tools::displayError('An error occurred while creating your account.');
                 } else {
                     if (!$customer->is_guest) {
                         if (!$this->sendConfirmationMail($customer)) {
                             $this->errors[] = Tools::displayError('Cannot send e-mail');
                         }
                     }
                     $this->updateContext($customer);
                     $this->context->cart->update();
                     Hook::exec('actionCustomerAccountAdd', array('_POST' => $_POST, 'newCustomer' => $customer));
                     if ($this->ajax) {
                         $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => true, 'id_customer' => (int) $this->context->cookie->id_customer, 'id_address_delivery' => $this->context->cart->id_address_delivery, 'id_address_invoice' => $this->context->cart->id_address_invoice, 'token' => Tools::getToken(false));
                         die(Tools::jsonEncode($return));
                     }
                     // redirection: if cart is not empty : redirection to the cart
                     if (count($this->context->cart->getProducts(true)) > 0) {
                         Tools::redirect('index.php?controller=order&multi-shipping=' . (int) Tools::getValue('multi-shipping'));
                     } else {
                         Tools::redirect('index.php?controller=my-account');
                     }
                 }
             }
         }
     } else {
         $lastnameAddress = $inv_first_on ? $_POST['lastname_invoice'] : $_POST['lastname'];
         $firstnameAddress = $inv_first_on ? $_POST['firstname_invoice'] : $_POST['firstname'];
         // Preparing address
         $id_address = isset($this->context->cart->id_address_delivery) ? (int) $this->context->cart->id_address_delivery : 0;
         if ($id_address > 0) {
             $address = new Address($id_address);
         } else {
             $address = new Address();
         }
         $_POST['lastname'] = $lastnameAddress;
         $_POST['firstname'] = $firstnameAddress;
         $address->id_customer = 1;
         $this->errors = array_unique(array_merge($this->errors, $address->validateController()));
         // US customer: normalize the address
         if (version_compare(_PS_VERSION_, "1.6.0") < 0 && $address->id_country == Country::getByIso('US')) {
             include_once _PS_TAASC_PATH_ . 'AddressStandardizationSolution.php';
             $normalize = new AddressStandardizationSolution();
             $address->address1 = $normalize->AddressLineStandardization($address->address1);
             $address->address2 = $normalize->AddressLineStandardization($address->address2);
         }
         $inv_suffix = $inv_first_on ? "_invoice" : "";
         $country = new Country((int) Tools::getValue('id_country' . $inv_suffix));
         if ($country->need_zip_code) {
             if (($postcode = Tools::getValue('postcode' . $inv_suffix)) && $country->zip_code_format) {
                 if (!$country->checkZipCode($postcode)) {
                     $this->errors[] = sprintf(Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
                 }
             } elseif ($country->zip_code_format && !$this->context->cart->isVirtualCart()) {
                 $this->errors[] = Tools::displayError('Zip/Postal code is required.');
             } elseif ($postcode && !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode)) {
                 $this->errors[] = Tools::displayError('Zip/Postal code is invalid.');
             }
         }
         /*if ($country->need_identification_number && (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni'))))
                     $this->errors[] = Tools::displayError('Identification number is incorrect or has already been used.');
                 elseif (!$country->need_identification_number)
           $address->dni = null;*/
     }
     if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) && !(Tools::getValue('months') == '' && Tools::getValue('days') == '' && Tools::getValue('years') == '')) {
         $this->errors[] = Tools::displayError('Invalid date of birth');
     }
     if (!count($this->errors)) {
         if (Customer::customerExists(Tools::getValue('email'))) {
             $this->errors[] = Tools::displayError('An account is already registered with this e-mail, please enter your password or request a new one.', false);
         }
         if (Tools::isSubmit('newsletter')) {
             $this->processCustomerNewsletter($customer);
         }
         $customer->birthday = empty($_POST['years']) ? '' : (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
         if (!Validate::isBirthDate($customer->birthday)) {
             $this->errors[] = Tools::displayError('Invalid birthday.');
         }
         if (!count($this->errors)) {
             // if registration type is in one step, we save the address
             if (Configuration::get('PS_REGISTRATION_PROCESS_TYPE')) {
                 if (!($country = new Country($address->id_country, Configuration::get('PS_LANG_DEFAULT'))) || !Validate::isLoadedObject($country)) {
                     die(Tools::displayError());
                 }
             }
             $contains_state = isset($country) && is_object($country) ? (int) $country->contains_states : 0;
             $id_state = isset($address) && is_object($address) ? (int) $address->id_state : 0;
             if ($contains_state && !$id_state) {
                 $this->errors[] = Tools::displayError('This country requires a state selection.');
             } else {
                 $customer->active = 1;
                 // New Guest customer
                 if (Tools::isSubmit('is_new_customer')) {
                     $customer->is_guest = !Tools::getValue('is_new_customer', 1);
                 } else {
                     $customer->is_guest = 0;
                 }
                 if (!$customer->add()) {
                     $this->errors[] = Tools::displayError('An error occurred while creating your account.');
                 } else {
                     $address->id_customer = (int) $customer->id;
                     $this->errors = array_unique(array_merge($this->errors, $address->validateController()));
                     if (!count($this->errors) && (Configuration::get('PS_REGISTRATION_PROCESS_TYPE') || $this->ajax || Tools::isSubmit('submitGuestAccount'))) {
                         if ($address->id > 0 && !$address->update() || !($address->id > 0) && !$address->add()) {
                             $this->errors[] = Tools::displayError('An error occurred while creating your address.');
                         } else {
                             if (!$customer->is_guest) {
                                 $this->context->customer = $customer;
                                 $customer->cleanGroups();
                                 // we add the guest customer in the default customer group
                                 $customer->addGroups(array((int) Configuration::get('PS_CUSTOMER_GROUP')));
                                 if (!$this->sendConfirmationMail($customer)) {
                                     $this->errors[] = Tools::displayError('Cannot send e-mail');
                                 }
                             } else {
                                 $customer->cleanGroups();
                                 // we add the guest customer in the guest customer group
                                 $customer->addGroups(array((int) Configuration::get('PS_GUEST_GROUP')));
                             }
                             $this->updateContext($customer);
                             $this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int) $customer->id);
                             if ($this->context->cart->id_address_invoice == 0) {
                                 $this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int) $customer->id);
                             }
                             // If a logged guest logs in as a customer, the cart secure key was already set and needs to be updated
                             $this->context->cart->update();
                             // Avoid articles without delivery address on the cart
                             $this->context->cart->autosetProductAddress();
                             Hook::exec('actionCustomerAccountAdd', array('_POST' => $_POST, 'newCustomer' => $customer));
                             if ($this->ajax) {
                                 $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => true, 'id_customer' => (int) $this->context->cookie->id_customer, 'id_address_delivery' => $this->context->cart->id_address_delivery, 'id_address_invoice' => $this->context->cart->id_address_invoice, 'token' => Tools::getToken(false));
                                 die(Tools::jsonEncode($return));
                             }
                             // if registration type is in two steps, we redirect to register address
                             if (!Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && !$this->ajax && !Tools::isSubmit('submitGuestAccount')) {
                                 Tools::redirect('index.php?controller=address');
                             }
                             if ($back = Tools::getValue('back')) {
                                 Tools::redirect($back);
                             }
                             Tools::redirect('index.php?controller=my-account');
                             // redirection: if cart is not empty : redirection to the cart
                             if (count($this->context->cart->getProducts(true)) > 0) {
                                 Tools::redirect('index.php?controller=order&multi-shipping=' . (int) Tools::getValue('multi-shipping'));
                             } else {
                                 Tools::redirect('index.php?controller=my-account');
                             }
                         }
                     }
                 }
             }
         }
     }
     if (count($this->errors)) {
         //for retro compatibility to display guest account creation form on authentication page
         if (Tools::getValue('submitGuestAccount')) {
             $_GET['display_guest_checkout'] = 1;
         }
         if (!Tools::getValue('is_new_customer')) {
             unset($_POST['passwd']);
         }
         if ($this->ajax) {
             $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => false, 'id_customer' => 0);
             die(Tools::jsonEncode($return));
         }
         $this->context->smarty->assign('account_error', $this->errors);
     }
 }
 protected function processCreateRule()
 {
     $zip_code = Tools::getValue('zipcode');
     $id_rule = (int) Tools::getValue('id_tax_rule');
     $id_tax = (int) Tools::getValue('id_tax');
     $id_tax_rules_group = (int) Tools::getValue('id_tax_rules_group');
     $behavior = (int) Tools::getValue('behavior');
     $description = pSQL(Tools::getValue('description'));
     $this->selected_countries = Tools::getValue('country');
     $this->selected_states = Tools::getValue('states');
     if (empty($this->selected_states) || count($this->selected_states) == 0) {
         $this->selected_states = array(0);
     }
     foreach ($this->selected_countries as $id_country) {
         foreach ($this->selected_states as $id_state) {
             $tr = new TaxRule();
             // update or creation?
             if (isset($id_rule)) {
                 $tr->id = $id_rule;
             }
             $tr->id_tax = $id_tax;
             $tr->id_tax_rules_group = (int) $id_tax_rules_group;
             $tr->id_country = (int) $id_country;
             $tr->id_state = (int) $id_state;
             list($tr->zipcode_from, $tr->zipcode_to) = $tr->breakDownZipCode($zip_code);
             // Construct Object Country
             $country = new Country((int) $id_country);
             if ($zip_code && $country->need_zip_code) {
                 if ($country->zip_code_format) {
                     foreach (array($tr->zipcode_from, $tr->zipcode_to) as $zip_code) {
                         if ($zip_code) {
                             if (!$country->checkZipCode($zip_code)) {
                                 $this->errors[] = sprintf(Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
                             }
                         }
                     }
                 }
             }
             $tr->behavior = (int) $behavior;
             $tr->description = $description;
             $this->tax_rule = $tr;
             $_POST['id_state'] = $tr->id_state;
             $this->errors = array_merge($this->errors, $this->validateTaxRule($tr));
             if (count($this->errors) == 0) {
                 if (!$tr->save()) {
                     $this->errors[] = Tools::displayError('An error has occurred: Can\'t save the current tax rule');
                 } else {
                     Tools::redirectAdmin(self::$currentIndex . '&' . $this->identifier . '=' . $tr->id_tax_rules_group . '&conf=4&update' . $this->table . '&token=' . $this->token);
                 }
             }
         }
     }
     if (count($this->errors) == 0) {
         Tools::redirectAdmin(self::$currentIndex . '&' . $this->identifier . '=' . (int) $id_tax_rules_group . '&conf=4&update' . $this->table . '&token=' . $this->token);
     } else {
         $this->display = 'edit';
     }
 }
示例#6
0
 private function checkCSVZip($id_country, $iso_code)
 {
     $country = new Country($id_country);
     return $country->checkZipCode($iso_code);
 }
示例#7
0
 public function postProcess()
 {
     if (isset($_POST['submitAdd' . $this->table])) {
         /* Cleaning fields */
         foreach ($_POST as $kp => $vp) {
             $_POST[$kp] = trim($vp);
         }
         /* If the selected country does not contain states */
         $id_state = (int) Tools::getValue('id_state');
         if ($id_country = Tools::getValue('id_country') and $country = new Country((int) $id_country) and !(int) $country->contains_states and $id_state) {
             $this->_errors[] = Tools::displayError('You have selected a state for a country that does not contain states.');
         }
         /* If the selected country contains states, then a state have to be selected */
         if ((int) $country->contains_states and !$id_state) {
             $this->_errors[] = Tools::displayError('An address located in a country containing states must have a state selected.');
         }
         $latitude = (double) Tools::getValue('latitude');
         $longitude = (double) Tools::getValue('longitude');
         if (empty($latitude) or empty($longitude)) {
             $this->_errors[] = Tools::displayError('Latitude and longitude are required.');
         }
         $postcode = Tools::getValue('postcode');
         /* Check zip code format */
         if ($country->zip_code_format && !$country->checkZipCode($postcode)) {
             $this->_errors[] = Tools::displayError('Your zip/postal code is incorrect.') . '<br />' . Tools::displayError('Must be typed as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
         } elseif (empty($postcode) && $country->need_zip_code) {
             $this->_errors[] = Tools::displayError('Postcode required.');
         } elseif ($postcode && !Validate::isPostCode($postcode)) {
             $this->_errors[] = Tools::displayError('Your zip/postal code is incorrect.');
         }
         /* Store hours */
         $_POST['hours'] = array();
         for ($i = 1; $i < 8; $i++) {
             $_POST['hours'][] .= Tools::getValue('hours_' . (int) $i);
         }
         $_POST['hours'] = serialize($_POST['hours']);
     }
     if (!sizeof($this->_errors)) {
         parent::postProcess();
     }
 }
 public function postProcess()
 {
     if (isset($_POST['submitAdd' . $this->table])) {
         // Transform e-mail in id_customer for parent processing
         if ($this->addressType == 'customer') {
             if (Validate::isEmail(Tools::getValue('email'))) {
                 $customer = new Customer();
                 $customer->getByEmail(Tools::getValue('email'), null, true);
                 if (Validate::isLoadedObject($customer)) {
                     $_POST['id_customer'] = $customer->id;
                 } else {
                     $this->_errors[] = Tools::displayError('This e-mail address is not registered.');
                 }
             } elseif ($id_customer = Tools::getValue('id_customer')) {
                 $customer = new Customer((int) $id_customer);
                 if (Validate::isLoadedObject($customer)) {
                     $_POST['id_customer'] = $customer->id;
                 } else {
                     $this->_errors[] = Tools::displayError('Unknown customer');
                 }
             } else {
                 $this->_errors[] = Tools::displayError('Unknown customer');
             }
             if (Country::isNeedDniByCountryId(Tools::getValue('id_country')) and !Tools::getValue('dni')) {
                 $this->_errors[] = Tools::displayError('Identification number is incorrect or has already been used.');
             }
         }
         // Check manufacturer selected
         if ($this->addressType == 'manufacturer') {
             $manufacturer = new Manufacturer((int) Tools::getValue('id_manufacturer'));
             if (!Validate::isLoadedObject($manufacturer)) {
                 $this->_errors[] = Tools::displayError('Manufacturer selected is not valid.');
             }
         }
         /* If the selected country does not contain states */
         $id_state = (int) Tools::getValue('id_state');
         if ($id_country = Tools::getValue('id_country') and $country = new Country((int) $id_country) and !(int) $country->contains_states and $id_state) {
             $this->_errors[] = Tools::displayError('You have selected a state for a country that does not contain states.');
         }
         /* If the selected country contains states, then a state have to be selected */
         if ((int) $country->contains_states && !$id_state) {
             $this->_errors[] = Tools::displayError('An address located in a country containing states must have a state selected.');
         }
         $postcode = Tools::getValue('postcode');
         /* Check zip code format */
         if ($country->zip_code_format && !$country->checkZipCode($postcode)) {
             $this->_errors[] = Tools::displayError('Your zip/postal code is incorrect.') . '<br />' . Tools::displayError('Must be typed as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
         } elseif (empty($postcode) && $country->need_zip_code) {
             $this->_errors[] = Tools::displayError('Postcode required.');
         } elseif ($postcode && !Validate::isPostCode($postcode)) {
             $this->_errors[] = Tools::displayError('Your zip/postal code is incorrect.');
         }
         /* If this address come from order's edition and is the same as the other one (invoice or delivery one)
          ** we delete its id_address to force the creation of a new one */
         if ((int) Tools::getValue('id_order')) {
             $this->_redirect = false;
             if (isset($_POST['address_type'])) {
                 $_POST['id_address'] = '';
             }
         }
     }
     if (Tools::getIsset('delete' . $this->table) && $this->tabAccess['delete'] === '1') {
         call_user_func_array(array($this->className, '_cleanCart'), array(null, (int) Tools::getValue('id_address')));
     }
     if (!sizeof($this->_errors)) {
         parent::postProcess();
     }
     /* Reassignation of the order's new (invoice or delivery) address */
     $address_type = (int) Tools::getValue('address_type') == 2 ? 'invoice' : ((int) Tools::getValue('address_type') == 1 ? 'delivery' : '');
     if (isset($_POST['submitAdd' . $this->table]) and $id_order = (int) Tools::getValue('id_order') and !sizeof($this->_errors) and !empty($address_type)) {
         if (!Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'orders SET `id_address_' . $address_type . '` = ' . Db::getInstance()->Insert_ID() . ' WHERE `id_order` = ' . $id_order)) {
             $this->_errors[] = Tools::displayError('An error occurred while linking this address to its order.');
         } else {
             Tools::redirectAdmin(Tools::getValue('back') . '&conf=4');
         }
     }
 }