Skip to content

Commit 05fbd1f

Browse files
authored
Merge branch '2.4-develop' into fallback-to-storelabels-customer-attributes
2 parents b1480fb + ba5f8eb commit 05fbd1f

File tree

68 files changed

+1775
-721
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1775
-721
lines changed

app/code/Magento/Bundle/Test/Mftf/Test/AdminCreateAndEditBundleProductSettingsTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126

127127
<!-- Verify Url Key after changing -->
128128
<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openProductPage">
129-
<argument name="productUrl" value="{{ApiBundleProduct.name}}"/>
129+
<argument name="productUrl" value="{{ApiBundleProduct.urlKey}}"/>
130130
</actionGroup>
131131

132132
<!-- Assert product design settings "Layout empty" -->

app/code/Magento/Catalog/Block/Product/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @method string getHeight()
1515
* @method string getLabel()
1616
* @method float getRatio()
17-
* @method string getCustomAttributes()
17+
* @method array getCustomAttributes()
1818
* @method string getClass()
1919
* @since 100.0.2
2020
*/

app/code/Magento/Catalog/Block/Product/ImageFactory.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,17 @@ public function __construct(
6868
}
6969

7070
/**
71-
* Retrieve image custom attributes for HTML element
71+
* Remove class from custom attributes
7272
*
7373
* @param array $attributes
74-
* @return string
74+
* @return array
7575
*/
76-
private function getStringCustomAttributes(array $attributes): string
76+
private function filterCustomAttributes(array $attributes): array
7777
{
78-
$result = [];
79-
foreach ($attributes as $name => $value) {
80-
if ($name != 'class') {
81-
$result[] = $name . '="' . $value . '"';
82-
}
78+
if (isset($attributes['class'])) {
79+
unset($attributes['class']);
8380
}
84-
return !empty($result) ? implode(' ', $result) : '';
81+
return $attributes;
8582
}
8683

8784
/**
@@ -170,7 +167,7 @@ public function create(Product $product, string $imageId, array $attributes = nu
170167
'height' => $imageMiscParams['image_height'],
171168
'label' => $this->getLabel($product, $imageMiscParams['image_type']),
172169
'ratio' => $this->getRatio($imageMiscParams['image_width'] ?? 0, $imageMiscParams['image_height'] ?? 0),
173-
'custom_attributes' => $this->getStringCustomAttributes($attributes),
170+
'custom_attributes' => $this->filterCustomAttributes($attributes),
174171
'class' => $this->getClass($attributes),
175172
'product_id' => $product->getId()
176173
],

app/code/Magento/Catalog/Model/ImageUploader.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,10 @@ public function moveFileFromTmp($imageName, $returnRelativePath = false)
236236
$storage->put($baseImagePath, $content);
237237

238238
} catch (\Exception $e) {
239+
$this->logger->critical($e);
239240
throw new \Magento\Framework\Exception\LocalizedException(
240-
__('Something went wrong while saving the file(s).')
241+
__('Something went wrong while saving the file(s).'),
242+
$e
241243
);
242244
}
243245

@@ -291,7 +293,8 @@ public function saveFileToTmpDir($fileId)
291293
} catch (\Exception $e) {
292294
$this->logger->critical($e);
293295
throw new \Magento\Framework\Exception\LocalizedException(
294-
__('Something went wrong while saving the file(s).')
296+
__('Something went wrong while saving the file(s).'),
297+
$e
295298
);
296299
}
297300
}

app/code/Magento/Catalog/Model/ProductRepository/MediaGalleryProcessor.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,15 @@ private function processEntries(ProductInterface $product, array $newEntries, ar
224224
$this->processNewMediaGalleryEntry($product, $newEntry);
225225

226226
$finalGallery = $product->getData('media_gallery');
227-
$newEntryId = key(array_diff_key($product->getData('media_gallery')['images'], $entriesById));
227+
228+
$entryIds = array_keys(
229+
array_diff_key(
230+
$product->getData('media_gallery')['images'],
231+
$entriesById
232+
)
233+
);
234+
$newEntryId = array_pop($entryIds);
235+
228236
$newEntry = array_replace_recursive($newEntry, $finalGallery['images'][$newEntryId]);
229237
$entriesById[$newEntryId] = $newEntry;
230238
$finalGallery['images'][$newEntryId] = $newEntry;

app/code/Magento/Catalog/Model/ResourceModel/Product/Website/Link.php

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
use Magento\Catalog\Api\Data\ProductInterface;
99
use Magento\Framework\App\ResourceConnection;
10-
use Magento\Framework\EntityManager\MetadataPool;
1110

11+
/**
12+
* Class Link used for assign website to the product
13+
*/
1214
class Link
1315
{
1416
/**
@@ -28,6 +30,7 @@ public function __construct(
2830

2931
/**
3032
* Retrieve associated with product websites ids
33+
*
3134
* @param int $productId
3235
* @return array
3336
*/
@@ -48,29 +51,53 @@ public function getWebsiteIdsByProductId($productId)
4851

4952
/**
5053
* Return true - if websites was changed, and false - if not
54+
*
5155
* @param ProductInterface $product
5256
* @param array $websiteIds
5357
* @return bool
5458
*/
5559
public function saveWebsiteIds(ProductInterface $product, array $websiteIds)
60+
{
61+
$productId = (int) $product->getId();
62+
return $this->updateProductWebsite($productId, $websiteIds);
63+
}
64+
65+
/**
66+
* Get Product website table
67+
*
68+
* @return string
69+
*/
70+
private function getProductWebsiteTable()
71+
{
72+
return $this->resourceConnection->getTableName('catalog_product_website');
73+
}
74+
75+
/**
76+
* Update product website table
77+
*
78+
* @param int $productId
79+
* @param array $websiteIds
80+
* @return bool
81+
*/
82+
public function updateProductWebsite(int $productId, array $websiteIds): bool
5683
{
5784
$connection = $this->resourceConnection->getConnection();
5885

59-
$oldWebsiteIds = $this->getWebsiteIdsByProductId($product->getId());
86+
$oldWebsiteIds = $this->getWebsiteIdsByProductId($productId);
6087
$insert = array_diff($websiteIds, $oldWebsiteIds);
6188
$delete = array_diff($oldWebsiteIds, $websiteIds);
6289

6390
if (!empty($insert)) {
6491
$data = [];
6592
foreach ($insert as $websiteId) {
66-
$data[] = ['product_id' => (int) $product->getId(), 'website_id' => (int) $websiteId];
93+
$data[] = ['product_id' => $productId, 'website_id' => (int)$websiteId];
6794
}
6895
$connection->insertMultiple($this->getProductWebsiteTable(), $data);
6996
}
7097

7198
if (!empty($delete)) {
7299
foreach ($delete as $websiteId) {
73-
$condition = ['product_id = ?' => (int) $product->getId(), 'website_id = ?' => (int) $websiteId];
100+
$condition = ['product_id = ?' => $productId, 'website_id = ?' => (int)$websiteId];
74101
$connection->delete($this->getProductWebsiteTable(), $condition);
75102
}
76103
}
@@ -81,12 +108,4 @@ public function saveWebsiteIds(ProductInterface $product, array $websiteIds)
81108

82109
return false;
83110
}
84-
85-
/**
86-
* @return string
87-
*/
88-
private function getProductWebsiteTable()
89-
{
90-
return $this->resourceConnection->getTableName('catalog_product_website');
91-
}
92111
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
namespace Magento\Catalog\Model\ResourceModel;
8+
9+
use Magento\Catalog\Model\ResourceModel\Product\Website\Link;
10+
use Magento\Framework\EntityManager\Operation\AttributeInterface;
11+
12+
/**
13+
* Class purpose is to handle product websites assignment
14+
*/
15+
class ProductWebsiteAssignmentHandler implements AttributeInterface
16+
{
17+
/**
18+
* @var Link
19+
*/
20+
private $productLink;
21+
22+
/**
23+
* ProductWebsiteAssignmentHandler constructor
24+
*
25+
* @param Link $productLink
26+
*/
27+
public function __construct(
28+
Link $productLink
29+
) {
30+
$this->productLink = $productLink;
31+
}
32+
33+
/**
34+
* Assign product website entity to the product repository
35+
*
36+
* @param string $entityType
37+
* @param array $entityData
38+
* @param array $arguments
39+
* @return array
40+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
41+
* @throws \Exception
42+
*/
43+
public function execute($entityType, $entityData, $arguments = []): array
44+
{
45+
$websiteIds = array_key_exists('website_ids', $entityData) ?
46+
array_filter($entityData['website_ids'], function ($websiteId) {
47+
return $websiteId !== null;
48+
}) : [];
49+
$productId = array_key_exists('entity_id', $entityData) ? (int) $entityData['entity_id'] : null;
50+
51+
if (!empty($productId) && !empty($websiteIds)) {
52+
$this->productLink->updateProductWebsite($productId, $websiteIds);
53+
}
54+
return $entityData;
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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="AssertSeeProductDetailsOnStorefrontRecentlyViewedWidgetActionGroup">
12+
<annotations>
13+
<description>Goes to the home Page Recently VIewed Product and Grab the Prdouct name and Position from it.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="productName" type="string"/>
17+
<argument name="productPosition" type="string"/>
18+
</arguments>
19+
<grabTextFrom selector="{{StoreFrontRecentlyViewedProductSection.ProductName(productPosition)}}" stepKey="grabRelatedProductPosition"/>
20+
<assertContains expected="{{productName}}" actual="$grabRelatedProductPosition" stepKey="assertRelatedProductName"/>
21+
</actionGroup>
22+
</actionGroups>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
11+
<entity name="RecentlyViewedProductScopeStore">
12+
<data key="path">catalog/recently_products/scope</data>
13+
<data key="value">store</data>
14+
</entity>
15+
<entity name="RecentlyViewedProductScopeWebsite">
16+
<data key="path">catalog/recently_products/scope</data>
17+
<data key="value">website</data>
18+
</entity>
19+
<entity name="RecentlyViewedProductScopeStoreGroup">
20+
<data key="path">catalog/recently_products/scope</data>
21+
<data key="value">group</data>
22+
</entity>
23+
</entities>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
12+
<section name="StoreFrontRecentlyViewedProductSection">
13+
<element name="ProductName" type="text" selector="//div[@class='products-grid']/ol/li[position()={{position}}]/div/div[@class='product-item-details']/strong/a" parameterized="true"/>
14+
</section>
15+
</sections>

app/code/Magento/Catalog/Test/Mftf/Test/AdminMoveCategoryAndCheckUrlRewritesTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<createData entity="FirstLevelSubCat" stepKey="createDefaultCategory">
2323
<field key="is_active">true</field>
2424
</createData>
25+
<!-- Perform reindex and flush cache -->
26+
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
27+
<magentoCLI command="cache:flush" stepKey="flushCache"/>
2528
</before>
2629
<after>
2730
<deleteData createDataKey="createDefaultCategory" stepKey="deleteCategory"/>

0 commit comments

Comments
 (0)