cancel
Showing results for 
Search instead for 
Did you mean: 

I need to get Current quote data from checkout cart model in Custom cron job.

I need to get Current quote data from checkout cart model in Custom cron job.

Hi All,

 

I want to get current quote data for cronjob in cron/run.php. But it's not working.

Please check my code. I am stuck with this. Magento2 version is CE 2.2.6

namespace ABC\Abandon\Cron;

use \Psr\Log\LoggerInterface;
class Run {

protected $logger;
protected $scopeConfig;
public function __construct(
LoggerInterface $logger,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
){
$this->logger = $logger;
$this->scopeConfig = $scopeConfig;

}


public function execute(){

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cartObj = $objectManager->get('\Magento\Checkout\Model\Cart'); 
$quoteId = $cartObj->getQuote()->getId();
$itemsArray = $cartObj->getQuote()->getAllItems();
foreach($itemsArray as $item) {
$productName[] = $item->getName();
}
if(is_array($productName)){
$productNames .= implode(';',$productName);
}
$abdata['productNames'] = $productNames;
$abdata['quoteid'] = $quoteId;
return $abdata;
}

}

 Thanks

6 REPLIES 6

Re: I need to get Current quote data from checkout cart model in Custom cron job.

hello @Shiwani Miglani 

 

your code seems fine .. but in cron file since the area is different you will not get checkout session there . You can achieve your object by using observers as well.

If my answer is useful click kudos and Accept as Solution

Re: I need to get Current quote data from checkout cart model in Custom cron job.

Thanks @shikha1193  for the reply.

 

How I can use observer function in the cron.php file. Do you have any code snippet? 

Or

I am working on a custom cron job the first time.

Can I run the observer file in the cron job? But I have tried already, it's not working at my end.

 

 

 

Re: I need to get Current quote data from checkout cart model in Custom cron job.

@Shiwani Miglanican you tell me for what purpose you are adding cron .. based on that I can suggest how to do that

thanks

Re: I need to get Current quote data from checkout cart model in Custom cron job.

@shikha1193 

 

I just want to get abandon cart details in cron/run.php

Re: I need to get Current quote data from checkout cart model in Custom cron job.

hello @Shiwani Miglani 

 

For getting abandon cart details what you can do you need to create collection of all customers' active quotes which is not being updated since "the time condition you need " in your cron/run.php


If my answer is useful click kudos and Accept as Solution

Re: I need to get Current quote data from checkout cart model in Custom cron job.

Hi @shikha1193 

 

I really appreciate If you can share the running code for this? I have tried all the ways and not able to get solve this.

 

Thanks