I am using the Magento2.2 version . I am using the class Magento\Sales\Model\ResourceModel\Order\CollectionFactory; to get the order collection.But getting the error
Fatal error: Uncaught Error: Call to a member function create() on null.
when I try to call create() function. Why I getting the error.please give a solution...
My code is:
<?php
namespace {VendorName}\{moduleName}\Cron;
use Magento\Sales\Api\Data\OrderAddressInterface;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
class {class name}
{
protected $orderAddress;
protected $orderCollectionFactory;
/**
* @param OrderAddressInterface $orderAddressInterface
* @param CollectionFactoryInterface $collectionFactoryInterface
*/
public function __contruct(
OrderAddressInterface $orderAddressInterface,
CollectionFactory $collectionFactoryInterface
)
{
$this->orderCollectionFactory = $collectionFactoryInterface;
$this->orderAddress = $orderAddressInterface;
}
public function execute()
{
$dateNow = (new \DateTime())->format('Y-m-d H:i:s');
echo $days_ago = date('Y-m-d H:i:s', strtotime('-180 days', strtotime($dateNow)));
$orderCollection = $this->orderCollectionFactory->create()
->addFieldToFilter('updated_at', ['lteq' => $days_ago]);
echo $orderCollection->getSelect()->__toString();
return $orderCollection;
}
}
di:compile
– Keyur Shah Feb 4 '18 at 18:50