productModelFactory = $productModelFactory; $this->swatchHelper = $swatchHelper; $this->config = $config; parent::__construct($context); } /** * Get product media for specified configurable product variation * * @return string * @throws \Magento\Framework\Exception\LocalizedException */ public function execute() { $productMedia = []; /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); /** @var \Magento\Framework\App\ResponseInterface $response */ $response = $this->getResponse(); if ($productId = (int)$this->getRequest()->getParam('product_id')) { $product = $this->productModelFactory->create()->load($productId); $productMedia = $this->swatchHelper->getProductMediaGallery( $product ); $resultJson->setHeader('X-Magento-Tags', implode(',', $product->getIdentities())); $response->setPublicHeaders($this->config->getTtl()); } $resultJson->setData($productMedia); return $resultJson; } }