Magento 2: I need to run observer in crontab.xml. But it is not working

by Shiwani   Last Updated April 15, 2019 10:09 AM

I am running observer in crontab.xml. This is not working.

Here is my code

    <?xml version="1.0"?>
<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="abandon_cron_run" instance="Abc\Abandon\Observer\Abandon" method="execute">
            <schedule>* * * * *</schedule> 
        </job>
    </group>
</config>

Abandon.php

namespace Abc\Abandon\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class Abandon  implements ObserverInterface
{

    protected $scopeConfig;

    public function __construct(

        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig

    )
    {
      $this->scopeConfig = $scopeConfig;
    }

    public function execute(Observer $observer)
    {

            $productName=array();
            $productNames=''; 
             $itemsArray = $observer->getCart()->getQuote()->getItems();
            foreach($itemsArray as $item) {
                $productName[] = $item->getName();
            }
                 if(is_array($productName)){
                    $productNames .= implode(';',$productName);
                } 

                $abdata['productNames'] = $productNames;
            return $abdata; 
    }
}


Related Questions


Updated January 09, 2018 13:09 PM

Updated March 08, 2019 13:09 PM

Updated October 30, 2018 07:09 AM

Updated January 28, 2018 17:09 PM

Updated April 18, 2018 07:09 AM