I have a cron job in magento 2, since I have added dependencies it has stopped running. I am getting the error
Fatal error: Uncaught Error: Cannot access parent:: when current class scope has no parent
and this is when I add this to the constructor :
parent::__construct($context,$data);
If I remove this line then the cron fails because it can't see the dependencies. This is my cron, I want to log the customer ids for that store:
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
use Magento\Framework\Registry;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Catalog\Model\ProductRepository;
use Magento\Customer\Api\CustomerRepositoryInterface;
class reinitpricing {
private $resultJsonFactory;
protected $resourceConnection;
protected $authSession;
private $productCollectionFactory;
protected $helperData;
protected $coreRegistry;
private $currentStore;
private $storeManager;
private $storeId;
protected $productRepository;
protected $_productAttributeRepository;
private $storeResolver;
protected $_customer;
protected $_customerFactory;
public function __construct(\Magento\Framework\App\Action\Context $context,
JsonFactory $resultJsonFactory,
\Magento\Framework\App\ResourceConnection $resourceConnection,
\Magento\Backend\Model\Auth\Session $authSession, ProductCollectionFactory $productCollectionFactory,
\FlavourWarehouse\Pricing\Helper\Data $helperData,
Registry $coreRegistry,
\Magento\Catalog\Model\Product\Attribute\Repository $productAttributeRepository,
ProductRepository $productRepository,
\Magento\Store\Model\StoreResolver $storeResolver,
\Magento\Framework\App\RequestInterface $request,
CustomerRepositoryInterface $customerRepository,
\Magento\Customer\Model\Customer $customer,
\Magento\Customer\Model\CustomerFactory $customerFactory,
array $data = [])
{
parent::__construct($context,$data);
$this->resultJsonFactory = $resultJsonFactory;
$this->resourceConnection = $resourceConnection;
$this->authSession = $authSession;
$this->productCollectionFactory = $productCollectionFactory;
$this->helperData = $helperData;
$this->storeManager = $storeManager;
$this->currentStore = 1;
$this->storeId = 1;
$this->coreRegistry = $coreRegistry;
$this->productRepository = $productRepository;
$this->_productAttributeRepository = $productAttributeRepository;
$this->storeResolver = $storeResolver;
$this->_request = $request;
$this->customerRepository = $customerRepository;
$this->_customer = $customer;
$this->_customerFactory = $customerFactory;
}
public function execute() {
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/logger.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info("the cron job is running");
$collection = $this->_customerFactory->create()->getCollection()
->addAttributeToSelect("*")
->addStoreFilter(1)
->load();
foreach ($collection AS $customer) {
$logger->info($customer->getId());
}
}