From a43b515f77c8e7e7d4cb4b24ca3e292cfa7ecb5d Mon Sep 17 00:00:00 2001 From: Lucas Calazans Date: Sat, 4 Apr 2020 16:14:04 -0300 Subject: [PATCH 1/4] Sorting galery media by position --- app/code/Magento/Catalog/Model/Product.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index a9907c1661bd8..45c9cfddce69f 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -1530,7 +1530,18 @@ public function getMediaGalleryImages() } if (!$this->getData('media_gallery_images')->count() && is_array($this->getMediaGallery('images'))) { $images = $this->getData('media_gallery_images'); - foreach ($this->getMediaGallery('images') as $image) { + $mediaGallery = $this->getMediaGallery('images'); + usort( + $mediaGallery, + function (array $media, array $compare): int { + $posA = (int)$media['position']; + $posB = (int)$compare['position']; + + return $posA <=> $posB; + } + ); + + foreach ($mediaGallery as $image) { if (!empty($image['disabled']) || !empty($image['removed']) || empty($image['value_id']) From a593a120053463221043d5bb7c947f519d5628d6 Mon Sep 17 00:00:00 2001 From: Lucas Calazans Date: Sat, 4 Apr 2020 19:24:12 -0300 Subject: [PATCH 2/4] Fixing unit tests --- app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php index ce234e17c41aa..bb91f0455a0c4 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php @@ -1283,15 +1283,18 @@ public function testGetMediaGalleryImagesMerging() 'value_id' => 1, 'file' => 'imageFile.jpg', 'media_type' => 'image', + 'position' => 1, ], [ 'value_id' => 3, 'file' => 'imageFile.jpg', + 'position' => 2, ], [ 'value_id' => 2, 'file' => 'smallImageFile.jpg', 'media_type' => 'image', + 'position' => 3, ], ] ]; From 4d5f0de8d6974cd30284590f63129461328fcd52 Mon Sep 17 00:00:00 2001 From: Lucas Calazans Date: Sun, 5 Apr 2020 01:18:41 -0300 Subject: [PATCH 3/4] Fixing static tests --- app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php index bb91f0455a0c4..73d8cd77c8689 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php @@ -16,7 +16,7 @@ use Magento\Store\Model\StoreManagerInterface; /** - * Product Test + * Unit test for Product class * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.TooManyFields) @@ -1003,7 +1003,7 @@ public function testGetIsSalableHasDataIsSaleable() /** * Configure environment for `testSave` and `testSaveAndDuplicate` methods * - * @return array + * @return void */ protected function configureSaveTest() { From 4501b8a1da401a6846b034532c0d24a5e69b1058 Mon Sep 17 00:00:00 2001 From: engcom-Echo Date: Mon, 21 Sep 2020 11:29:12 +0300 Subject: [PATCH 4/4] fix static, unit test --- app/code/Magento/Catalog/Model/Product.php | 8 ++++---- app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index c2d1e20b42d08..b03cc243e92ac 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -1033,7 +1033,7 @@ public function priceReindexCallback() */ public function eavReindexCallback() { - if ($this->isObjectNew() || $this->isDataChanged($this)) { + if ($this->isObjectNew() || $this->isDataChanged()) { $this->_productEavIndexerProcessor->reindexRow($this->getEntityId()); } } @@ -1168,8 +1168,8 @@ public function setTierPrices(array $tierPrices = null) /** * Get product tier price for the customer, based on qty of this product * - * @param float $qty - * @return float|array + * @param float $qty + * @return float|array */ public function getTierPrice($qty = null) { @@ -1179,7 +1179,7 @@ public function getTierPrice($qty = null) /** * Get formatted by currency product price * - * @return array|double + * @return array|float * @since 102.0.6 */ public function getFormattedPrice() diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php index 944316863a81e..ee3269e69af4d 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php @@ -315,10 +315,7 @@ protected function setUp(): void $contextMock = $this->createPartialMock( Context::class, - ['getEventDispatcher', 'getCacheManager', 'getAppState', 'getActionValidator'], - [], - '', - false + ['getEventDispatcher', 'getCacheManager', 'getAppState', 'getActionValidator'] ); $contextMock->expects($this->any())->method('getAppState')->willReturn($this->appStateMock); $contextMock->expects($this->any()) @@ -621,7 +618,7 @@ public function testGetCategoryCollectionCollectionNull($initCategoryCollection, $result = $product->getCategoryCollection(); - $productIdCachedActual = $this->getPropertyValue($product, '_productIdCached', $productIdCached); + $productIdCachedActual = $this->getPropertyValue($product, '_productIdCached'); $this->assertEquals($getIdResult, $productIdCachedActual); $this->assertEquals($initCategoryCollection, $result); } @@ -1362,6 +1359,7 @@ public function testGetMediaGalleryImagesMerging() 'url' => 'http://magento.dev/pub/imageFile.jpg', 'id' => 1, 'path' => '/var/www/html/pub/imageFile.jpg', + 'position' => 1, ] ); $expectedSmallImageDataObject = new DataObject( @@ -1372,6 +1370,7 @@ public function testGetMediaGalleryImagesMerging() 'url' => 'http://magento.dev/pub/smallImageFile.jpg', 'id' => 2, 'path' => '/var/www/html/pub/smallImageFile.jpg', + 'position' => 3, ] );