コード例 #1
0
 public function preProcess()
 {
     if (Tools::isSubmit('submitAddress') || Tools::isSubmit('submitAccount')) {
         include_once dirname(__FILE__) . '/../../modules/avalaratax/avalaratax.php';
         $avalaraModule = new AvalaraTax();
         $avalaraModule->fixPOST();
     }
     parent::preProcess();
 }
コード例 #2
0
 public function processSubmitAddress()
 {
     include_once _PS_MODULE_DIR_ . 'avalaratax/avalaratax.php';
     $avalara_module = new AvalaraTax();
     if ($avalara_module->active) {
         $result = $avalara_module->fixPOST();
         if (isset($result['ResultCode']) && $result['ResultCode'] == 'Error') {
             if (isset($result['Messages']['Summary'])) {
                 foreach ($result['Messages']['Summary'] as $error) {
                     $this->errors[] = Tools::safeOutput($error);
                 }
             } else {
                 $this->errors[] = Tools::displayError('This address cannot be submitted');
             }
             return false;
         }
     }
     parent::processSubmitAddress();
 }
コード例 #3
0
 public function postProcess()
 {
     if (!$this->isOpcModuleActive()) {
         return parent::postProcess();
     }
     $inv_first_on = Configuration::get('OPC_INVOICE_FIRST') == "1";
     if (Tools::isSubmit('submitAddress') && Tools::isSubmit('ajax')) {
         if (Tools::isSubmit('type')) {
             if (Tools::getValue('type') == 'delivery') {
                 if (!$inv_first_on) {
                     $id_address = isset($this->context->cart->id_address_delivery) ? (int) $this->context->cart->id_address_delivery : 0;
                 } else {
                     $id_address = (Tools::isSubmit('id_address') and (int) Tools::getValue('id_address', 0) != $this->context->cart->id_address_invoice) ? (int) Tools::getValue('id_address', 0) : 0;
                 }
             } elseif (Tools::getValue('type') == 'invoice') {
                 if (!$inv_first_on) {
                     $id_address = (Tools::isSubmit('id_address') and (int) Tools::getValue('id_address', 0) != $this->context->cart->id_address_delivery) ? (int) Tools::getValue('id_address', 0) : 0;
                 } else {
                     $id_address = isset($this->context->cart->id_address_invoice) ? (int) $this->context->cart->id_address_invoice : 0;
                 }
             } else {
                 exit;
             }
         } else {
             $id_address = (int) Tools::getValue('id_address', 0);
         }
         if (Tools::getValue('alias') == Tools::getValue('default_alias') && Tools::getValue('address1') && trim(Tools::getValue('address1')) != "") {
             $_POST['alias'] = Tools::substr(preg_replace('/[;#]/', '_', Tools::getValue('address1')), 0, 32);
         }
         $address = new Address();
         $this->errors = $address->validateController();
         if (Tools::getValue('type') == 'invoice' && isset($id_address) && $id_address > 0) {
             $this->context->cart->id_address_invoice = $id_address;
             $this->context->cart->update();
         }
         $address_old = new Address((int) $id_address);
         if (!sizeof($this->errors) && isset($id_address) && (int) $id_address > 0 && Validate::isLoadedObject($address_old) and Customer::customerHasAddress((int) $this->context->cookie->id_customer, (int) $address_old->id)) {
             if ($address_old->isUsed() && $address_old->isDifferent($address)) {
                 $address_1 = new Address();
                 $_POST['alias'] = Tools::substr(preg_replace('/[;#]/', '_', Tools::getValue('address1')), 0, 32);
                 $this->errors = $address_1->validateController();
                 $address_1->id_customer = (int) $this->context->cookie->id_customer;
                 if ((!Tools::getValue('phone') and !Tools::getValue('phone_mobile')) || (!($country = new Country((int) $address_1->id_country)) or !Validate::isLoadedObject($country)) || ($country->isNeedDni() and (!Tools::getValue('dni') or !Validate::isDniLite(Tools::getValue('dni')))) || ((int) $country->contains_states and !(int) $address_1->id_state)) {
                 } elseif ($result = $address_1->save()) {
                     $id_address = $address_1->id;
                     if (Tools::getValue('type') == 'delivery') {
                         if ($this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice) {
                             $this->context->cart->id_address_invoice = (int) $address_1->id;
                         }
                         $this->context->cart->id_address_delivery = (int) $address_1->id;
                         $this->context->cart->update();
                     }
                     if (Tools::getValue('type') == 'invoice') {
                         if ($this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice) {
                             $this->context->cart->id_address_delivery = (int) $address_1->id;
                         }
                         $this->context->cart->id_address_invoice = (int) $address_1->id;
                         $this->context->cart->update();
                     }
                 }
             }
         }
         $this->_processSubmitAddress($id_address, Tools::getValue('type'));
     } elseif (Tools::isSubmit('partialSubmitAddress')) {
         // called separately for delivery country/state change and invoice country/state change
         $is_separate_invoice_address = Tools::getValue('invoice_address');
         $is_separate_delivery_address = Tools::getValue('delivery_address');
         $type = Tools::getValue('type');
         $id_country = Tools::getValue('id_country');
         $id_state = Tools::getValue('id_state');
         $postcode = Tools::getValue('postcode');
         $city = Tools::getValue('city');
         $firstname = Tools::getValue('firstname');
         $lastname = Tools::getValue('lastname');
         $addr1 = Tools::getValue('address1');
         $id_address_delivery = 0;
         $id_address_invoice = 0;
         $create_different_delivery_address = 0;
         $create_different_invoice_address = 0;
         $last_addr_id = 0;
         $last_addr_ids_tmp = Customer::getLastTwoCustomerAddressIds($this->context->cart->id_customer);
         if ($id_country !== false && $id_state !== false) {
             if ($type == 'delivery' && isset($this->context->cart->id_address_delivery) && $this->context->cart->id_address_delivery > 0) {
                 $address_old1 = new Address((int) $this->context->cart->id_address_delivery);
                 $address1 = new Address();
                 $errors1 = $address1->validateController();
                 if (Validate::isLoadedObject($address_old1) && $address_old1->isUsed() && $address_old1->isDifferent($address1, true)) {
                     $create_different_delivery_address = 1;
                 }
             }
             if ($is_separate_invoice_address) {
                 if ($this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice) {
                     $create_different_invoice_address = 1;
                 }
                 if (isset($last_addr_ids_tmp) && $last_addr_ids_tmp != false && is_array($last_addr_ids_tmp) && count($last_addr_ids_tmp) > 0) {
                     foreach ($last_addr_ids_tmp as $item) {
                         if ($item != $this->context->cart->id_address_delivery) {
                             $last_addr_id = $item;
                             break;
                         }
                     }
                 }
             }
             if ($is_separate_delivery_address) {
                 if ($this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice) {
                     $create_different_delivery_address = 1;
                 }
                 if (isset($last_addr_ids_tmp) && $last_addr_ids_tmp != false && is_array($last_addr_ids_tmp) && count($last_addr_ids_tmp) > 0) {
                     foreach ($last_addr_ids_tmp as $item) {
                         if ($item != $this->context->cart->id_address_invoice) {
                             $last_addr_id = $item;
                             break;
                         }
                     }
                 }
             }
             if ($type == 'delivery') {
                 $id_address_delivery = $last_addr_id > 0 && $create_different_delivery_address ? $last_addr_id : $this->saveAddress($create_different_delivery_address ? $last_addr_id : $this->context->cart->id_address_delivery, $id_country, $id_state, $postcode, $city, $firstname, $lastname, $addr1);
             } else {
                 $id_address_invoice = $last_addr_id > 0 && $create_different_invoice_address ? $last_addr_id : $this->saveAddress($create_different_invoice_address ? $last_addr_id : $this->context->cart->id_address_invoice, $id_country, $id_state, $postcode, $city, $firstname, $lastname, $addr1);
             }
         }
         if ($id_address_delivery > 0) {
             $this->context->cart->id_address_delivery = $id_address_delivery;
             if ($is_separate_invoice_address == 0 && $is_separate_delivery_address == 0) {
                 $this->context->cart->id_address_invoice = $this->context->cart->id_address_delivery;
             }
         } elseif ($id_address_invoice > 0) {
             $this->context->cart->id_address_invoice = $id_address_invoice;
             if ($is_separate_invoice_address == 0 && $is_separate_delivery_address == 0) {
                 $this->context->cart->id_address_delivery = $this->context->cart->id_address_invoice;
             }
         }
         $this->context->cart->update();
         if (Configuration::get('VATNUMBER_MANAGEMENT') and file_exists(dirname(__FILE__) . '/../../modules/vatnumber/vatnumber.php') && VatNumber::isApplicable($id_country) && Configuration::get('VATNUMBER_COUNTRY') != $id_country) {
             $allow_eu_vat = 1;
         } else {
             $allow_eu_vat = 0;
         }
         if (Tools::isSubmit('ajax')) {
             $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'id_address_delivery' => $this->context->cart->id_address_delivery, 'id_address_invoice' => $this->context->cart->id_address_invoice, 'allow_eu_vat' => $allow_eu_vat);
             die(Tools::jsonEncode($return));
         }
     } else {
         # assign pre-guessed address to this customer
         if (Tools::getValue('type') == 'invoice' && (isset($this->context->cart->id_address_invoice) and $this->context->cart->id_address_invoice != $this->context->cart->id_address_delivery) && isset($this->context->cookie->id_customer) and (int) $this->context->cookie->id_customer > 0) {
             $address_a = new Address($this->context->cart->id_address_invoice);
             $address_a->id_customer = (int) $this->context->cookie->id_customer;
             $address_a->save();
         }
         # then call original postProcess to make standard validations and save to DB
         parent::postProcess();
     }
 }
