Magento 2.1.7 Mini Cart RemoveItem Not Working – Troubleshooting Guide

magento-2.1.7mini-cart

I have a magento2 live store, that was working properly. But today mini cart remove item functionality stopped working.

When I checked in developer mode, I found that the Request Url /checkout/sidebar/removeItem/ returning 302 found response status.

enter image description here

How to resolve this issue?

Best Answer

Create Vendor/Module/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  <preference for="Magento\Checkout\Controller\Sidebar\RemoveItem" type="Vendor\Module\Controller\Sidebar\RemoveItem" />
</config>

Create Vendor/Module/Controller/Sidebar/RemoveItem.php

<?php
namespace Vendor\Module\Controller\Sidebar;

class RemoveItem extends \Magento\Checkout\Controller\Sidebar\RemoveItem
{

    public function execute()
    {
        $itemId = (int)$this->getRequest()->getParam('item_id');
        try {
            $this->sidebar->checkQuoteItem($itemId);
            $this->sidebar->removeQuoteItem($itemId);
            return $this->jsonResponse();
        } catch (\Magento\Framework\Exception\LocalizedException $e) {
            return $this->jsonResponse($e->getMessage());
        } catch (\Exception $e) {
            $this->logger->critical($e);
            return $this->jsonResponse($e->getMessage());
        }
    }
}
Related Topic