2

I have been developing my own site for the last couple of years i am still using Magento 1.8. with a 3rd party theme. I noticed whenever i try to update the quantity of a product in my basket, for example type 3 in the box at the first checkout stage and press enter, I receive the page showing my basket is empty and the customer has to start again adding items 1 at a time. Can anybody help please. My site is stickerstocker.co.uk

1
  • I just want to point out, this issue is present in M2.3.x on the Magento Blank and Luma theme. In custom themes, it is safe to remove the Clear Cart button entirely and that way the submission of the form falls back to using the Update Cart Items instead. Not even going to bother making a bug issue on the M2 github because PWA's are a thing. Nov 8, 2019 at 1:58

2 Answers 2

5

As I ran into the same problem and it's already the behavior observed in Magento 2.2.8, I decided to post this answer.
In Magento 2.3.x this issue seems to be fixed.

You can override the form.phtml template used in the cart and there change the order of the submit buttons.

In Magento core it is as follows:

<button type="submit"
        name="update_cart_action"
        data-cart-empty=""
        value="empty_cart"
        title="<?= $block->escapeHtml(__('Clear Shopping Cart')) ?>"
        class="action clear" id="empty_cart_button">
    <span><?= /* @escapeNotVerified */ __('Clear Shopping Cart') ?></span>
</button>
<button type="submit"
        name="update_cart_action"
        data-cart-item-update=""
        value="update_qty"
        title="<?= $block->escapeHtml(__('Update Shopping Cart')) ?>"
        class="action update">
    <span><?= /* @escapeNotVerified */ __('Update Shopping Cart') ?></span>
</button>

So change the order of the buttons to:

<button type="submit"
        name="update_cart_action"
        data-cart-item-update=""
        value="update_qty"
        title="<?= $block->escapeHtml(__('Update Shopping Cart')) ?>"
        class="action update">
    <span><?= /* @escapeNotVerified */ __('Update Shopping Cart') ?></span>
</button>
<button type="submit"
        name="update_cart_action"
        data-cart-empty=""
        value="empty_cart"
        title="<?= $block->escapeHtml(__('Clear Shopping Cart')) ?>"
        class="action clear" id="empty_cart_button">
    <span><?= /* @escapeNotVerified */ __('Clear Shopping Cart') ?></span>
</button>

According to the HTML 5 specs the first submit button appearing inside the form is considered as the default button, when submitting the form via hitting the enter key while being inside a qty input.

A form element’s default button is the first Submit Button in tree order whose form owner is that form element.

If the user agent supports letting the user submit a form implicitly (for example, on some platforms hitting the "enter" key while a text field is focused implicitly submits the form), then doing so for a form whose default button has a defined activation behavior must cause the user agent to run synthetic click activation steps on that default button.

See: https://www.w3.org/TR/html5/forms.html#implicit-submission

1

Your 'CLEAR SHOPPING CART' button acts like the submit button for the form. The same thing applies to your 'UPDATE CART' button. When you press the enter key after changing the quantity value you submit the form and this triggers the wrong submit action.

<button type="submit" name="update_cart_action" value="empty_cart" title="Clear Shopping Cart" class="button-2x dark" id="empty_cart_button"><span><span>Clear Shopping Cart</span></span></button>

<button type="submit" name="update_cart_action" value="update_qty" class="button-2x dark">UPDATE CART</button>

1
  • Thanks for the response and indicating the issue. Can you explain how to correct it please. Am i replacing the code quoted at the top with the code below you have typed?
    – Mattee
    Oct 5, 2016 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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