I'm having a trouble with my Magento 2 store. I need to clear all items of users carts programmatically.

If user don't purchase his cart, it'll be cleaned.

Do you have any idea of how can i do that?



Byron, I guess that you need to clear the Abandoned Carts from your system. As per Abandoned Cart concept if A shipping cart is In-active is sudden time, then it becomes called Abandoned Cart.

At Magento, if anything update happens then the update_at of quote table will update at.

So, you need to get a quote collection where updated_at field value 24hrs before. and using cron clear that quote collection.

| improve this answer | |

Try this:

 * @var \Magento\Checkout\Model\Cart
protected $cart;

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

public function execute()
    // Truncate the cart items
| improve this answer | |

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.