Skip to content

"Clear Shopping Cart" in Magento Blank theme no longer working after 2.2.6 #18475

Closed
@perryholden

Description

@perryholden

The "Clear Shopping Cart" button no longer works in the Magento blank theme after the 2.2.6 upgrade.

Preconditions

  1. Magento Open Source and Commerce 2.2.6
  2. PHP 7.1.22
  3. MySQL Ver 14.14 Distrib 5.6.41-84.1
  4. Using the Magento Blank theme (not Luma)
  5. Sample data is installed

Steps to reproduce

  1. Ensure that your site is using the Magento blank theme:
    1. In admin, go to CONTENT > Design > Configuration.
    2. In the grid, select your "Default Store View"
    3. Select "Magento Blank" as your "Applied Theme"
    4. Click "Save Configuration"
  2. From the frontend, add an item to your cart (e.g. Joust Duffle Bag).
  3. Navigate to the cart page.
  4. Click "Clear Shopping Cart".

Expected result

  • The cart is cleared.

Actual result

  • The page refreshes, and the cart is never cleared.

Additional Details

  • Before 2.2.6, vendor/magento/module-checkout/view/frontend/templates/cart/form.phtml had an empty value for data-mage-init on the form element (e.g. data-mage-init='{"validation":{}}').
  • Both the clear cart and the update cart button used the same HTML form, but they used different submit buttons each with a unique "update_cart_action" value.
  • After 2.2.6, this form had additional validation added: data-mage-init='{"Magento_Checkout/js/action/update-shopping-cart":{ ... }'
  • In this new file update-shopping-cart.js, it serializes the data using the serialize method (e.g. this.element.serialize())
  • Unfortunately, the serialize() method doesn't serialize button values (again, which contains the "update_cart_action" value), cause the JS method doesn't know which button was clicked.
  • As a result, the $updateAction variable in the update cart controller method (\Magento\Checkout\Controller\Cart\UpdatePost::execute) will always be null.
  • However, that method will always default to updating the shopping cart, due to the switch call.
  • In the Luma theme, the "Clear Shopping Cart" button was removed. So this functionality continued to work normally while still being technically broken.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Format is validGate 1 Passed. Automatic verification of issue format passed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions