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

Magento2 version is CE 2.2.6. Here is my code

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();
        $productNames .= implode(';',$productName);
        $abdata['productNames'] = $productNames;
        $abdata['quoteid'] = $quoteId;
        return $abdata;

I am not able to get cart session data inside the cron run.php file.

any suggestion? Thanks

  • I think code working fine. Please check your cron – Arunprabakaran M Apr 8 '19 at 9:38
  • @ARUNPRABAKARANM cron is working fine. Only the problem is with the cart session. I am not able to GET cart data in cron run.php file. – Pankaj Sharma Apr 8 '19 at 9:44
  • Kindly check my code – Arunprabakaran M Apr 8 '19 at 10:16
  • You can not get the current quote from cron, you will need to load quote by customer id. – Ashish Viradiya Apr 8 '19 at 11:11
  • @AshishViradiya do you have any reference for this? – Pankaj Sharma Apr 8 '19 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.