Skip to content

Commit 02ee4d7

Browse files
authored
ENGCOM-8532: ISSUE-29690: Fixing issue when the images' sort was using ID instead of position field #30938
2 parents 9335786 + 6a2c40e commit 02ee4d7

File tree

4 files changed

+187
-3
lines changed

4 files changed

+187
-3
lines changed

app/code/Magento/ConfigurableProduct/Block/Plugin/Product/Media/Gallery.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public function afterGetOptionsMediaGalleryDataJson(
5656
* @param Product $product
5757
* @return array
5858
*/
59-
private function getProductGallery($product)
59+
private function getProductGallery(Product $product): array
6060
{
6161
$result = [];
62-
$images = $product->getMediaGalleryImages();
62+
$images = $this->getImagesOrderedByPosition($product);
6363
foreach ($images as $image) {
6464
$result[] = [
6565
'mediaType' => $image->getMediaType(),
@@ -69,4 +69,18 @@ private function getProductGallery($product)
6969
}
7070
return $result;
7171
}
72+
73+
/**
74+
* @param Product $product
75+
* @return array
76+
*/
77+
private function getImagesOrderedByPosition(Product $product): array
78+
{
79+
$imagesCollection = $product->getMediaGalleryImages();
80+
$images = $imagesCollection->getItems();
81+
usort($images, function ($el1, $el2) {
82+
return $el1['position'] <=> $el2['position'];
83+
});
84+
return $images;
85+
}
7286
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="StorefrontSelectSimpleProductOfConfigurableProductPageActionGroup">
12+
<annotations>
13+
<description>Goes to the provided Storefront URL. Selects the provided Product Option under the Product Attribute.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="urlKey" type="string"/>
17+
<argument name="productAttribute" type="string"/>
18+
<argument name="productOption" type="string"/>
19+
</arguments>
20+
21+
<amOnPage url="{{urlKey}}.html" stepKey="goToStorefrontPage"/>
22+
<waitForPageLoad stepKey="waitForProductFrontPageToLoad"/>
23+
<selectOption selector="{{StorefrontProductInfoMainSection.productOptionSelect(productAttribute)}}" userInput="{{productOption}}" stepKey="selectOption1"/>
24+
</actionGroup>
25+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminCreateConfigurableProductWithVideoAssociatedToVariantTest">
12+
<annotations>
13+
<features value="ConfigurableProduct"/>
14+
<stories value="Add videos for all variant product"/>
15+
<title value="Admin should be able to add videos for a variant Product"/>
16+
<description value="Admin should be able to add videos for a Variant Product"/>
17+
<severity value="MAJOR"/>
18+
<testCaseId value="MC-37344"/>
19+
<group value="ConfigurableProduct"/>
20+
<skip>
21+
<issueId value="MC-33903"/>
22+
</skip>
23+
</annotations>
24+
25+
<before>
26+
<createData entity="ProductVideoYoutubeApiKeyConfig" stepKey="setYoutubeApiKeyConfig"/>
27+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
28+
<createData entity="SimpleSubCategory" stepKey="categoryHandle"/>
29+
30+
<createData entity="SimpleProduct" stepKey="simple1Handle">
31+
<requiredEntity createDataKey="categoryHandle"/>
32+
</createData>
33+
34+
<createData entity="SimpleProduct" stepKey="simple2Handle">
35+
<requiredEntity createDataKey="categoryHandle"/>
36+
</createData>
37+
38+
<createData entity="BaseConfigurableProduct" stepKey="baseConfigProductHandle">
39+
<requiredEntity createDataKey="categoryHandle"/>
40+
</createData>
41+
<createData entity="productDropDownAttribute" stepKey="productAttributeHandle"/>
42+
43+
<createData entity="productAttributeOption1" stepKey="productAttributeOption1Handle">
44+
<requiredEntity createDataKey="productAttributeHandle"/>
45+
</createData>
46+
<createData entity="productAttributeOption2" stepKey="productAttributeOption2Handle">
47+
<requiredEntity createDataKey="productAttributeHandle"/>
48+
</createData>
49+
50+
<createData entity="AddToDefaultSet" stepKey="addToAttributeSetHandle">
51+
<requiredEntity createDataKey="productAttributeHandle"/>
52+
</createData>
53+
54+
<getData entity="ProductAttributeOptionGetter" index="1" stepKey="getAttributeOption1Handle">
55+
<requiredEntity createDataKey="productAttributeHandle"/>
56+
</getData>
57+
<getData entity="ProductAttributeOptionGetter" index="2" stepKey="getAttributeOption2Handle">
58+
<requiredEntity createDataKey="productAttributeHandle"/>
59+
</getData>
60+
61+
<createData entity="SimpleOne" stepKey="childProductHandle1">
62+
<requiredEntity createDataKey="productAttributeHandle"/>
63+
<requiredEntity createDataKey="getAttributeOption1Handle"/>
64+
</createData>
65+
<createData entity="SimpleOne" stepKey="childProductHandle2">
66+
<requiredEntity createDataKey="productAttributeHandle"/>
67+
<requiredEntity createDataKey="getAttributeOption2Handle"/>
68+
</createData>
69+
70+
<createData entity="ConfigurableProductTwoOptions" stepKey="configProductOptionHandle">
71+
<requiredEntity createDataKey="baseConfigProductHandle"/>
72+
<requiredEntity createDataKey="productAttributeHandle"/>
73+
<requiredEntity createDataKey="getAttributeOption1Handle"/>
74+
<requiredEntity createDataKey="getAttributeOption2Handle"/>
75+
</createData>
76+
77+
<createData entity="ConfigurableProductAddChild" stepKey="configProductHandle1">
78+
<requiredEntity createDataKey="baseConfigProductHandle"/>
79+
<requiredEntity createDataKey="childProductHandle1"/>
80+
</createData>
81+
<createData entity="ConfigurableProductAddChild" stepKey="configProductHandle2">
82+
<requiredEntity createDataKey="baseConfigProductHandle"/>
83+
<requiredEntity createDataKey="childProductHandle2"/>
84+
</createData>
85+
</before>
86+
<after>
87+
<actionGroup ref="AdminLogoutActionGroup" stepKey="amOnLogoutPage"/>
88+
<createData entity="DefaultProductVideoConfig" stepKey="setYoutubeApiKeyDefaultConfig"/>
89+
<deleteData createDataKey="simple1Handle" stepKey="deleteSimple1"/>
90+
<deleteData createDataKey="simple2Handle" stepKey="deleteSimple2"/>
91+
<deleteData createDataKey="childProductHandle1" stepKey="deleteChild1"/>
92+
<deleteData createDataKey="childProductHandle2" stepKey="deleteChild2"/>
93+
<deleteData createDataKey="baseConfigProductHandle" stepKey="deleteConfig"/>
94+
<deleteData createDataKey="categoryHandle" stepKey="deleteCategory"/>
95+
<deleteData createDataKey="productAttributeHandle" stepKey="deleteProductAttribute"/>
96+
97+
<!-- Reindex invalidated indices after product attribute has been created/deleted -->
98+
<magentoCron groups="index" stepKey="reindexInvalidatedIndices"/>
99+
</after>
100+
101+
<actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="productIndexPage"/>
102+
103+
<actionGroup ref="FilterProductGridBySkuActionGroup" stepKey="filterProductGrid">
104+
<argument name="product" value="$$childProductHandle1$$"/>
105+
</actionGroup>
106+
<actionGroup ref="OpenProductForEditByClickingRowXColumnYInProductGridActionGroup" stepKey="openProducForEditByClickingRow1Column2InProductGrid1"/>
107+
108+
<actionGroup ref="AddProductVideoActionGroup" stepKey="addVideoForProduct" />
109+
110+
<!-- Add image to product -->
111+
<actionGroup ref="AddProductImageActionGroup" stepKey="addImageForProduct">
112+
<argument name="image" value="MagentoLogo"/>
113+
</actionGroup>
114+
<actionGroup ref="SaveProductFormActionGroup" stepKey="saveProduct"/>
115+
116+
<!-- Assert product image in admin product form -->
117+
<actionGroup ref="AssertProductImageAdminProductPageActionGroup" stepKey="assertProductImageAdminProductPage"/>
118+
119+
<!-- Assert product in storefront product page -->
120+
<actionGroup ref="AssertProductNameAndSkuInStorefrontProductPageByCustomAttributeUrlKeyActionGroup" stepKey="AssertProductInStorefrontProductPage">
121+
<argument name="product" value="$$baseConfigProductHandle$$"/>
122+
</actionGroup>
123+
124+
<actionGroup ref="StorefrontSelectSimpleProductOfConfigurableProductPageActionGroup" stepKey="assertSimpleProductIsAccessibleInStorefrontProductPageActionGroup" >
125+
<argument name="urlKey" value="$$baseConfigProductHandle.custom_attributes[url_key]$$" />
126+
<argument name="productAttribute" value="$$productAttributeHandle.default_value$$"/>
127+
<argument name="productOption" value="$$getAttributeOption1Handle.value$$"/>
128+
</actionGroup>
129+
130+
<!-- Assert product image in storefront product page -->
131+
<actionGroup ref="AssertProductImageStorefrontProductPage2ActionGroup" stepKey="assertProductImageStorefrontProductPageActionGroup">
132+
<argument name="product" value="$$baseConfigProductHandle$$"/>
133+
<argument name="image" value="MagentoLogo"/>
134+
</actionGroup>
135+
136+
<!-- Assert product video in storefront product page -->
137+
<actionGroup ref="AssertProductVideoStorefrontProductPageActionGroup" stepKey="assertProductVideoStorefrontProductPage"/>
138+
</test>
139+
</tests>

app/code/Magento/ConfigurableProduct/Test/Unit/Block/Plugin/Product/Media/GalleryTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\ConfigurableProduct\Block\Plugin\Product\Media\Gallery;
1212
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1313
use Magento\Framework\DataObject;
14+
use Magento\Framework\Data\Collection as DataCollection;
1415
use Magento\Framework\Serialize\Serializer\Json;
1516
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1617
use PHPUnit\Framework\MockObject\MockObject;
@@ -41,13 +42,18 @@ public function testAfterGetOptions()
4142
['media_type' => 'type', 'video_url' => 'url', 'file' => 'image.jpg']
4243
);
4344

45+
$dataCollection = $this->getMockBuilder(DataCollection::class)
46+
->disableOriginalConstructor()
47+
->onlyMethods(['getItems'])
48+
->getMock();
4449
$galleryMock->expects(($this->any()))->method('getProduct')->willReturn($productMock);
4550
$productMock->expects($this->once())->method('getTypeId')->willReturn('configurable');
4651
$productMock->expects($this->once())->method('getTypeInstance')->willReturn($configurableTypeMock);
4752
$configurableTypeMock->expects($this->once())->method('getUsedProducts')->with($productMock)
4853
->willReturn([$variationProductMock]);
4954
$variationProductMock->expects($this->once())->method('getId')->willReturn($variationProductId);
50-
$variationProductMock->expects($this->once())->method('getMediaGalleryImages')->willReturn([$image]);
55+
$variationProductMock->expects($this->once())->method('getMediaGalleryImages')->willReturn($dataCollection);
56+
$dataCollection->expects($this->once())->method('getItems')->willReturn([$image]);
5157
$variationProductMock->expects($this->once())->method('getImage')->willReturn('image.jpg');
5258
$jsonMock->expects($this->once())->method('serialize')->with($expectedGalleryJson)
5359
->willReturn(json_encode($expectedGalleryJson));

0 commit comments

Comments
 (0)