From 49bc150fc4e6886cd84e92cc047dce2653ad2b36 Mon Sep 17 00:00:00 2001 From: slopukhov Date: Mon, 8 Oct 2018 11:24:19 +0300 Subject: [PATCH 1/8] MAGETWO-91388: Enable caching of AJAX requests on Varnish/Fastly --- .../Swatches/Controller/Ajax/Media.php | 22 ++++++++++++++++--- .../view/frontend/web/js/swatch-renderer.js | 14 +++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Swatches/Controller/Ajax/Media.php b/app/code/Magento/Swatches/Controller/Ajax/Media.php index 079ba8f897127..2616213336f98 100644 --- a/app/code/Magento/Swatches/Controller/Ajax/Media.php +++ b/app/code/Magento/Swatches/Controller/Ajax/Media.php @@ -24,18 +24,26 @@ class Media extends \Magento\Framework\App\Action\Action */ private $swatchHelper; + /** + * @var \Magento\PageCache\Model\Config + */ + protected $config; + /** * @param Context $context * @param \Magento\Catalog\Model\ProductFactory $productModelFactory * @param \Magento\Swatches\Helper\Data $swatchHelper + * @param \Magento\PageCache\Model\Config $config */ public function __construct( Context $context, \Magento\Catalog\Model\ProductFactory $productModelFactory, - \Magento\Swatches\Helper\Data $swatchHelper + \Magento\Swatches\Helper\Data $swatchHelper, + \Magento\PageCache\Model\Config $config ) { $this->productModelFactory = $productModelFactory; $this->swatchHelper = $swatchHelper; + $this->config = $config; parent::__construct($context); } @@ -48,14 +56,22 @@ public function __construct( 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')) { $productMedia = $this->swatchHelper->getProductMediaGallery( $this->productModelFactory->create()->load($productId) ); + $resultJson->setHeader('X-Magento-Tags', 'catalog_product_' . $productId); + + $response->setPublicHeaders($this->config->getTtl()); } - /** @var \Magento\Framework\Controller\Result\Json $resultJson */ - $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); $resultJson->setData($productMedia); return $resultJson; } diff --git a/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js b/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js index 853eba3c98df2..63dbd31751e85 100644 --- a/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js +++ b/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js @@ -1029,12 +1029,14 @@ define([ mediaCallData.isAjax = true; $widget._XhrKiller(); $widget._EnableProductMediaLoader($this); - $widget.xhr = $.get( - $widget.options.mediaCallback, - mediaCallData, - mediaSuccessCallback, - 'json' - ).done(function () { + $widget.xhr = $.ajax({ + url: $widget.options.mediaCallback, + cache: true, + type: 'GET', + dataType: 'json', + data: mediaCallData, + success: mediaSuccessCallback + }).done(function () { $widget._XhrKiller(); }); } From 406c6dceb0331ac25e7f090090d5f2bc2faced1f Mon Sep 17 00:00:00 2001 From: slopukhov Date: Tue, 9 Oct 2018 07:49:30 +0300 Subject: [PATCH 2/8] MAGETWO-91388: Enable caching of AJAX requests on Varnish/Fastly --- app/code/Magento/Swatches/Controller/Ajax/Media.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Swatches/Controller/Ajax/Media.php b/app/code/Magento/Swatches/Controller/Ajax/Media.php index 2616213336f98..5847846f4d5f0 100644 --- a/app/code/Magento/Swatches/Controller/Ajax/Media.php +++ b/app/code/Magento/Swatches/Controller/Ajax/Media.php @@ -64,10 +64,11 @@ public function execute() $response = $this->getResponse(); if ($productId = (int)$this->getRequest()->getParam('product_id')) { + $product = $this->productModelFactory->create()->load($productId); $productMedia = $this->swatchHelper->getProductMediaGallery( - $this->productModelFactory->create()->load($productId) + $product ); - $resultJson->setHeader('X-Magento-Tags', 'catalog_product_' . $productId); + $resultJson->setHeader('X-Magento-Tags', implode(',', $product->getIdentities())); $response->setPublicHeaders($this->config->getTtl()); } From 66807400903ad21d6269b6c1db9a8fab62617267 Mon Sep 17 00:00:00 2001 From: slopukhov Date: Wed, 10 Oct 2018 14:08:04 +0300 Subject: [PATCH 3/8] MAGETWO-91388: Enable caching of AJAX requests on Varnish/Fastly --- .../Swatches/Controller/Ajax/Media.php | 2 +- .../Test/Unit/Controller/Ajax/MediaTest.php | 22 ++++++++++++++++++- app/code/Magento/Swatches/composer.json | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Swatches/Controller/Ajax/Media.php b/app/code/Magento/Swatches/Controller/Ajax/Media.php index 5847846f4d5f0..7692245e9b27a 100644 --- a/app/code/Magento/Swatches/Controller/Ajax/Media.php +++ b/app/code/Magento/Swatches/Controller/Ajax/Media.php @@ -12,7 +12,7 @@ /** * Class Media */ -class Media extends \Magento\Framework\App\Action\Action +class Media extends \Magento\Framework\App\Action\Action implements \Magento\Framework\App\Action\HttpGetActionInterface { /** * @var \Magento\Catalog\Model\Product Factory diff --git a/app/code/Magento/Swatches/Test/Unit/Controller/Ajax/MediaTest.php b/app/code/Magento/Swatches/Test/Unit/Controller/Ajax/MediaTest.php index 7a110c63da79e..5a11e2787bc69 100644 --- a/app/code/Magento/Swatches/Test/Unit/Controller/Ajax/MediaTest.php +++ b/app/code/Magento/Swatches/Test/Unit/Controller/Ajax/MediaTest.php @@ -20,6 +20,9 @@ class MediaTest extends \PHPUnit\Framework\TestCase /** @var \Magento\Catalog\Model\ProductFactory|\PHPUnit_Framework_MockObject_MockObject */ private $productModelFactoryMock; + /** @var \Magento\PageCache\Model\Config|\PHPUnit_Framework_MockObject_MockObject */ + private $config; + /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject */ private $productMock; @@ -29,6 +32,9 @@ class MediaTest extends \PHPUnit\Framework\TestCase /** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */ private $requestMock; + /** @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject */ + private $responseMock; + /** @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject */ private $resultFactory; @@ -57,11 +63,20 @@ protected function setUp() \Magento\Catalog\Model\ProductFactory::class, ['create'] ); + $this->config = $this->createMock(\Magento\PageCache\Model\Config::class); + $this->config->method('getTtl')->willReturn(1); + $this->productMock = $this->createMock(\Magento\Catalog\Model\Product::class); $this->contextMock = $this->createMock(\Magento\Framework\App\Action\Context::class); $this->requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class); $this->contextMock->method('getRequest')->willReturn($this->requestMock); + $this->responseMock = $this->getMockBuilder(\Magento\Framework\App\ResponseInterface::class) + ->disableOriginalConstructor() + ->setMethods(['setPublicHeaders']) + ->getMockForAbstractClass(); + $this->responseMock->method('setPublicHeaders')->willReturnSelf(); + $this->contextMock->method('getResponse')->willReturn($this->responseMock); $this->resultFactory = $this->createPartialMock(\Magento\Framework\Controller\ResultFactory::class, ['create']); $this->contextMock->method('getResultFactory')->willReturn($this->resultFactory); @@ -73,7 +88,8 @@ protected function setUp() [ 'context' => $this->contextMock, 'swatchHelper' => $this->swatchHelperMock, - 'productModelFactory' => $this->productModelFactoryMock + 'productModelFactory' => $this->productModelFactoryMock, + 'config' => $this->config ] ); } @@ -86,6 +102,10 @@ public function testExecute() ->method('load') ->with(59) ->willReturn($this->productMock); + $this->productMock + ->expects($this->once()) + ->method('getIdentities') + ->willReturn(['tags']); $this->productModelFactoryMock ->expects($this->once()) diff --git a/app/code/Magento/Swatches/composer.json b/app/code/Magento/Swatches/composer.json index 0940003b6a72d..09d3e05008afe 100644 --- a/app/code/Magento/Swatches/composer.json +++ b/app/code/Magento/Swatches/composer.json @@ -13,6 +13,7 @@ "magento/module-configurable-product": "*", "magento/module-customer": "*", "magento/module-eav": "*", + "magento/module-page-cache": "*", "magento/module-media-storage": "*", "magento/module-store": "*", "magento/module-theme": "*" From 65cfb295e3ec4963c03b6c5bdcff39d5fa4c6501 Mon Sep 17 00:00:00 2001 From: Vitalii Zabaznov Date: Tue, 2 Oct 2018 18:25:45 +0300 Subject: [PATCH 4/8] MAGETWO-94671: Product Export fails --- .../Magento/CatalogImportExport/Model/Export/Product.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/CatalogImportExport/Model/Export/Product.php b/app/code/Magento/CatalogImportExport/Model/Export/Product.php index 23aa8d65ddb0d..41e74837f4cf3 100644 --- a/app/code/Magento/CatalogImportExport/Model/Export/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Export/Product.php @@ -520,10 +520,13 @@ protected function getMediaGallery(array $productIds) if (empty($productIds)) { return []; } + + $productEntityJoinField = $this->getProductEntityLinkField(); + $select = $this->_connection->select()->from( ['mgvte' => $this->_resourceModel->getTableName('catalog_product_entity_media_gallery_value_to_entity')], [ - "mgvte.{$this->getProductEntityLinkField()}", + "mgvte.$productEntityJoinField", 'mgvte.value_id' ] )->joinLeft( @@ -535,7 +538,7 @@ protected function getMediaGallery(array $productIds) ] )->joinLeft( ['mgv' => $this->_resourceModel->getTableName('catalog_product_entity_media_gallery_value')], - '(mg.value_id = mgv.value_id)', + "(mg.value_id = mgv.value_id) and (mgvte.$productEntityJoinField = mgv.$productEntityJoinField)", [ 'mgv.label', 'mgv.position', From 1766f07493612123a4b5bddbc3652d55c168cb95 Mon Sep 17 00:00:00 2001 From: Vitalii Zabaznov Date: Tue, 2 Oct 2018 18:40:42 +0300 Subject: [PATCH 5/8] MAGETWO-94671: Product Export fails --- app/code/Magento/CatalogImportExport/Model/Export/Product.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/CatalogImportExport/Model/Export/Product.php b/app/code/Magento/CatalogImportExport/Model/Export/Product.php index 41e74837f4cf3..b2c3aeb096b95 100644 --- a/app/code/Magento/CatalogImportExport/Model/Export/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Export/Product.php @@ -546,14 +546,14 @@ protected function getMediaGallery(array $productIds) 'mgv.store_id', ] )->where( - "mgvte.{$this->getProductEntityLinkField()} IN (?)", + "mgvte.$productEntityJoinField IN (?)", $productIds ); $rowMediaGallery = []; $stmt = $this->_connection->query($select); while ($mediaRow = $stmt->fetch()) { - $rowMediaGallery[$mediaRow[$this->getProductEntityLinkField()]][] = [ + $rowMediaGallery[$mediaRow[$productEntityJoinField]][] = [ '_media_attribute_id' => $mediaRow['attribute_id'], '_media_image' => $mediaRow['filename'], '_media_label' => $mediaRow['label'], From 5681284c06c78798e51b7c4bae1820e9f80e1828 Mon Sep 17 00:00:00 2001 From: Vitalii Zabaznov Date: Thu, 11 Oct 2018 11:16:04 +0300 Subject: [PATCH 6/8] MAGETWO-94671: Product Export fails --- .../Model/Export/Product.php | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/CatalogImportExport/Model/Export/Product.php b/app/code/Magento/CatalogImportExport/Model/Export/Product.php index b2c3aeb096b95..f90eba0bba281 100644 --- a/app/code/Magento/CatalogImportExport/Model/Export/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Export/Product.php @@ -349,12 +349,13 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity private $productEntityLinkField; /** + * Product constructor. * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate * @param \Magento\Eav\Model\Config $config * @param \Magento\Framework\App\ResourceConnection $resource * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Psr\Log\LoggerInterface $logger - * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection + * @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory * @param \Magento\ImportExport\Model\Export\ConfigInterface $exportConfig * @param \Magento\Catalog\Model\ResourceModel\ProductFactory $productFactory * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $attrSetColFactory @@ -363,10 +364,10 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity * @param \Magento\Catalog\Model\ResourceModel\Product\Option\CollectionFactory $optionColFactory * @param \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeColFactory * @param Product\Type\Factory $_typeFactory - * @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider - * @param \Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer + * @param ProductEntity\LinkTypeProvider $linkTypeProvider + * @param RowCustomizerInterface $rowCustomizer * @param array $dateAttrCodes - * @SuppressWarnings(PHPMD.ExcessiveParameterList) + * @throws \Magento\Framework\Exception\LocalizedException */ public function __construct( \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, @@ -695,7 +696,9 @@ protected function updateDataWithCategoryColumns(&$dataRow, &$rowCategories, $pr } /** - * {@inheritdoc} + * Get header columns + * + * @return string[] */ public function _getHeaderColumns() { @@ -754,7 +757,10 @@ protected function _getExportMainAttrCodes() } /** - * {@inheritdoc} + * Get entity collection + * + * @param bool $resetCollection + * @return \Magento\Framework\Data\Collection\AbstractDb */ protected function _getEntityCollection($resetCollection = false) { @@ -861,7 +867,10 @@ public function export() } /** - * {@inheritdoc} + * Apply filter to collection and add not skipped attributes to select. + * + * @param \Magento\Eav\Model\Entity\Collection\AbstractCollection $collection + * @return \Magento\Eav\Model\Entity\Collection\AbstractCollection * @since 100.2.0 */ protected function _prepareEntityCollection(\Magento\Eav\Model\Entity\Collection\AbstractCollection $collection) @@ -923,8 +932,7 @@ protected function getExportData() } /** - * Load products' data from the collection - * and filter it (if needed). + * Load products' data from the collection and filter it (if needed). * * @return array Keys are product IDs, values arrays with keys as store IDs * and values as store-specific versions of Product entity. @@ -1066,6 +1074,8 @@ private function wrapValue($value) } /** + * Collect multi raw data from + * * @return array */ protected function collectMultirawData() @@ -1107,6 +1117,8 @@ protected function collectMultirawData() } /** + * Check the current data has multiselect value + * * @param \Magento\Catalog\Model\Product $item * @param int $storeId * @return bool @@ -1119,6 +1131,8 @@ protected function hasMultiselectData($item, $storeId) } /** + * Collect multiselect values based on value + * * @param \Magento\Catalog\Model\Product $item * @param string $attrCode * @param int $storeId @@ -1143,6 +1157,8 @@ protected function collectMultiselectValues($item, $attrCode, $storeId) } /** + * Check attribute is valid + * * @param string $code * @param mixed $value * @return bool @@ -1162,6 +1178,8 @@ protected function isValidAttributeValue($code, $value) } /** + * Append multi row data + * * @param array $dataRow * @param array $multiRawData * @return array @@ -1291,6 +1309,8 @@ private function appendMultirowData(&$dataRow, $multiRawData) } /** + * Add multi row data to export + * * @deprecated 100.1.0 * @param array $dataRow * @param array $multiRawData @@ -1338,6 +1358,8 @@ protected function _customHeadersMapping($rowData) } /** + * Convert option row to cell string + * * @param array $option * @return string */ From defec8bb1c1a053ab3af79dfdb1e0fa91387b9ac Mon Sep 17 00:00:00 2001 From: Vitalii Zabaznov Date: Thu, 11 Oct 2018 15:53:23 +0300 Subject: [PATCH 7/8] MAGETWO-94671: Product Export fails --- app/code/Magento/CatalogImportExport/Model/Export/Product.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/CatalogImportExport/Model/Export/Product.php b/app/code/Magento/CatalogImportExport/Model/Export/Product.php index f90eba0bba281..096d8495d70cd 100644 --- a/app/code/Magento/CatalogImportExport/Model/Export/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Export/Product.php @@ -20,6 +20,7 @@ * @SuppressWarnings(PHPMD.TooManyFields) * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.ExcessiveParameterList) * @since 100.0.2 */ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity From a09220431c5ca8974bcca53231a38a3a95d5bb62 Mon Sep 17 00:00:00 2001 From: Vitaliy Honcharenko Date: Tue, 2 Oct 2018 16:08:46 +0300 Subject: [PATCH 8/8] MAGETWO-95412: [2.3] Add missed dependencies for catalogsearch_fulltext indexer --- app/code/Magento/Elasticsearch/etc/indexer.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Elasticsearch/etc/indexer.xml b/app/code/Magento/Elasticsearch/etc/indexer.xml index 8d75a59f84048..f22eb8f0bd39b 100644 --- a/app/code/Magento/Elasticsearch/etc/indexer.xml +++ b/app/code/Magento/Elasticsearch/etc/indexer.xml @@ -8,6 +8,7 @@ +