Skip to content

Commit 1487fb3

Browse files
Merge branch 'MC-29126' into 2.3-develop-com-pr10
2 parents 7f98a0a + e7c8428 commit 1487fb3

File tree

123 files changed

+5686
-258
lines changed

Some content is hidden

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

123 files changed

+5686
-258
lines changed

app/code/Magento/Catalog/Model/Category/Attribute/Backend/Image.php

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
*/
66
namespace Magento\Catalog\Model\Category\Attribute\Backend;
77

8+
use Magento\Catalog\Model\ImageUploader;
89
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\App\ObjectManager;
911
use Magento\Framework\File\Uploader;
12+
use Magento\Store\Api\Data\StoreInterface;
13+
use Magento\Store\Model\StoreManagerInterface;
1014

1115
/**
1216
* Catalog category image attribute backend model
@@ -45,7 +49,7 @@ class Image extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
4549
protected $_logger;
4650

4751
/**
48-
* @var \Magento\Catalog\Model\ImageUploader
52+
* @var ImageUploader
4953
*/
5054
private $imageUploader;
5155

@@ -54,19 +58,32 @@ class Image extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
5458
*/
5559
private $additionalData = '_additional_data_';
5660

61+
/**
62+
* @var StoreManagerInterface
63+
*/
64+
private $storeManager;
65+
5766
/**
5867
* @param \Psr\Log\LoggerInterface $logger
5968
* @param \Magento\Framework\Filesystem $filesystem
6069
* @param \Magento\MediaStorage\Model\File\UploaderFactory $fileUploaderFactory
70+
* @param StoreManagerInterface $storeManager
71+
* @param ImageUploader $imageUploader
6172
*/
6273
public function __construct(
6374
\Psr\Log\LoggerInterface $logger,
6475
\Magento\Framework\Filesystem $filesystem,
65-
\Magento\MediaStorage\Model\File\UploaderFactory $fileUploaderFactory
76+
\Magento\MediaStorage\Model\File\UploaderFactory $fileUploaderFactory,
77+
StoreManagerInterface $storeManager = null,
78+
ImageUploader $imageUploader = null
6679
) {
6780
$this->_filesystem = $filesystem;
6881
$this->_fileUploaderFactory = $fileUploaderFactory;
6982
$this->_logger = $logger;
83+
$this->storeManager = $storeManager ??
84+
ObjectManager::getInstance()->get(StoreManagerInterface::class);
85+
$this->imageUploader = $imageUploader ??
86+
ObjectManager::getInstance()->get(ImageUploader::class);
7087
}
7188

