Jump to content

Can't retrieve custom form data in OrderController


sdrissi

Recommended Posts

Hi all,

I'm struggling for days now on how to retrieve my custom field 'delivery-date', displayed in CheckoutDeliveryStep of Front Office, in OrderController.

I have tried to get it in OrderController#postProcess function by doing: Tools::getValue('delivery-date') but it doesn't return any value (i.e it returns false).

I have also tried to do print_r($_POST) in this same function but it prints an empty array which is super weird since in chrome's developer tools under network tab I can see the data posted...

Your help would be very much appreciated :)

Thanks!

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

Here's a bit more details (prestashop version 1.7.5.0):

I override in my theme shipping.tpl:

{extends file='parent:checkout/_partials/steps/shipping.tpl'}}

{block name='delivery_options'}
    <div class="delivery-options">
        {foreach from=$delivery_options item=carrier key=carrier_id}
            <div class="row delivery-option">
                <div class="col-sm-1">
                      <span class="custom-radio float-xs-left">
                        <input type="radio" name="delivery_option[{$id_address}]" id="delivery_option_{$carrier.id}" value="{$carrier_id}"{if $delivery_option == $carrier_id} checked{/if}>
                        <span></span>
                      </span>
                </div>
                <label for="delivery_option_{$carrier.id}" class="col-sm-11 delivery-option-2">
                    <div class="row">
                        <div class="col-sm-5 col-xs-12">
                            <div class="row">
                                {if $carrier.logo}
                                    <div class="col-xs-3">
                                        <img src="{$carrier.logo}" alt="{$carrier.name}" />
                                    </div>
                                {/if}
                                <div class="{if $carrier.logo}col-xs-9{else}col-xs-12{/if}">
                                    <span class="h6 carrier-name">{$carrier.name}</span>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-4 col-xs-12">
                            <span class="carrier-delay">{hook h='displayDelayDelivery'}</span>
                        </div>
                        <div class="col-sm-3 col-xs-12">
                            <span class="carrier-price">{$carrier.price}</span>
                        </div>
                    </div>
                </label>
            </div>
            <div class="row carrier-extra-content"{if $delivery_option != $carrier_id} style="display:none;"{/if}>
                {$carrier.extraContent nofilter}
            </div>
            <div class="clearfix"></div>
        {/foreach}
    </div>
{/block}

As you can see I use the displayDelayDelivery custom hook and the code injected is the following:

<div>
    <strong>Livraison: </strong>
    <select name="delivery-date" id="delivery-date">
            {foreach from=$available_delivery_dates item=$date}
                    <option value={$date.date}>{$date.label}</option>
            {/foreach}
        </select>
</div>

When the user validate the carrier, there is a POST request made to OrderController, I expect to retrieve 'delivery-date' field in OrderController:

<?php

class OrderController extends OrderControllerCore {
    public function postProcess()
    {
        parent::postProcess();

        print_r($_POST);

        if (Tools::isSubmit('submitReorder') && $id_order = (int) Tools::getValue('id_order')) {
            $oldCart = new Cart(Order::getCartIdStatic($id_order, $this->context->customer->id));
            $duplication = $oldCart->duplicate();
            if (!$duplication || !Validate::isLoadedObject($duplication['cart'])) {
                $this->errors[] = $this->trans('Sorry. We cannot renew your order.', array(), 'Shop.Notifications.Error');
            } elseif (!$duplication['success']) {
                $this->errors[] = $this->trans(
                    'Some items are no longer available, and we are unable to renew your order.', array(), 'Shop.Notifications.Error'
                );
            } else {
                $this->context->cookie->id_cart = $duplication['cart']->id;
                $context = $this->context;
                $context->cart = $duplication['cart'];
                CartRule::autoAddToCart($context);
                $this->context->cookie->write();
                Tools::redirect('index.php?controller=order');
            }
        }
        
        $this->bootstrap();
    }
}

But print_r($_POST) returns an empty array...

Edited by sdrissi (see edit history)
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...