Please, how can i remove all cart's items from controller?

namespace Demo\Demo\Controller\Demo;

class Demo extends \Magento\Framework\App\Action\Action

    public function execute()
      //Codes for removing all cart's items


1 Answer 1


First inject the Magento\Checkout\Model\Cart in your constructor:

protected $cart;

public function __construct(
    \Magento\Checkout\Model\Cart $cart
) {
    $this->cart = $cart;

Then in your execute method you can call:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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