7289
/**
@@ -91,16 +108,17 @@ private function getUploadedImageName($value)
91108
*
92109
* @param string $imageName
93110
* @return string
111+
* @throws \Magento\Framework\Exception\FileSystemException
94112
*/
95113
private function checkUniqueImageName(string $imageName): string
96114
{
97-
$imageUploader = $this->getImageUploader();
98115
$mediaDirectory = $this->_filesystem->getDirectoryWrite(DirectoryList::MEDIA);
99116
$imageAbsolutePath = $mediaDirectory->getAbsolutePath(
100-
$imageUploader->getBasePath() . DIRECTORY_SEPARATOR . $imageName
117+
$this->imageUploader->getBasePath() . DIRECTORY_SEPARATOR . $imageName
101118
);
102119

103-
$imageName = Uploader::getNewFilename($imageAbsolutePath);
120+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
121+
$imageName = call_user_func([Uploader::class, 'getNewFilename'], $imageAbsolutePath);
104122

105123
return $imageName;
106124
}
@@ -112,14 +130,26 @@ private function checkUniqueImageName(string $imageName): string
112130
*
113131
* @param \Magento\Framework\DataObject $object
114132
* @return $this
133+
* @throws \Magento\Framework\Exception\FileSystemException
115134
* @since 101.0.8
116135
*/
117136
public function beforeSave($object)
118137
{
119138
$attributeName = $this->getAttribute()->getName();
120139
$value = $object->getData($attributeName);
121140

122-
if ($this->fileResidesOutsideCategoryDir($value)) {
141+
if ($this->isTmpFileAvailable($value) && $imageName = $this->getUploadedImageName($value)) {
142+
try {
143+
/** @var StoreInterface $store */
144+
$store = $this->storeManager->getStore();
145+
$baseMediaDir = $store->getBaseMediaDir();
146+
$newImgRelativePath = $this->imageUploader->moveFileFromTmp($imageName, true);
147+
$value[0]['url'] = '/' . $baseMediaDir . '/' . $newImgRelativePath;
148+
$value[0]['name'] = $value[0]['url'];
149+
} catch (\Exception $e) {
150+
$this->_logger->critical($e);
151+
}
152+
} elseif ($this->fileResidesOutsideCategoryDir($value)) {
123153
// use relative path for image attribute so we know it's outside of category dir when we fetch it
124154
// phpcs:ignore Magento2.Functions.DiscouragedFunction
125155
$value[0]['url'] = parse_url($value[0]['url'], PHP_URL_PATH);
@@ -139,23 +169,6 @@ public function beforeSave($object)
139169
return parent::beforeSave($object);
140170
}
141171

142-
/**
143-
* Get Instance of Category Image Uploader.
144-
*
145-
* @return \Magento\Catalog\Model\ImageUploader
146-
*
147-
* @deprecated 101.0.0
148-
*/
149-
private function getImageUploader()
150-
{
151-
if ($this->imageUploader === null) {
152-
$this->imageUploader = \Magento\Framework\App\ObjectManager::getInstance()
153-
->get(\Magento\Catalog\CategoryImageUpload::class);
154-
}
155-
156-
return $this->imageUploader;
157-
}
158-
159172
/**
160173
* Check if temporary file is available for new image upload.
161174
*
@@ -194,19 +207,10 @@ private function fileResidesOutsideCategoryDir($value)
194207
*
195208
* @param \Magento\Framework\DataObject $object
196209
* @return \Magento\Catalog\Model\Category\Attribute\Backend\Image
210+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
197211
*/
198212
public function afterSave($object)
199213
{
200-
$value = $object->getData($this->additionalData . $this->getAttribute()->getName());
201-
202-
if ($this->isTmpFileAvailable($value) && $imageName = $this->getUploadedImageName($value)) {
203-
try {
204-
$this->getImageUploader()->moveFileFromTmp($imageName);
205-
} catch (\Exception $e) {
206-
$this->_logger->critical($e);
207-
}
208-
}
209-
210214
return $this;
211215
}
212216
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ public function getFilePath($path, $imageName)
191191
* Checking file for moving and move it
192192
*
193193
* @param string $imageName
194-
*
194+
* @param bool $returnRelativePath
195195
* @return string
196196
*
197197
* @throws \Magento\Framework\Exception\LocalizedException
198198
*/
199-
public function moveFileFromTmp($imageName)
199+
public function moveFileFromTmp($imageName, $returnRelativePath = false)
200200
{
201201
$baseTmpPath = $this->getBaseTmpPath();
202202
$basePath = $this->getBasePath();
@@ -226,7 +226,7 @@ public function moveFileFromTmp($imageName)
226226
);
227227
}
228228

229-
return $imageName;
229+
return $returnRelativePath ? $baseImagePath : $imageName;
230230
}
231231

