10

After upgrading to Magento CE 1.9.3.3, when I enable Form Key Validation on Checkout as recommended by SUPEE-9767 onestep checkout stops working.

After selecting a payment method, when I click Continue Payment the one step process does not continue. I do not see any server response or logged error messages.

When I disable Form Key Validation on Checkout, the checkout process functions as expected.

This is a default Magento installation with no extended theme.

Update1

This seems to be associated with SUPEE-9767 Patch/CE 1.9.3.3 - One Page Checkout - Customer Registration issue where the ajax savepayment method call is returning null even though template files are patched and formkeys are present,

I could not replicate this on a clean 1933 install.

Update2

Here is the cause of my problem

<input name="form_key" type="hidden" value="SLLU234jmligBYb9" disabled="" autocomplete="off">

CSS is adding the disabled selector to the form_key. This means the form_key value is not submitted to the one step checkout controller causing the controller to return null. To test this, remove the disabled selector in your browser inspector.

This problem was caused by Paypal Plus which dynamically replaces the contents of fieldset at the onestep checkout payment method. See my answer below.

  • i got same issue maybe it's done by javascript,It is disable form_key input type so form_key is not able to submit.I am also looking for solution – Vaibhav Ahalpara Jun 6 '17 at 11:26
  • @7ochem how to remove the disabled selector.Help me – Nadh Jun 7 '17 at 14:09
14

My problem was caused by dynamic code (paypal plus) in the one page checkout process overwriting the fieldset element in the one step method form html - deleting or disabling (with css) the hidden form_key element.

The fix is to ensure the formkey element is not being affected by dynamic code or css. Moving the formkey code outside of the fieldset may help

<form action="" id="co-payment-form">
    <?php echo $this->getBlockHtml('formkey') ?>
    <fieldset>
        <?php echo $this->getChildHtml('methods') ?>
    </fieldset>
</form>

You can easily confirm if the form_key is being detected and sent to the one page controller by inspecting the ajax network requests in your browser as you move through the checkout methods, each method should include the form key in the ajax form data, if the form key is not there but had been patched in the Magento source code then check for external code affecting the form key element, i.e. css or dynamic client side changes.

