resultJsonFactory = $resultJsonFactory; $this->sectionIdentifier = $sectionIdentifier; $this->sectionPool = $sectionPool; $this->escaper = $escaper ?: $this->_objectManager->get(\Magento\Framework\Escaper::class); } /** * @inheritdoc */ public function execute() { /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->resultJsonFactory->create(); $resultJson->setHeader('Cache-Control', 'max-age=0, must-revalidate, no-cache, no-store', true); $resultJson->setHeader('Pragma', 'no-cache', true); try { $sectionNames = $this->getRequest()->getParam('sections'); $sectionNames = $sectionNames ? array_unique(\explode(',', $sectionNames)) : null; $forceNewSectionTimestamp = $this->getRequest()->getParam('force_new_section_timestamp'); if ('false' === $forceNewSectionTimestamp) { $forceNewSectionTimestamp = false; } $response = $this->sectionPool->getSectionsData($sectionNames, (bool)$forceNewSectionTimestamp); } catch (\Exception $e) { $resultJson->setStatusHeader( \Zend\Http\Response::STATUS_CODE_400, \Zend\Http\AbstractMessage::VERSION_11, 'Bad Request' ); $response = ['message' => $this->escaper->escapeHtml($e->getMessage())]; } return $resultJson->setData($response); } }