232232
/**

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<!--
12+
NOTICE: AddSimpleProductToCart is deprecated.
13+
Please use AddSimpleProductToCartActionGroup instead.
14+
-->
1115
<actionGroup name="AddSimpleProductToCart">
1216
<annotations>
1317
<description>Navigates to the Storefront Product page. Then adds the Product to the Cart. Validates that the Success Message is present and correct.</description>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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="AddSimpleProductToCartActionGroup">
12+
<annotations>
13+
<description>Navigates to the Storefront Product page. Then adds the Product to the Cart. Validates that the Success Message is present and correct.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="product" defaultValue="product"/>
17+
</arguments>
18+
19+
<amOnPage url="{{StorefrontProductPage.url(product.custom_attributes[url_key])}}" stepKey="goToProductPage"/>
20+
<waitForPageLoad stepKey="waitForProductPage"/>
21+
<click selector="{{StorefrontProductPageSection.addToCartBtn}}" stepKey="addToCart"/>
22+
<waitForElementNotVisible selector="{{StorefrontProductActionSection.addToCartButtonTitleIsAdding}}" stepKey="waitForElementNotVisibleAddToCartButtonTitleIsAdding"/>
23+
<waitForElementNotVisible selector="{{StorefrontProductActionSection.addToCartButtonTitleIsAdded}}" stepKey="waitForElementNotVisibleAddToCartButtonTitleIsAdded"/>
24+
<waitForElementVisible selector="{{StorefrontProductActionSection.addToCartButtonTitleIsAddToCart}}" stepKey="waitForElementVisibleAddToCartButtonTitleIsAddToCart"/>
25+
<waitForPageLoad stepKey="waitForPageLoad"/>
26+
<waitForElementVisible selector="{{StorefrontMessagesSection.success}}" time="30" stepKey="waitForProductAddedMessage"/>
27+
<see selector="{{StorefrontMessagesSection.success}}" userInput="You added {{product.name}} to your shopping cart." stepKey="seeAddToCartSuccessMessage"/>
28+
</actionGroup>
29+
</actionGroups>

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11-
<!--Navigate to create product page from product grid page-->
11+
<!--
12+
NOTICE: goToCreateProductPage is deprecated.
13+
Please use GoToCreateProductPageActionGroup instead.
14+
-->
1215
<actionGroup name="goToCreateProductPage">
1316
<annotations>
1417
<description>Clicks on the 'Add Product' toggle on the Admin Products grid page. Clicks on the provided Product (Type).</description>
@@ -25,7 +28,10 @@
2528
<see selector="{{AdminHeaderSection.pageTitle}}" userInput="New Product" stepKey="seeNewProductTitle"/>
2629
</actionGroup>
2730

28-
<!--Navigate to create product page directly via ID-->
31+
<!--
32+
NOTICE: goToProductPageViaID is deprecated.
33+
Please use GoToProductPageViaIDActionGroup instead.
34+
-->
2935
<actionGroup name="goToProductPageViaID">
3036
<annotations>
3137
<description>Goes to the Product edit page for the provided Product ID.</description>
@@ -37,7 +43,10 @@
3743
<amOnPage url="{{AdminProductEditPage.url(productId)}}" stepKey="goToProduct"/>
3844
</actionGroup>
3945

40-
<!-- Fill main fields in create product form using a product entity -->
46+
<!--
47+
NOTICE: fillMainProductForm is deprecated.
48+
Please use FillMainProductFormActionGroup instead.
49+
-->
4150
<actionGroup name="fillMainProductForm">
4251
<annotations>
4352
<description>Fills in the provided Product details (Name, SKU, Price, Quantity, Stock Status, Weight Type and Weight) on the Admin Products creation/edit page.</description>
@@ -56,7 +65,10 @@
5665
<fillField selector="{{AdminProductFormSection.productWeight}}" userInput="{{product.weight}}" stepKey="fillProductWeight"/>
5766
</actionGroup>
5867

59-
<!-- Fill main fields in create product form using strings for flexibility -->
68+
<!--
69+
NOTICE: FillMainProductFormByString is deprecated.
70+
Please use FillMainProductFormByStringActionGroup instead.
71+
-->
6072
<actionGroup name="FillMainProductFormByString">
6173
<annotations>
6274
<description>Fills in the provided Product Name, SKU, Price, Quantity, Stock Status and Weight on the Admin Products creation/edit page.</description>
@@ -79,7 +91,10 @@
7991
<fillField selector="{{AdminProductFormSection.productWeight}}" userInput="{{productWeight}}" stepKey="fillProductWeight"/>
8092
</actionGroup>
8193

82-
<!--Fill main fields in create product form with no weight, useful for virtual and downloadable products -->
94+
<!--
95+
NOTICE: fillMainProductFormNoWeight is deprecated.
96+
Please use FillMainProductFormNoWeightActionGroup instead.
97+
-->
8398
<actionGroup name="fillMainProductFormNoWeight">
8499
<annotations>
85100
<description>Fills in the provided Product details (Name, SKU, Price, Quantity, Stock Status and Weight Type) on the Admin Products creation/edit page.</description>
@@ -96,7 +111,10 @@
96111
<selectOption selector="{{AdminProductFormSection.productWeightSelect}}" userInput="This item has no weight" stepKey="selectWeight"/>
97112
</actionGroup>
98113

99-
<!--Fill main fields in create product form with name and sku -->
114+
<!--
115+
NOTICE: fillProductNameAndSkuInProductForm is deprecated.
116+
Please use FillProductNameAndSkuInProductForm instead.
117+
-->
100118
<actionGroup name="fillProductNameAndSkuInProductForm">
101119
<annotations>
102120
<description>Fills in the provided Product details (Name and SKU) on the Admin Products creation and edit page.</description>
@@ -131,7 +149,10 @@
131149
<see selector="{{AdminProductFormSection.priceFieldError}}" userInput="This is a required field." stepKey="seePriceRequired"/>
132150
</actionGroup>
133151

134-
<!--Save product and see success message-->
152+
<!--
153+
NOTICE: saveProductForm is deprecated.
154+
Please use SaveProductFormActionGroup instead.
155+
-->
135156
<actionGroup name="saveProductForm">
136157
<annotations>
137158
<description>Clicks on the Save button. Validates that the Success Message is present and correct.</description>

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11-
<!--Reset the product grid to the default view-->
11+
<!--
12+
NOTICE: resetProductGridToDefaultView is deprecated.
13+
Please use ResetProductGridToDefaultViewActionGroup instead.
14+
-->
1215
<actionGroup name="resetProductGridToDefaultView">
1316
<annotations>
1417
<description>Sets the Admin Products grid view to the 'Default View'.</description>
@@ -21,7 +24,10 @@
2124
<see selector="{{AdminProductGridFilterSection.viewDropdown}}" userInput="Default View" stepKey="seeDefaultViewSelected"/>
2225
</actionGroup>
2326

24-
<!--Filter the product grid by the SKU field-->
27+
<!--
28+
NOTICE: filterProductGridBySku is deprecated.
29+
Please use FilterProductGridBySkuActionGroup instead.
30+
-->
2531
<actionGroup name="filterProductGridBySku">
2632
<annotations>
2733
<description>Filters the Admin Products grid by the provided Product (SKU).</description>
@@ -37,7 +43,10 @@
3743
<waitForElementNotVisible selector="{{AdminProductGridSection.loadingMask}}" stepKey="waitForFilteredGridLoad" time="30"/>
3844
</actionGroup>
3945

40-
<!--Filter the product grid by the SKU string -->
46+
<!--
47+
NOTICE: filterProductGridBySku2 is deprecated.
48+
Please use FilterProductGridBySku2ActionGroup instead.
49+
-->
4150
<actionGroup name="filterProductGridBySku2">
4251
<annotations>
4352
<description>Filters the Admin Products grid by the provided Product SKU.</description>
@@ -53,7 +62,10 @@
5362
<waitForElementNotVisible selector="{{AdminProductGridSection.loadingMask}}" stepKey="waitForFilteredGridLoad" time="30"/>
5463
</actionGroup>
5564

56-
<!--Filter the product grid by the Name field-->
65+
<!--
66+
NOTICE: filterProductGridByName is deprecated.
67+
Please use FilterProductGridByNameActionGroup instead.
68+
-->
5769
<actionGroup name="filterProductGridByName">
5870
<annotations>
5971
<description>Filters the Admin Products grid by the provided Product (Name).</description>
@@ -208,7 +220,10 @@
208220
<click selector="{{AdminProductGridFilterSection.applyFilters}}" stepKey="clickApplyFilters"/>
209221
</actionGroup>
210222

211-
<!--Delete a product by filtering grid and using delete action-->
223+
<!--
224+
NOTICE: deleteProductUsingProductGrid is deprecated.
225+
Please use DeleteProductUsingProductGridActionGroup instead.
226+
-->
212227
<actionGroup name="deleteProductUsingProductGrid">
213228
<annotations>
214229
<description>Deletes the provided Product from the Admin Products grid page.</description>
@@ -246,7 +261,10 @@
246261
<remove keyForRemoval="seeProductSkuInGrid"/>
247262
</actionGroup>
248263

249-
<!--Delete a product by filtering grid and using delete action-->
264+
<!--
265+
NOTICE: deleteProductBySku is deprecated.
266+
Please use DeleteProductBySkuActionGroup instead.
267+
-->
250268
<actionGroup name="deleteProductBySku">
251269
<annotations>
252270
<description>Goes to the Admin Products grid page. Deletes the provided Product SKU.</description>

0 commit comments

Comments
 (0)