@@ -24,18 +24,26 @@ class Media extends \Magento\Framework\App\Action\Action
24
24
*/
25
25
private $ swatchHelper ;
26
26
27
+ /**
28
+ * @var \Magento\PageCache\Model\Config
29
+ */
30
+ protected $ config ;
31
+
27
32
/**
28
33
* @param Context $context
29
34
* @param \Magento\Catalog\Model\ProductFactory $productModelFactory
30
35
* @param \Magento\Swatches\Helper\Data $swatchHelper
36
+ * @param \Magento\PageCache\Model\Config $config
31
37
*/
32
38
public function __construct (
33
39
Context $ context ,
34
40
\Magento \Catalog \Model \ProductFactory $ productModelFactory ,
35
- \Magento \Swatches \Helper \Data $ swatchHelper
41
+ \Magento \Swatches \Helper \Data $ swatchHelper ,
42
+ \Magento \PageCache \Model \Config $ config
36
43
) {
37
44
$ this ->productModelFactory = $ productModelFactory ;
38
45
$ this ->swatchHelper = $ swatchHelper ;
46
+ $ this ->config = $ config ;
39
47
40
48
parent ::__construct ($ context );
41
49
}
@@ -48,14 +56,22 @@ public function __construct(
48
56
public function execute ()
49
57
{
50
58
$ productMedia = [];
59
+
60
+ /** @var \Magento\Framework\Controller\Result\Json $resultJson */
61
+ $ resultJson = $ this ->resultFactory ->create (ResultFactory::TYPE_JSON );
62
+
63
+ /** @var \Magento\Framework\App\ResponseInterface $response */
64
+ $ response = $ this ->getResponse ();
65
+
51
66
if ($ productId = (int )$ this ->getRequest ()->getParam ('product_id ' )) {
52
67
$ productMedia = $ this ->swatchHelper ->getProductMediaGallery (
53
68
$ this ->productModelFactory ->create ()->load ($ productId )
54
69
);
70
+ $ resultJson ->setHeader ('X-Magento-Tags ' , 'catalog_product_ ' . $ productId );
71
+
72
+ $ response ->setPublicHeaders ($ this ->config ->getTtl ());
55
73
}
56
74
57
- /** @var \Magento\Framework\Controller\Result\Json $resultJson */
58
- $ resultJson = $ this ->resultFactory ->create (ResultFactory::TYPE_JSON );
59
75
$ resultJson ->setData ($ productMedia );
60
76
return $ resultJson ;
61
77
}
0 commit comments