Jump to content

Retrieve $_POST value in ActionCarrierProcess hook


Recommended Posts

Hello,

I've developped a small Carrier module to add delivery options with checkboxes.

I'm displaying the checkboxes with the DisplayCarrierExtraContent hook.

My problem is I don't know how to retrieve the $_POST values from the form. My module hookActionCarrierProcess method is correctly called, but it seems that the $_POST variable is empty (dumping it is showing [ ]). I've tried with Tools::getValue but obviously it returns false too.

When I press the submit button after selecting my carrier and checking some options, it seems that the $_POST values are correctly sent but the server responds with the following HTTP code: 302 Moved Temporarly.  What's weird is that submitting the form does trigger my code from the hookActionCarrierProcess  method.

 

Why is $_POST value empty when hookActionCarrierProcess  is called ?

Is there another way to send the form values (the checkboxes) to the hookActionCarrierProcess  method ?

 

I hope I am clear enough.

Thanks a lot for your help

 

 

 

 

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

  • 1 year later...

I ended up overriding OrderController::displayAjaxselectDeliveryOption in my module. From there you can access Tools::getValue('your_value')

 

<?php

// modules/MyModule/override/controllers/front/OrderController.php

class OrderController extends OrderControllerCore {
    public function displayAjaxselectDeliveryOption()
    {
        $cart = $this->cart_presenter->present(
            $this->context->cart
        );
        
        if ($this->context->cart->id_carrier == Configuration::get('MY_DELIVERY_CARRIER_ID')) {
            // Setting the options here            
        }

        ob_end_clean();
        header('Content-Type: application/json');
        $this->ajaxDie(Tools::jsonEncode(array(
            'preview' => $this->render('checkout/_partials/cart-summary', array(
                'cart' => $cart,
                'static_token' => Tools::getToken(false),
            ))
        )));
    }
}

 

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