I have created a cron and in that i want to get some values from core_config_data table in my Cron File.
My Cron file is :
<?php
namespace Mageplaza\HelloWorld\Cron;
use Psr\Log\LoggerInterface;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Catalog\Model\ResourceModel\Product\Action;
class Customcron
{
private $productAction;
protected $_logger;
protected $_productCollectionFactory;
private $_objectManager;
public function __construct(
Action $productAction,
\Psr\Log\LoggerInterface $logger,
\Magento\Framework\ObjectManagerInterface $objectmanager
) {
$this->productAction = $productAction;
$this->_logger = $logger;
$this->_objectManager = $objectmanager;
}
public function execute(){
$config = $this->_objectManager->get('Magento\Framework\App\Config\ScopeConfigInterface')->getValue('section/group/field');
$values = (array)json_decode($config, true);
$attributes = [
'status' => 2,
'price' => '10.70'
];
$productIds = ['1'];
$storeId = 0;
$this->productAction->updateAttributes($productIds, $attributes, $storeId);
}
}
My controller index file is :
<?php
namespace Mageplaza\HelloWorld\Controller\Index;
class Index extends \Magento\Framework\App\Action\Action
{
protected $_pageFactory;
private $scopeConfig;
protected $_productCollectionFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\View\Result\PageFactory $pageFactory,
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
array $data = []
){
$this->_pageFactory = $pageFactory;
$this->scopeConfig = $scopeConfig;
return parent::__construct($context, $data);
}
public function execute()
{
$product_ids = [];
$configValue = $this->scopeConfig->getValue('am_shipping/prices/add_item');
$productCollection = $this->_productCollectionFactory->create();
$productCollection->setFlag('has_stock_status_filter', false);
foreach ($productCollection as $key => $value) {
$product_ids[] = $value->getId();
}
print_r($product_ids);
print_r($configValue);die('aaaa');
//return $this->_pageFactory->create();
}
}
It shows me the error Type Error occurred when creating object: Mageplaza\HelloWorld\Controller\Index\Index\Interceptor