Step 1: create a “Registration.php” file inside our extension at the following path.
Path: app\code\Magemonkeys\Removecart
1 2 3 4 5 6 |
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Magemonkeys_Removecart', __DIR__ ); |
Step 2: After that, create a “Module.xml” file inside extension etc folder. app\code\Magemonkeys\Removecart\etc
1 2 3 4 5 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Magemonkeys_Removecart" setup_version="1.0.0" schema_version="1.0.0"> </module> </config> |
Step 3: After that, create “crontab.xml” file inside extension etc folder. app\code\Magemonkeys\Removecart\etc
1 2 3 4 5 6 7 8 |
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd"> <group id="default"> <job name="removecart" instance="Magemonkeys\Removecart\Cron\Removecart" method="getItemData"> <schedule>* * * * *</schedule> </job> </group> </config> |
Step 4: Lastly, Create the “Removecart.php” file inside the Cron folder of extension. app\code\Magemonkeys\Removecart\Cron
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
<?php namespace Magemonkeys\Removecart\Cron; class Removecart { /** * @var \Magento\Quote\Model\QuoteRepository */ protected $quoteRepository; /** * @var \Magento\Quote\Model\ResourceModel\Quote\CollectionFactory */ protected $quoteCollectionFactory; public function __construct( \Magento\Quote\Model\ResourceModel\Quote\CollectionFactory $quoteCollectionFactory, \Magento\Quote\Model\QuoteRepository $quoteRepository ) { $this->quoteCollectionFactory = $quoteCollectionFactory; $this->quoteRepository = $quoteRepository; } public function getItemData() { $fromTime = new \DateTime('now', new \DateTimezone('UTC')); $fromTime->sub(\DateInterval::createFromDateString('30 minutes')); $fromDate = $fromTime->format('Y-m-d H:i:s'); $quoteCollection = $this->quoteCollectionFactory->create(); $quoteCollection ->addFieldToFilter('created_at', ['lteq' => $fromDate]); if($quoteCollection->getSize() >0){ foreach ($quoteCollection as $quote) { $quoteFullObject = $this->quoteRepository->get($quote->getId()); $quoteFullObject->delete(); } } } } |
Run below command in your command prompt
php bin/magento cron:install
php bin/magento cron:run
Every 30 minutes, the cron is executed. If there is an item available in the cart, it will be then removed, automatically!
[crayon-63e0a78ae9ba4273298827/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.