How to empty all cart items in magento cart (all PCs around the world)

When I run the script, then empty the trash items from all PCs that have already added the trash item.

+3


source to share


2 answers


try below code.



protected $quoteFactory;

public function __construct(
    ...
    \Magento\Quote\Model\QuoteFactory $quoteFactory,
    ....
) {
    ....
    $this->quoteFactory = $quoteFactory;
    ....
}

$quoteCollection = $this->quoteFactory->create()->getCollection()
          ->addFieldToFilter('is_active', 1);       

foreach ($quoteCollection as $item) {
    $item->delete();    
}

      

0


source


Run the following query:

Remove FROM quote

WHERE is_active = 1 AND reserved_order_id IS NULL



Now run the following command from the Magento Root directory:

Truncate persistent_session

-1


source







All Articles