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!
If you want get query string params in controller file,...
Create di.xml and add the below code Magemonkey/Redirect/etc/frontend/di.xml [crayon-62847350103dc251625527/] Create...
You can try below code to change local date to...
Step 1: First you need to add registration.php file in...
Step1 : Override message.js in current theme file on the...