enter image description here

  • 4
    had an issue where the extension file /js/amasty/amorderattr/payment.js was setting elements[i].disabled = true; want to make sure that this is in the for loop on the elements if (elements[i].name=='payment[method]' || elements[i].name=='form_key') { modified the loop from /js/varien/payment.js – asherrard Jun 2 '17 at 17:39
  • @paj thank you! I've lost hours trying to fix this "boarding effect". – DarkCowboy Jun 6 '17 at 14:42
  • I have also same issue. I have applied Patch - 9767 V2 successfully. It is working properly with the default theme. But i am using my custom theme so have added form key in all the custom theme files according to files which was patched. My other steps are working except "Payment" step. Similar to your issue have also disabled in the form key field of Payment step. My form key fee is already outside of <fieldset> but still it's not working. Can you please say what will be other issue there. – Magecode Aug 31 '17 at 5:07
  • Hi there. Somehow the bug is back again. I rolled-back SUPEE-9767v1 then applied v2. Doesn't change anything. @Magecode : did you found the cause from your side? – DarkCowboy Dec 19 '17 at 13:13
  • I had that the issue that after upgrade to 1.9 the opcheckout.js file was being cached heavily by the browser. I forced an update of the file for all browsers by appending ?19 to app/design/frontend/base/default/template/checkout/onepage.phtml to the load call of opcheckout.js. – Paul van Schayck Nov 18 '18 at 11:33
3

https://gist.github.com/schmengler/c42acc607901a887ef86b4daa7a0445b

apply this patch after 9767 as you applied security patch and this patch add form keys in all required PHTML file

  • Yes, I have done that, but as there are no extended themes to patch it didn't make any difference. – paj Jun 1 '17 at 13:11
1

In my case I had applied SUPE-9767 but our custom checkout was missing the formkey code as above, i.e. <?php echo $this->getBlockHtml('formkey') ?>. I was still getting the error when I hit the checkout, but then I cleared the compiled classes:

server:~$ cd /path/to/magento/public/shell
server:/path/to/magento/public/shell$ php compiler.php disable
server:/path/to/magento/public/shell$ php compiler.php clear
server:/path/to/magento/public/shell$ php compiler.php compile
server:/path/to/magento/public/shell$ php compiler.php enable

And also cleared the cache for good measure:

server:/path/to/magento/public/shell$ cd ..
server:/path/to/magento/public/$ rm -r var/cache/*

Problem solved.

  • 1
    Specifically I was getting the following in /var/log/apache2/error.log - PHP Fatal error: Call to undefined method Mage_Checkout_OnepageController::isFormkeyValidationOnCheckoutEnabled() in .... – GuruBob Jun 6 '17 at 21:50
  • hey GuruBob, I've got the same. Did you figure out the problem? – Detzler Jun 22 '17 at 9:01
  • Yes, my problem was solved by disabling, clearing, compiling and enabling the compiler cache as above. Happy to help more if you need it, get me on gurubob@gmail.com. – GuruBob Jul 5 '17 at 9:44
0

Add in all of your custom checkout templates in forms next line

<?php echo $this->getBlockHtml('formkey') ?>
0

If you're using EE, you might need to check if your custom theme has also overridden the following file:

app/design/frontend/rwd/enterprise/template/giftcardaccount/onepage/payment/scripts.phtml

var quoteBaseGrandTotal = <?php echo (float)$this->_getQuote()->getBaseGrandTotal(); ?>;
var isGiftCardApplied = <?php if($this->isFullyPaidAfterApplication()): ?>true<?php else: ?>false<?php endif; ?>;
var epsilon = 0.0001;
function enablePaymentMethods(free) {
    Payment.prototype.init = function () {
        var elements = Form.getElements(this.form);
        var methodName = '';
        for (var i=0; i < elements.length; i++) {
            if (elements[i].name == 'payment[method]'
                || elements[i].name == 'payment[use_customer_balance]'
                || elements[i].name == 'payment[use_reward_points]'


// Make sure the next line exists in your theme
                || elements[i].name == 'form_key'


            ) {
                methodName = elements[i].value;
0

Having the same issue, but I had to edit the core files to fix it!

I'm getting this error:

[02-Jun-2017 14:25:32 UTC] PHP Fatal error:  Call to undefined method Mage_Checkout_OnepageController::isFormkeyValidationOnCheckoutEnabled() in /chroot/he/Checkout/controllers/OnepageController.php on line 353
[02-Jun-2017 14:37:07 UTC] PHP Fatal error:  Call to undefined method Mage_Checkout_OnepageController::isFormkeyValidationOnCheckoutEnabled() in /chroot/he/Checkout/controllers/OnepageController.php on line 353
[02-Jun-2017 14:41:48 UTC] PHP Fatal error:  Call to undefined method Mage_Checkout_OnepageController::isFormkeyValidationOnCheckoutEnabled() in /chroot/he/Checkout/controllers/OnepageController.php on line 353
[02-Jun-2017 14:43:09 UTC] PHP Fatal error:  Call to undefined method Mage_Checkout_OnepageController::isFormkeyValidationOnCheckoutEnabled() in /chroot/he/Checkout/controllers/OnepageController.php on line 353
[02-Jun-2017 14:52:19 UTC] PHP Fatal error:  Call to undefined method Mage_Checkout_OnepageController::isFormkeyValidationOnCheckoutEnabled() in /chroot/he/Checkout/controllers/OnepageController.php on line 353
[02-Jun-2017 15:00:40 UTC] PHP Fatal error:  Call to undefined method Mage_Checkout_OnepageController::isFormkeyValidationOnCheckoutEnabled() in /chroot/he/Checkout/controllers/OnepageController.php on line 353
[02-Jun-2017 15:03:54 UTC] PHP Fatal error:  Call to undefined method Mage_Checkout_OnepageController::isFormkeyValidationOnCheckoutEnabled() in /chroot/he/Checkout/controllers/OnepageController.php on line 353
[02-Jun-2017 15:06:50 UTC] PHP Fatal error:  Call to undefined method Mage_Checkout_OnepageController::isFormkeyValidationOnCheckoutEnabled() in /chroot/he/Checkout/controllers/OnepageController.php on line 353
[02-Jun-2017 15:09:45 UTC] PHP Fatal error:  Call to undefined method Mage_Checkout_OnepageController::isFormkeyValidationOnCheckoutEnabled() in /chroot/he/Checkout/controllers/OnepageController.php on line 353
[02-Jun-2017 15:12:50 UTC] PHP Fatal error:  Call to undefined method Mage_Checkout_OnepageController::isFormkeyValidationOnCheckoutEnabled() in /chroot/he/Checkout/controllers/OnepageController.php on line 353

So i edited out the function $this-> isFormkeyValidationOnCheckoutEnabled() in this file:

\app\code\core\Mage\Checkout\controllers\OnepageController.php

and Now my checkout process works again!

  • 1
    Its good to get your shop working again, but what you have done is just a temporary workaround. I would try and find out why that controller method is undefined. – paj Jun 2 '17 at 18:33
  • 1
    Indeed editing the function in the onepagecontroller.php file "solves" the issue but is a bad practice if you ask me. Did you find a more sustainable solution? – Badger Jul 10 '17 at 11:44
  • At least you should have apply this workaround through an override by copying/editing into \app\code\local\Mage\Checkout\controllers\OnepageController.php – DarkCowboy Dec 19 '17 at 13:17
0

Checkout Stuck on Step 4 after SUPEE-9767 with Formkey Validation on Checkout Enabled Obviously you are using a custom theme then. Simple as it is, you will have to add the Line there too. It is easy as follows: Open your custom themes payment.phtml and add the line in your Formular with ID "co-payment-form":

<?php echo $this->getBlockHtml('formkey') ?>

As example I did it right after the initial php-tag so its on top of the template.

Additionally: If your custom theme overwrites the opcheckout.js, there is some needed editing too: Find

if (elements[i].name=='payment[method]') {

and replace it with

if (elements[i].name=='payment[method]' || elements[i].name == 'form_key') {

All credits to community.magento.com

-4

You have to use form key in your formkey to make it working.

getBlockHtml('formkey') ?>
  • At least you could copy/paste it completely: <?php echo $this->getBlockHtml('formkey') ?> – DarkCowboy Jun 6 '17 at 14:46

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