Exemplo n.º 1
0
 public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null, $id_zone = null)
 {
     include_once _PS_ROOT_DIR_ . '/modules/avalaratax/avalaratax.php';
     /* Instanciate the Avalara module and check if active */
     $avalara = new AvalaraTax();
     if (!$avalara->active) {
         return parent::getPackageShippingCost((int) $id_carrier, $use_tax, $default_country, $product_list);
     }
     /* Retrieve the original carrier fee tax excluded */
     $tax_excluded_cost = parent::getPackageShippingCost((int) $id_carrier, false, $default_country, $product_list);
     /* If we want price without tax or if this carrier is tax free, return this price */
     if (!(int) $this->{Configuration::get('PS_TAX_ADDRESS_TYPE')} || !$use_tax) {
         return $tax_excluded_cost;
     }
     /* If there is no cache or cache expired, we regenerate it */
     if (CacheTools::checkCarrierCache($this)) {
         return parent::getPackageShippingCost((int) $id_carrier, $use_tax, $default_country, $product_list);
     }
     /* If we do already know it, then return it */
     return $tax_excluded_cost + (double) CacheTools::getCarrierTaxAmount($this);
 }
Exemplo n.º 2
0
$ids_product = implode(', ', $ids_product);
$address = new Address((int) $_POST['id_address']);
if (!Validate::isLoadedObject($address)) {
    die('{"hasError":true, "errors":["Error while loading Address"]}');
}
$region = null;
if ((int) $address->id_state) {
    $state = new State((int) $address->id_state);
    if (!Validate::isLoadedObject($state)) {
        die('{"hasError":true, "errors":["Error while loading State"]}');
    }
    $region = $state->iso_code;
}
$taxable = true;
//check if it is outside the state and if we are in united state and if conf AVALARATAX_TAX_OUTSIDE IS ENABLE
if ($region && !Configuration::get('AVALARATAX_TAX_OUTSIDE') && $region != Configuration::get('AVALARATAX_STATE')) {
    $taxable = false;
}
// Check cache before asking Avalara webservice
$pc = CacheTools::checkProductCache($ids_product, $region, $cart);
$cc = CacheTools::checkCarrierCache($cart);
if (!$pc && !$cc) {
    die('{"hasError":false, "cached_tax":true}');
}
if ($pc) {
    CacheTools::updateProductsTax($avalaraModule, $cart, (int) $_POST['id_address'], $region, $taxable);
}
if ($cc) {
    CacheTools::updateCarrierTax($avalaraModule, $cart, (int) $_POST['id_address'], $taxable);
}
die('{"hasError":false, "cached_tax":false, "total_tax":"' . Tools::displayPrice($cart->getOrderTotal() - $cart->getOrderTotal(false)) . '"}');