public function preProcess() { if (Tools::isSubmit('submitAccount') || Tools::isSubmit('submitGuestAccount')) { include_once dirname(__FILE__) . '/../../modules/avalaratax/avalaratax.php'; $avalaraModule = new AvalaraTax(); $avalaraModule->fixPOST(); } parent::preProcess(); }
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(); }
public static function updateCarrierTax(AvalaraTax $avalaraModule, Cart $cart, $id_address, $region, $taxable = true) { /** Update cache only if it is outdated */ if (self::checkCarrierCache($cart)) { $avalaraProducts = array(); foreach ($cart->getProducts() as $product) { $avalaraProducts[] = array('id_product' => (int) $product['id_product'], 'name' => $product['name'], 'description_short' => $product['description_short'], 'quantity' => (int) $product['quantity'], 'total' => (double) $product['price'], 'tax_code' => $taxable ? $avalaraModule->getProductTaxCode((int) $product['id_product']) : 'NT'); } if (count($avalaraProducts)) { // Calculate the carrier taxes $getTaxResult = $avalaraModule->getTax($avalaraProducts, array('cart' => $cart), (int) $id_address); $amount = (double) (isset($getTaxResult['TaxLines']['Shipping']['GetTax']) ? (double) $getTaxResult['TaxLines']['Shipping']['GetTax'] : 0); $total_tax = (double) (isset($getTaxResult['TotalTax']) ? $getTaxResult['TotalTax'] : 0); $total_amount = (double) (isset($getTaxResult['TotalAmount']) ? $getTaxResult['TotalAmount'] : 0); $tax_rate = (double) ($total_amount != 0 ? $total_tax * 100 / $total_amount : 0); $tmp = array('id_carrier' => (int) $cart->id_carrier, 'id_address' => (int) $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); foreach ($cart->getProducts() as $product) { $tmp[] = array('id_product' => (int) $product['id_product'], 'id_product_attribute' => (int) $product['id_product_attribute'], 'quantity' => (int) $product['quantity']); } Db::getInstance()->Execute(' INSERT INTO `' . _DB_PREFIX_ . 'avalara_carrier_cache` (`id_carrier`, `tax_rate`, `region`, `amount`, `update_date`, `id_cart`, `cart_hash`) VALUES (' . (int) $cart->id_carrier . ', ' . (double) $tax_rate . ', \'' . pSQL($region) . '\', ' . (double) $amount . ', \'' . date('Y-m-d H:i:s') . '\', ' . (int) $cart->id . ', \'' . md5(serialize($tmp)) . '\')'); } } }