Jump to content

Use command handler in front


Recommended Posts

Hi,

I need to remove an order cart rule and recalculate the order amounts when the hook validateOrder is executed.

I seen that prestashop have a symfony order controller with the method i need.

        //$oc = new OrderController();

        //$oc->removeCartRuleAction(185,37);

Is possible use this? Recalculate the amounts manually will cause me a lot of bugs :(

The problem is that the commandBus "prestashop.core.command_bus" does not exists for front (i guess)

I tryed to execute the handler class manually, but it need some classes that im not able to create...

 

Thanks.

 

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

Finally i use the same code that use the prestashop core:

$orderProducts = $order->getCartProducts();

            $carrierId = $order->id_carrier;

            $order->total_discounts = (float) abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS, $orderProducts, $carrierId, false, true));

            $order->total_discounts_tax_excl = (float) abs($cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS, $orderProducts, $carrierId, false, true));

            $order->total_discounts_tax_incl = (float) abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS, $orderProducts, $carrierId, false, true));



            $order->total_paid = Tools::ps_round(

                (float) $cart->getOrderTotal(true, Cart::BOTH, $orderProducts, $carrierId, false, true),

                2

            );

            $order->total_paid_tax_excl = Tools::ps_round(

                (float) $cart->getOrderTotal(false, Cart::BOTH, $orderProducts, $carrierId, false, true),

                2

            );

            $order->total_paid_tax_incl = Tools::ps_round(

                (float) $cart->getOrderTotal(true, Cart::BOTH, $orderProducts, $carrierId, false, true),

                2

            );

            $order->update();

 

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...