jsonSerializer = $jsonSerializer; $this->config = $config; $this->createSettingsFromParam = $createSettingsFromParam; } /** * Execute controller. */ public function execute() { /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); $consentDetailJson = $this->getRequest()->getContent(); if (! $consentDetailJson || ! $this->config->isModuleEnabled()) { $resultJson->setHttpResponseCode(404); $response = ['message' => __('Not found.')]; return $resultJson->setData($response); } $consentDetail = $this->jsonSerializer->unserialize($consentDetailJson); $acceptedKeys = $consentDetail['acceptedKeys'] ?: []; $settings = $this->createSettingsFromParam->execute($acceptedKeys); $this->_eventManager->dispatch( 'pr_cookie_consent_update', ['settings' => $settings] ); $response = ['Update processed.']; return $resultJson->setData($response); } }