コード例 #4
0
 public function postProcess()
 {
     if (!$this->isOpcModuleActive()) {
         return parent::postProcess();
     }
     $inv_first_on = Configuration::get('OPC_INVOICE_FIRST') == "1";
     // handle case when already used address (assigned to an order) is being changed - we need to create new one and save it's reference to order
     if (Tools::isSubmit('submitAddress') && Tools::isSubmit('ajax')) {
         if (Tools::isSubmit('type')) {
             if (Tools::getValue('type') == 'delivery') {
                 if (!$inv_first_on) {
                     $id_address = isset($this->context->cart->id_address_delivery) ? (int) $this->context->cart->id_address_delivery : 0;
                 } else {
                     $id_address = (Tools::isSubmit('id_address') and (int) Tools::getValue('id_address', 0) != $this->context->cart->id_address_invoice) ? (int) Tools::getValue('id_address', 0) : 0;
                 }
             } elseif (Tools::getValue('type') == 'invoice') {
                 //$id_address = (isset($this->context->cart->id_address_invoice) AND $this->context->cart->id_address_invoice != $this->context->cart->id_address_delivery) ? (int)$this->context->cart->id_address_invoice : 0;
                 if (!$inv_first_on) {
                     $id_address = (Tools::isSubmit('id_address') and (int) Tools::getValue('id_address', 0) != $this->context->cart->id_address_delivery) ? (int) Tools::getValue('id_address', 0) : 0;
                 } else {
                     $id_address = isset($this->context->cart->id_address_invoice) ? (int) $this->context->cart->id_address_invoice : 0;
                 }
             } else {
                 exit;
             }
         } else {
             $id_address = (int) Tools::getValue('id_address', 0);
         }
         if (Tools::getValue('alias') == Tools::getValue('default_alias') && Tools::getValue('address1') && trim(Tools::getValue('address1')) != "") {
             $_POST['alias'] = Tools::substr(preg_replace('/[;#]/', '_', Tools::getValue('address1')), 0, 32);
         }
         $address = new Address();
         $this->errors = $address->validateController();
         // AuthController sets (hardocded) invoice address to be same as delivery, because of guest checkout can have
         // only delivery address (in standard OPC)
         if (Tools::getValue('type') == 'invoice' && isset($id_address) && $id_address > 0) {
             $this->context->cart->id_address_invoice = $id_address;
             $this->context->cart->update();
         }
         $address_old = new Address((int) $id_address);
         if (!sizeof($this->errors) && isset($id_address) && (int) $id_address > 0 && Validate::isLoadedObject($address_old) and Customer::customerHasAddress((int) $this->context->cookie->id_customer, (int) $address_old->id)) {
             if ($address_old->isUsed() && $address_old->isDifferent($address)) {
                 // save as new and assing reference to cart
                 $address_1 = new Address();
                 $_POST['alias'] = Tools::substr(preg_replace('/[;#]/', '_', Tools::getValue('address1')), 0, 32);
                 $this->errors = $address_1->validateController();
                 $address_1->id_customer = (int) $this->context->cookie->id_customer;
                 if ((!Tools::getValue('phone') and !Tools::getValue('phone_mobile')) || (!($country = new Country((int) $address_1->id_country)) or !Validate::isLoadedObject($country)) || ($country->isNeedDni() and (!Tools::getValue('dni') or !Validate::isDniLite(Tools::getValue('dni')))) || ((int) $country->contains_states and !(int) $address_1->id_state)) {
                     /* empty */
                 } elseif ($result = $address_1->save()) {
                     $id_address = $address_1->id;
                     if (Tools::getValue('type') == 'delivery') {
                         if ($this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice) {
                             $this->context->cart->id_address_invoice = (int) $address_1->id;
                         }
                         $this->context->cart->id_address_delivery = (int) $address_1->id;
                         $this->context->cart->update();
                     }
                     if (Tools::getValue('type') == 'invoice') {
                         if ($this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice) {
                             $this->context->cart->id_address_delivery = (int) $address_1->id;
                         }
                         $this->context->cart->id_address_invoice = (int) $address_1->id;
                         $this->context->cart->update();
                     }
                 }
             }
             //if ($address_old->isUsed)
         }
         //if (Validate::isLoaded...)
         $this->_processSubmitAddress($id_address, Tools::getValue('type'));
         // parent::postProcess(); // call parent's method anyway, we only wanted to store this new address
     } elseif (Tools::isSubmit('partialSubmitAddress')) {
         // called separately for delivery country/state change and invoice country/state change
         // $this->context->cookie->id_cart by mohol byt kluc ku mazaniu adresy pri vytvoreni skutocneho accountu
         // not-null DB fields: id_address, id_country, alias, lastname, firstname, address1, city
         $is_separate_invoice_address = Tools::getValue('invoice_address');
         $is_separate_delivery_address = Tools::getValue('delivery_address');
         // $type is 'delivery' or 'invoice'
         $type = Tools::getValue('type');
         // Delivery address
         $id_country = Tools::getValue('id_country');
         $id_state = Tools::getValue('id_state');
         $postcode = Tools::getValue('postcode');
         $city = Tools::getValue('city');
         $firstname = Tools::getValue('firstname');
         $lastname = Tools::getValue('lastname');
         $addr1 = Tools::getValue('address1');
         $id_address_delivery = 0;
         $id_address_invoice = 0;
         $create_different_delivery_address = 0;
         $create_different_invoice_address = 0;
         $last_addr_id = 0;
         $last_addr_ids_tmp = Customer::getLastTwoCustomerAddressIds($this->context->cart->id_customer);
         if ($id_country !== false && $id_state !== false) {
             /* type is delivery AND cart's address is used and cart's address is different than form post*/
             if ($type == 'delivery' && isset($this->context->cart->id_address_delivery) && $this->context->cart->id_address_delivery > 0) {
                 $address_old1 = new Address((int) $this->context->cart->id_address_delivery);
                 $address1 = new Address();
                 $errors1 = $address1->validateController();
                 if (Validate::isLoadedObject($address_old1) && $address_old1->isUsed() && $address_old1->isDifferent($address1, true)) {
                     $create_different_delivery_address = 1;
                 }
             }
             if ($is_separate_invoice_address) {
                 if ($this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice) {
                     $create_different_invoice_address = 1;
                 }
                 // check whether we have some recently used addresses (excluded actual delivery address)
                 if (isset($last_addr_ids_tmp) && $last_addr_ids_tmp != false && is_array($last_addr_ids_tmp) && count($last_addr_ids_tmp) > 0) {
                     foreach ($last_addr_ids_tmp as $item) {
                         if ($item != $this->context->cart->id_address_delivery) {
                             $last_addr_id = $item;
                             break;
                         }
                     }
                 }
                 //if (isset($last_addr_ids_tmp)...
             }
             //if  ($is_separate_invoice_address)
             if ($is_separate_delivery_address) {
                 if ($this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice) {
                     $create_different_delivery_address = 1;
                 }
                 // check whether we have some recently used addresses (excluded actual delivery address)
                 if (isset($last_addr_ids_tmp) && $last_addr_ids_tmp != false && is_array($last_addr_ids_tmp) && count($last_addr_ids_tmp) > 0) {
                     foreach ($last_addr_ids_tmp as $item) {
                         if ($item != $this->context->cart->id_address_invoice) {
                             $last_addr_id = $item;
                             break;
                         }
                     }
                 }
                 //if (isset($last_addr_ids_tmp)...
             }
             //if  ($is_separate_delivery_address)
             if ($type == 'delivery') {
                 $id_address_delivery = $last_addr_id > 0 && $create_different_delivery_address ? $last_addr_id : $this->saveAddress($create_different_delivery_address ? $last_addr_id : $this->context->cart->id_address_delivery, $id_country, $id_state, $postcode, $city, $firstname, $lastname, $addr1);
             } else {
                 $id_address_invoice = $last_addr_id > 0 && $create_different_invoice_address ? $last_addr_id : $this->saveAddress($create_different_invoice_address ? $last_addr_id : $this->context->cart->id_address_invoice, $id_country, $id_state, $postcode, $city, $firstname, $lastname, $addr1);
             }
         }
         if ($id_address_delivery > 0) {
             $this->context->cart->id_address_delivery = $id_address_delivery;
             if ($is_separate_invoice_address == 0 && $is_separate_delivery_address == 0) {
                 $this->context->cart->id_address_invoice = $this->context->cart->id_address_delivery;
             }
         } elseif ($id_address_invoice > 0) {
             $this->context->cart->id_address_invoice = $id_address_invoice;
             if ($is_separate_invoice_address == 0 && $is_separate_delivery_address == 0) {
                 $this->context->cart->id_address_delivery = $this->context->cart->id_address_invoice;
             }
         }
         $this->context->cart->update();
         if (Configuration::get('VATNUMBER_MANAGEMENT') and file_exists(dirname(__FILE__) . '/../../modules/vatnumber/vatnumber.php') && VatNumber::isApplicable($id_country) && Configuration::get('VATNUMBER_COUNTRY') != $id_country) {
             $allow_eu_vat = 1;
         } else {
             $allow_eu_vat = 0;
         }
         if (Tools::isSubmit('ajax')) {
             $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'id_address_delivery' => $this->context->cart->id_address_delivery, 'id_address_invoice' => $this->context->cart->id_address_invoice, 'allow_eu_vat' => $allow_eu_vat);
             die(Tools::jsonEncode($return));
         }
     } else {
         # assign pre-guessed address to this customer
         if (Tools::getValue('type') == 'invoice' && (isset($this->context->cart->id_address_invoice) and $this->context->cart->id_address_invoice != $this->context->cart->id_address_delivery) && isset($this->context->cookie->id_customer) and (int) $this->context->cookie->id_customer > 0) {
             $address_a = new Address($this->context->cart->id_address_invoice);
             $address_a->id_customer = (int) $this->context->cookie->id_customer;
             $address_a->save();
         }
         # then call original postProcess to make standard validations and save to DB
         parent::postProcess();
     }
 }