1

I found this code below at AddressesPost.php for addresses.phtml. How can addresses.phtml send parameter continue or new_address so AddressesPost.php can getParam('continue') or getParam('new_address')?

AddressesPost.php :

if ($this->getRequest()->getParam('continue', false)) {
   $this->_getCheckout()->setCollectRatesFlag(true);
   $this->_getState()->setActiveStep(State::STEP_SHIPPING);
   $this->_getState()->setCompleteStep(State::STEP_SELECT_ADDRESSES);
   $this->_redirect('*/*/shipping');
} elseif ($this->getRequest()->getParam('new_address')) {
   $this->_redirect('*/checkout_address/newShipping');
} else {
   $this->_redirect('*/*/addresses');
}

I already add <input type="hidden" name="split" value="0" id="split_flag"/> and <input type="hidden" name="update" value="0" id="update_flag"/> in addresses.phtml and the getParam in controller like in code below.

Controller :

elseif ($this->getRequest()->getParam('new_address')) {
    $this->_redirect('*/checkout_address/newShipping');
} elseif ($this->getRequest()->getParam('split')) {
    $btn = $this->getRequest()->getPost('btn');
       if($post = $this->getRequest()->getPost('split')){
            $this->_getCheckout()->setSplitItemInformation($post, $btn);
       } else{
            $this->_redirect('*/*/addresses');
       }
} elseif ($this->getRequest()->getParam('update')) {
    $this->messageManager->addError('test');
    $this->_redirect('*/*/addresses');
} else {
    $this->_redirect('*/*/addresses');
}

It's work for getParam('split'), but it's not work for getParam('update').

5
  • It is default things, the fields access from controller when form is submitted. Nov 22, 2017 at 10:18
  • So, how can i add new parameter so i could getParam('custom') in the controller? Nov 22, 2017 at 10:22
  • You need to specify that field in your form which is submitted in controller. Nov 22, 2017 at 10:27
  • which field did you mean? Nov 22, 2017 at 10:28
  • In your form, you need to pass field with name "custom" so you get that field value in controller. Nov 22, 2017 at 10:37

1 Answer 1

2

You can simply add one more field in the form itself. If you look into the template file below, you can see there is a hidden field called continue.

{magento-root}/vendor/magento/module-multishipping/view/frontend/templates/checkout/addresses.phtml

Similar to this hidden field, you can also include your own custom field let say your_custom_field in this form.

<form id="checkout_multishipping_form" data-mage-init='{"multiShipping":{}, "validation":{}}' action="<?= /* @escapeNotVerified */ $block->getPostActionUrl() ?>" method="post" class="multicheckout address form">
    <div class="title">
        <strong><?= /* @escapeNotVerified */ __('Please select a shipping address for applicable items.') ?></strong>
    </div>
    <input type="hidden" name="continue" value="0" id="can_continue_flag"/>

    .
    .
    .

    <input type="hidden" name="your_custom_field" value="0" id="your_custom_field"/>
</form>
4
  • already tried this, but it's not work. Nov 22, 2017 at 10:36
  • 1
    Can you update your question with your code because just checked with this code $this->getRequest()->getParam('your_custom_field') in controller and it's working..
    – Shyam
    Nov 22, 2017 at 10:45
  • Could you check it again in my update? Nov 23, 2017 at 1:57
  • Now i know the problem, the <input type="hidden" name="your_custom_field" value="0" id="your_custom_field"/> work fine, in my case, it's not work because i add 2 new input, and it's always checked on the first custom input, now i could solve the problem, thank you for the answer!! Nov 23, 2017 at 2:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.