Skip to content

Commit 5fad0cd

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop-express-lane-prs
- merged with '2.4-develop-fast-lane-prs' branch
2 parents 1fd9c35 + ef7617e commit 5fad0cd

File tree

97 files changed

+2599
-1100
lines changed

Some content is hidden

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

97 files changed

+2599
-1100
lines changed

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+
}

app/code/Magento/Catalog/Test/Mftf/ActionGroup/AddSimpleProductToCartActionGroup.xml

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

99
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11-
<actionGroup name="AddSimpleProductToCartActionGroup">
11+
<actionGroup name="AddSimpleProductToCartActionGroup" deprecated="Avoid using super-ActionGroups. Use StorefrontOpenProductEntityPageActionGroup, StorefrontAddSimpleProductToCartActionGroup and StorefrontAssertProductAddedToCartResultMessageActionGroup">
1212
<annotations>
1313
<description>Navigates to the Storefront Product page. Then adds the Product to the Cart. Validates that the Success Message is present and correct.</description>
1414
</annotations>
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AssertAdminProductGridCellActionGroup">
12+
<annotations>
13+
<description>Checks value for Admin Product Grid cell by provided row and column.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="row" type="string" defaultValue="1"/>
17+
<argument name="column" type="string" defaultValue="Name"/>
18+
<argument name="value" type="string" defaultValue="1"/>
19+
</arguments>
20+
21+
<see selector="{{AdminProductGridSection.productGridCell(row,column)}}" userInput="{{value}}" stepKey="seeProductGridCellWithProvidedValue"/>
22+
</actionGroup>
23+
</actionGroups>
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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="CheckAdminProductGridColumnOptionActionGroup">
12+
<annotations>
13+
<description>Checks Admin Product Grid 'Columns' option.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="optionName" type="string" defaultValue="Name"/>
17+
</arguments>
18+
19+
<checkOption selector="{{AdminProductGridFilterSection.viewColumnOption(optionName)}}" stepKey="checkColumn"/>
20+
</actionGroup>
21+
</actionGroups>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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="ClearFiltersAdminProductGridActionGroup">
12+
<annotations>
13+
<description>Clicks on 'Clear Filters'.</description>
14+
</annotations>
15+
16+
<conditionalClick selector="{{AdminProductGridFilterSection.clearFilters}}" dependentSelector="{{AdminProductGridFilterSection.clearFilters}}" visible="true" stepKey="clickClearFilters"/>
17+
<waitForPageLoad stepKey="waitForGridLoad"/>
18+
</actionGroup>
19+
</actionGroups>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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="ResetAdminProductGridColumnsActionGroup">
12+
<annotations>
13+
<description>Clicks 'reset' for Admin Product Grid 'Columns' dropdown.</description>
14+
</annotations>
15+
16+
<click selector="{{AdminProductGridFilterSection.resetGridColumns}}" stepKey="resetProductGridColumns"/>
17+
</actionGroup>
18+
</actionGroups>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="StorefrontOpenProductEntityPageActionGroup">
11+
<annotations>
12+
<description>Opens Storefront Product page for the provided Product Entity</description>
13+
</annotations>
14+
<arguments>
15+
<argument name="product" type="entity"/>
16+
</arguments>
17+
18+
<amOnPage url="{{StorefrontProductPage.url(product.custom_attributes[url_key])}}" stepKey="goToProductPage"/>
19+
<waitForPageLoad stepKey="waitForProductPageLoaded"/>
20+
</actionGroup>
21+
</actionGroups>

0 commit comments

Comments
 (0)