Closed
Description
The "Clear Shopping Cart" button no longer works in the Magento blank theme after the 2.2.6 upgrade.
Preconditions
- Magento Open Source and Commerce 2.2.6
- PHP 7.1.22
- MySQL Ver 14.14 Distrib 5.6.41-84.1
- Using the Magento Blank theme (not Luma)
- Sample data is installed
Steps to reproduce
- Ensure that your site is using the Magento blank theme:
- In admin, go to CONTENT > Design > Configuration.
- In the grid, select your "Default Store View"
- Select "Magento Blank" as your "Applied Theme"
- Click "Save Configuration"
- From the frontend, add an item to your cart (e.g. Joust Duffle Bag).
- Navigate to the cart page.
- 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.