namespace Cron\Test\Cron; class Example { protected $ customerSession; /** * Construct * * @param \Magento\Framework\View\Element\Template\Context $ context * @param \Magento\Customer\Model\Session $ customerSession * @param array $ data */ public function __construct( \Magento\Framework\View\Element\Template\Context $ context, \Magento\Customer\Model\Session $ customerSession, array $ data = [] ) { parent::__construct($ context, $ data); $ this->customerSession = $ customerSession; } public function customer() { return $ this->customerSession->getCustomer()->getId(); } public function execute() { $ suser_id= $ this>customer(); $ this->_resources = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Framework\App\ResourceConnection'); $ connection= $ this->_resources->getConnection(); $ sql = "UPDATE `total_cashback` SET is_active= 150 WHERE user_id = '$ suser_id' "; //$ sql = "UPDATE `wallet_discounts` SET is_active = 1 WHERE customer_id = '$ customerId' "; $ connection->query($ sql); }