diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index 7c463267e5a58..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() @@ -1547,7 +1547,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']) diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php index 48a081aaeda54..ee3269e69af4d 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php @@ -69,6 +69,8 @@ use PHPUnit\Framework\TestCase; /** + * Unit test for Product class + * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.TooManyFields) * @SuppressWarnings(PHPMD.ExcessivePublicCount) @@ -313,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()) @@ -619,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); } @@ -1056,6 +1055,8 @@ public function testGetIsSalableHasDataIsSaleable() /** * Configure environment for `testSave` and `testSaveAndDuplicate` methods + * + * @return void */ protected function configureSaveTest() { @@ -1330,22 +1331,25 @@ public function testGetMediaGalleryImagesMerging() { $mediaEntries = [ - 'images' => [ - [ - 'value_id' => 1, - 'file' => 'imageFile.jpg', - 'media_type' => 'image', - ], - [ - 'value_id' => 3, - 'file' => 'imageFile.jpg', - ], - [ - 'value_id' => 2, - 'file' => 'smallImageFile.jpg', - 'media_type' => 'image', - ], + 'images' => [ + [ + '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, ] + ] ]; $expectedImageDataObject = new DataObject( [ @@ -1355,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( @@ -1365,6 +1370,7 @@ public function testGetMediaGalleryImagesMerging() 'url' => 'http://magento.dev/pub/smallImageFile.jpg', 'id' => 2, 'path' => '/var/www/html/pub/smallImageFile.jpg', + 'position' => 3, ] );