/** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { parent::initContent(); if ($this->customer->birthday) { $birthday = explode('-', $this->customer->birthday); } else { $birthday = array('-', '-', '-'); } /* Generate years, months and days */ $this->context->smarty->assign(array('years' => Tools::dateYears(), 'sl_year' => $birthday[0], 'months' => Tools::dateMonths(), 'sl_month' => $birthday[1], 'days' => Tools::dateDays(), 'sl_day' => $birthday[2], 'errors' => $this->errors, 'genders' => Gender::getGenders())); if (Module::isInstalled('blocknewsletter')) { $this->context->smarty->assign('newsletter', (int) Module::getInstanceByName('blocknewsletter')->active); } // start of implementation of the module code - taxamo // Get selected country if (Tools::isSubmit('taxamoisocountryresidence') && !is_null(Tools::getValue('taxamoisocountryresidence'))) { $selected_country = Tools::getValue('taxamoisocountryresidence'); } else { $selected_country = Taxamoeuvat::getCountryByCustomer($this->customer->id); } // Generate countries list if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) { $countries = Carrier::getDeliveredCountries($this->context->language->id, true, true); } else { $countries = Country::getCountries($this->context->language->id, true); } /* todo use helper */ $list = '<option value="">-</option>'; foreach ($countries as $country) { $selected = $country['iso_code'] == $selected_country ? 'selected="selected"' : ''; $list .= '<option value="' . $country['iso_code'] . '" ' . $selected . '>' . htmlentities($country['name'], ENT_COMPAT, 'UTF-8') . '</option>'; } // Get selected cc prefix if (Tools::isSubmit('taxamoccprefix') && !is_null(Tools::getValue('taxamoccprefix'))) { $taxamo_cc_prefix = Tools::getValue('taxamoccprefix'); } else { $taxamo_cc_prefix = Taxamoeuvat::getPrefixByCustomer($this->customer->id); } if ($this->customer->id) { $this->context->smarty->assign(array('countries_list' => $list, 'taxamoisocountryresidence' => $selected_country, 'taxamoccprefix' => $taxamo_cc_prefix)); } // end of code implementation module - taxamo $this->setTemplate(_PS_THEME_DIR_ . 'identity.tpl'); }
public static function taxamoStoreTransaction($id_currency, $id_address_invoice, $id_customer, $order_products) { $exists_comments = false; $res_process = array('key_transaction' => null, 'comment' => ''); $transaction_lines = array(); $info_transaction_lines = array(); $valid_currency = self::validCurrency($id_currency); if (isset($valid_currency['error'])) { $res_process['comment'] .= '* ' . $valid_currency['error']; $exists_comments = true; } else { $currency_code = $valid_currency['currency_code']; } if (!$exists_comments) { $merchants_self_settings = self::getMerchantsSelfSettings(); if (isset($merchants_self_settings['error'])) { $res_process['comment'] .= '* ' . $merchants_self_settings['error']; $exists_comments = true; } } if (!$exists_comments) { $product_types = self::getDictionariesProductTypes(); if (isset($product_types['error'])) { $res_process['comment'] .= '* ' . $product_types['error']; $exists_comments = true; } else { $generic_name = Tools::getValue('TAXAMOEUVAT_GENERICNAME', Configuration::get('TAXAMOEUVAT_GENERICNAME')); $arr_tax_rules_group = array(); foreach ($product_types as $product_type) { $tax_group_name = $generic_name . ' - ' . $product_type; $arr_tax_rules_group[$product_type] = TaxRulesGroup::getIdByName($tax_group_name); } } } if (!$exists_comments) { foreach ($order_products as $product) { $id_tax_rules_group = $product['id_tax_rules_group']; $product_type = null; foreach ($arr_tax_rules_group as $key_product_type => $val_id_product_type) { if ($id_tax_rules_group == $val_id_product_type) { $product_type = $key_product_type; break 1; } } if (is_null($product_type)) { $transaction_lines[] = array('custom_id' => (string) $product['id_product'], 'quantity' => $product['cart_quantity'], 'unit_price' => $product['price'], 'informative' => true, 'tax_rate' => $product['tax_rate']); } else { $transaction_lines[] = array('custom_id' => (string) $product['id_product'], 'quantity' => $product['cart_quantity'], 'unit_price' => $product['price'], 'product_type' => $product_type); } $info_transaction_lines[(string) $product['id_product']] = array('product_type' => $product_type, 'quantity' => $product['cart_quantity'], 'unit_price' => $product['price'], 'amount' => $product['total_price'], 'tax_rate' => $product['tax_rate'], 'tax_amount' => $product['total_wt'] - $product['total_price'], 'total_amount' => $product['total_wt']); } } if (count($transaction_lines)) { $invoice_address = new Address((int) $id_address_invoice); $iso_country_code = Country::getIsoById($invoice_address->id_country); $success_verify_taxes = false; if ($merchants_self_settings['allow_eu_b2b']) { if ((bool) Configuration::get('PS_B2B_ENABLE')) { if (!is_null($invoice_address->vat_number) && !empty($invoice_address->vat_number)) { $params_tax_calculate = array('currency_code' => $currency_code, 'buyer_tax_number' => $invoice_address->vat_number, 'invoice_address' => array('street_name' => $invoice_address->address1, 'address_detail' => $invoice_address->address2, 'city' => $invoice_address->city, 'postal_code' => $invoice_address->postcode, 'country' => $iso_country_code)); $tax_calculate = self::transactions($params_tax_calculate, $transaction_lines); $valid_transaction = self::validTransaction($iso_country_code, $tax_calculate); $success_verify_taxes = $valid_transaction['success']; if (isset($valid_transaction['error'])) { $res_process['comment'] .= '* ' . $valid_transaction['error']; $exists_comments = true; $valid_evidence = self::getValidEvidence('by_tax_number', $tax_calculate); if (isset($valid_evidence['error'])) { $res_process['comment'] .= '* ' . $valid_evidence['error']; $exists_comments = true; } } } } } if (!$exists_comments && !$success_verify_taxes) { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $buyer_ip = $_SERVER['HTTP_CLIENT_IP']; // } elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { // $buyer_ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } elseif (!empty($_SERVER['REMOTE_ADDR'])) { $buyer_ip = $_SERVER['REMOTE_ADDR']; } else { $buyer_ip = null; } $params_tax_calculate = array('currency_code' => $currency_code, 'buyer_ip' => $buyer_ip, 'billing_country_code' => $iso_country_code, 'invoice_address' => array('street_name' => $invoice_address->address1, 'address_detail' => $invoice_address->address2, 'city' => $invoice_address->city, 'postal_code' => $invoice_address->postcode, 'country' => $iso_country_code)); $sms_verification = false; if ($merchants_self_settings['allow_sms_verification']) { $verification_token = Taxamoeuvat::getTokenByCustomer($id_customer); if ($verification_token) { $res_api_verify_sms_token = self::taxamoVerifySmsToken($verification_token); if (isset($res_api_verify_sms_token['country_code']) && $res_api_verify_sms_token['country_code'] == $iso_country_code) { $params_tax_calculate['verification_token'] = $verification_token; $sms_verification = true; } else { $iso_country_residence = Taxamoeuvat::getCountryByCustomer($id_customer); $cc_prefix = Taxamoeuvat::getPrefixByCustomer($id_customer); Taxamoeuvat::updateCCPrefix($id_customer, $iso_country_residence, $cc_prefix, null); } } } $tax_calculate = self::transactions($params_tax_calculate, $transaction_lines); if (isset($tax_calculate['error'])) { $res_process['comment'] .= '* ' . $tax_calculate['error']; $exists_comments = true; } else { $valid_transaction = self::validTransaction($iso_country_code, $tax_calculate); $success_verify_taxes = $valid_transaction['success']; if (isset($valid_transaction['error'])) { if (!$valid_transaction['no_country_match'] || $valid_transaction['no_country_match'] && !$merchants_self_settings['allow_self_declaration']) { $res_process['comment'] .= '* ' . $valid_transaction['error']; $exists_comments = true; } } } $no_buyer_credit_card_prefix = false; $no_force_country_code = false; //si el procedimiento de b2b y normal no se ejecuto o no fue exitoso se procede a una validacion con self declaration if (!$success_verify_taxes && !$sms_verification && $merchants_self_settings['allow_self_declaration']) { $exists_comments = false; $res_process['comment'] = ''; $buyer_credit_card_prefix = Taxamoeuvat::getPrefixByCustomer($id_customer); if (is_null($buyer_credit_card_prefix) || empty($buyer_credit_card_prefix)) { $no_buyer_credit_card_prefix = true; } else { $params_tax_calculate['buyer_credit_card_prefix'] = $buyer_credit_card_prefix; } $force_country_code = Taxamoeuvat::getCountryByCustomer($id_customer); if (is_null($force_country_code) || empty($force_country_code)) { $no_force_country_code = true; } else { $params_tax_calculate['force_country_code'] = $force_country_code; } if (!$no_buyer_credit_card_prefix || !$no_force_country_code) { $tax_calculate = self::transactions($params_tax_calculate, $transaction_lines); $valid_transaction = self::validTransaction($iso_country_code, $tax_calculate); $success_verify_taxes = $valid_transaction['success']; if (isset($valid_transaction['error'])) { $res_process['comment'] .= '* ' . $valid_transaction['error']; $exists_comments = true; } } if (!$success_verify_taxes) { $valid_evidence = self::getValidEvidence('by_cc', $tax_calculate); if (isset($valid_evidence['error'])) { $res_process['comment'] .= '* ' . $valid_evidence['error']; $exists_comments = true; } $valid_evidence = self::getValidEvidence('forced', $tax_calculate); if (isset($valid_evidence['error'])) { $res_process['comment'] .= '* ' . $valid_evidence['error']; $exists_comments = true; } } } } // if ($success_verify_taxes) if (isset($tax_calculate['key']) && !is_null($tax_calculate['key']) && !empty($tax_calculate['key'])) { $valid_transaction_lines = self::validTransactionLines($info_transaction_lines, $tax_calculate); if (isset($tax_calculate['key'])) { $res_process['key_transaction'] = $tax_calculate['key']; } if (!$valid_transaction_lines['success']) { $success_verify_taxes = false; foreach ($valid_transaction_lines['errors'] as $error) { $res_process['comment'] .= '* ' . $error; } $exists_comments = true; } } } return $res_process; }
/** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { parent::initContent(); if (Tools::isSubmit('ajax') && Tools::getValue('method') == 'updateExtraCarrier') { // Change virtualy the currents delivery options $delivery_option = $this->context->cart->getDeliveryOption(); $delivery_option[(int) Tools::getValue('id_address')] = Tools::getValue('id_delivery_option'); $this->context->cart->setDeliveryOption($delivery_option); $this->context->cart->save(); $return = array('content' => Hook::exec('displayCarrierList', array('address' => new Address((int) Tools::getValue('id_address'))))); die(Tools::jsonEncode($return)); } // start of implementation of the module code - taxamo if ((int) $this->step == 2) { // $this->errors = array_merge($this->errors, $taxamo_errores); // $this->step = 0; $merchants_self_settings = Tools::getMerchantsSelfSettings(); if ($merchants_self_settings['allow_sms_verification']) { $invoice_address = new Address((int) $this->context->cart->id_address_invoice); $iso_country_code = Country::getIsoById($invoice_address->id_country); $token_taxamo = Tools::getValue('tokenTaxamo'); if ($token_taxamo) { $res_api_verify_sms_token = Tools::taxamoVerifySmsToken($token_taxamo); if (isset($res_api_verify_sms_token['country_code']) && $res_api_verify_sms_token['country_code'] == $iso_country_code) { Taxamoeuvat::updateCCPrefix((int) $this->context->cart->id_customer, null, null, $token_taxamo); } else { $iso_country_residence = Taxamoeuvat::getCountryByCustomer((int) $this->context->cart->id_customer); $cc_prefix = Taxamoeuvat::getPrefixByCustomer((int) $this->context->cart->id_customer); Taxamoeuvat::updateCCPrefix((int) $this->context->cart->id_customer, $iso_country_residence, $cc_prefix, null); } } } if ($taxamo_errores = Tools::taxamoVerifyTaxes($this->context->cart)) { $this->errors = array_merge($this->errors, $taxamo_errores); $this->context->smarty->assign('allow_sms_verification', $merchants_self_settings['allow_sms_verification']); if ($merchants_self_settings['allow_sms_verification']) { $this->context->smarty->assign('iso_country_code', $iso_country_code); $country_name = Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), $invoice_address->id_country); $this->context->smarty->assign('country_name', $country_name); } $this->setTemplate(_PS_MODULE_DIR_ . 'taxamoeuvat/views/templates/front/info.tpl'); return; } } // end of code implementation module - taxamo if ($this->nbProducts) { $this->context->smarty->assign('virtual_cart', $this->context->cart->isVirtualCart()); } if (!Tools::getValue('multi-shipping')) { $this->context->cart->setNoMultishipping(); } // 4 steps to the order switch ((int) $this->step) { case -1: $this->context->smarty->assign('empty', 1); $this->setTemplate(_PS_THEME_DIR_ . 'shopping-cart.tpl'); break; case 1: $this->_assignAddress(); $this->processAddressFormat(); if (Tools::getValue('multi-shipping') == 1) { $this->_assignSummaryInformations(); $this->context->smarty->assign('product_list', $this->context->cart->getProducts()); $this->setTemplate(_PS_THEME_DIR_ . 'order-address-multishipping.tpl'); } else { $this->setTemplate(_PS_THEME_DIR_ . 'order-address.tpl'); } break; case 2: if (Tools::isSubmit('processAddress')) { $this->processAddress(); } $this->autoStep(); $this->_assignCarrier(); $this->setTemplate(_PS_THEME_DIR_ . 'order-carrier.tpl'); break; case 3: // Check that the conditions (so active) were accepted by the customer $cgv = Tools::getValue('cgv') || $this->context->cookie->check_cgv; if (Configuration::get('PS_CONDITIONS') && (!Validate::isBool($cgv) || $cgv == false)) { Tools::redirect('index.php?controller=order&step=2'); } Context::getContext()->cookie->check_cgv = true; // Check the delivery option is set if (!$this->context->cart->isVirtualCart()) { if (!Tools::getValue('delivery_option') && !Tools::getValue('id_carrier') && !$this->context->cart->delivery_option && !$this->context->cart->id_carrier) { Tools::redirect('index.php?controller=order&step=2'); } elseif (!Tools::getValue('id_carrier') && !$this->context->cart->id_carrier) { $deliveries_options = Tools::getValue('delivery_option'); if (!$deliveries_options) { $deliveries_options = $this->context->cart->delivery_option; } foreach ($deliveries_options as $delivery_option) { if (empty($delivery_option)) { Tools::redirect('index.php?controller=order&step=2'); } } } } $this->autoStep(); // Bypass payment step if total is 0 if (($id_order = $this->_checkFreeOrder()) && $id_order) { if ($this->context->customer->is_guest) { $order = new Order((int) $id_order); $email = $this->context->customer->email; $this->context->customer->mylogout(); // If guest we clear the cookie for security reason Tools::redirect('index.php?controller=guest-tracking&id_order=' . urlencode($order->reference) . '&email=' . urlencode($email)); } else { Tools::redirect('index.php?controller=history'); } } $this->_assignPayment(); // assign some informations to display cart $this->_assignSummaryInformations(); $this->setTemplate(_PS_THEME_DIR_ . 'order-payment.tpl'); break; default: $this->_assignSummaryInformations(); $this->setTemplate(_PS_THEME_DIR_ . 'shopping-cart.tpl'); break; } $this->context->smarty->assign(array('currencySign' => $this->context->currency->sign, 'currencyRate' => $this->context->currency->conversion_rate, 'currencyFormat' => $this->context->currency->format, 'currencyBlank' => $this->context->currency->blank)); }