Jump to content

Price override in hook ActionProductPriceCalculation removes all taxes


neoweiter

Recommended Posts

Hi everyone

I made a module with this hook

    public function hookActionProductPriceCalculation($params)
    {
        if (empty($params['cart']) || !Validate::isLoadedObject($params['cart'])) {
            return;
        }

        $id_product = (int)$params['id_product'];

        $prices = PriceController::getStaticPrices($id_product); // Custom Class with new price calculation

        if ($prices && isset($prices['final_price'])) {
            $params['price'] = (float)$prices['final_price'];
        }
    }

this simply overrides all my products Tax Excl. prices in the Cart and in final Order.

This works well, but strangely the Cart Total does not count the Taxes anymore. My total Tax Incl. is the same as the total Tax Exc. amount like if the total tax was 0.00

Why is that ? How can I fix the total tax incl ?

Thanks

Edited by neoweiter (see edit history)
Link to comment
Share on other sites

test with:

public function hookActionProductPriceCalculation($params)
{
    // Validate cart object
    if (empty($params['cart']) || !Validate::isLoadedObject($params['cart'])) {
        return;
    }

    $id_product = (int)$params['id_product'];
    
    // Get custom price from your PriceController
    $prices = PriceController::getStaticPrices($id_product);

    if ($prices && isset($prices['final_price'])) {
        $price_excl = (float)$prices['final_price']; // Assume this is tax-excluded price

        // Load product to get tax info
        $product = new Product($id_product);
        $taxCalculator = $product->getTaxCalculator($params['cart']->id_address_delivery);

        // Set tax-exclusive and tax-inclusive prices
        $params['price'] = $price_excl;
        $params['price_tax_exc'] = $price_excl;
        $params['price_tax_inc'] = $taxCalculator->getInclusivePrice($price_excl);
    }
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...