_runModelPath = $runModelPath; $this->_configValueFactory = $configValueFactory; parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); } public function afterSave() { $time = $this->getData('netsuite/cronScheduled/fields/time/value'); $frequency = $this->getData('netsuite/cronScheduled/fields/frequency/value'); $t1 = isset($time[1])?$time[1]:0; $t2 = isset($time[0])?$time[0]:0; $cronExprArray = [ (int)($t1), (int)($t2), $frequency == \Magento\Cron\Model\Config\Source\Frequency::CRON_MONTHLY ? '1' : '*', '*', $frequency == \Magento\Cron\Model\Config\Source\Frequency::CRON_WEEKLY ? '1' : '*', ]; $cronExprString = join(' ', $cronExprArray); try { $this->_configValueFactory->create()->load( self::CRON_STRING_PATH, 'path' )->setValue( $cronExprString )->setPath( self::CRON_STRING_PATH )->save(); $this->_configValueFactory->create()->load( self::CRON_MODEL_PATH, 'path' )->setValue( $this->_runModelPath )->setPath( self::CRON_MODEL_PATH )->save(); } catch (\Exception $e) { //throw new \Exception(__('We can\'t save the cron expression.')); $e->getMessage(); } return parent::afterSave(); } }