Skip to content

Commit a7c6bc4

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop
- merged latest code from mainline branch
2 parents 14dfa6f + c4c29b3 commit a7c6bc4

File tree

190 files changed

+5179
-1368
lines changed

Some content is hidden

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

190 files changed

+5179
-1368
lines changed

app/code/Magento/AsynchronousOperations/Model/MassSchedule.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class MassSchedule
5353
private $logger;
5454

5555
/**
56-
* @var OperationRepository
56+
* @var OperationRepositoryInterface
5757
*/
5858
private $operationRepository;
5959

@@ -75,7 +75,7 @@ class MassSchedule
7575
* @param AsyncResponseInterfaceFactory $asyncResponseFactory
7676
* @param BulkManagementInterface $bulkManagement
7777
* @param LoggerInterface $logger
78-
* @param OperationRepository $operationRepository
78+
* @param OperationRepositoryInterface $operationRepository
7979
* @param UserContextInterface $userContext
8080
* @param Encryptor $encryptor
8181
*/
@@ -85,7 +85,7 @@ public function __construct(
8585
AsyncResponseInterfaceFactory $asyncResponseFactory,
8686
BulkManagementInterface $bulkManagement,
8787
LoggerInterface $logger,
88-
OperationRepository $operationRepository,
88+
OperationRepositoryInterface $operationRepository,
8989
UserContextInterface $userContext,
9090
Encryptor $encryptor
9191
) {
@@ -137,7 +137,7 @@ public function publishMass($topicName, array $entitiesArray, $groupId = null, $
137137
$requestItem = $this->itemStatusInterfaceFactory->create();
138138

139139
try {
140-
$operation = $this->operationRepository->createByTopic($topicName, $entityParams, $groupId);
140+
$operation = $this->operationRepository->create($topicName, $entityParams, $groupId, $key);
141141
$operations[] = $operation;
142142
$requestItem->setId($key);
143143
$requestItem->setStatus(ItemStatusInterface::STATUS_ACCEPTED);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AsynchronousOperations\Model;
9+
10+
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
11+
12+
/**
13+
* Repository interface to create operation
14+
*/
15+
interface OperationRepositoryInterface
16+
{
17+
/**
18+
* Create operation by topic, parameters and group ID
19+
*
20+
* @param string $topicName
21+
* @param array $entityParams
22+
* format: array(
23+
* '<arg1-name>' => '<arg1-value>',
24+
* '<arg2-name>' => '<arg2-value>',
25+
* )
26+
* @param string $groupId
27+
* @param int $operationId
28+
* @return OperationInterface
29+
*/
30+
public function create($topicName, $entityParams, $groupId, $operationId): OperationInterface;
31+
}

app/code/Magento/AsynchronousOperations/Model/ResourceModel/Operation/OperationRepository.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
1212
use Magento\AsynchronousOperations\Api\Data\OperationInterfaceFactory;
13+
use Magento\AsynchronousOperations\Model\OperationRepositoryInterface;
1314
use Magento\Framework\MessageQueue\MessageValidator;
1415
use Magento\Framework\MessageQueue\MessageEncoder;
1516
use Magento\Framework\Serialize\Serializer\Json;
@@ -18,10 +19,10 @@
1819
/**
1920
* Create operation for list of bulk operations.
2021
*/
21-
class OperationRepository
22+
class OperationRepository implements OperationRepositoryInterface
2223
{
2324
/**
24-
* @var \Magento\AsynchronousOperations\Api\Data\OperationInterfaceFactory
25+
* @var OperationInterfaceFactory
2526
*/
2627
private $operationFactory;
2728

@@ -67,10 +68,14 @@ public function __construct(
6768
}
6869

6970
/**
70-
* @param $topicName
71-
* @param $entityParams
72-
* @param $groupId
73-
* @return mixed
71+
* Create operation by topic, parameters and group ID
72+
*
73+
* @param string $topicName
74+
* @param array $entityParams
75+
* @param string $groupId
76+
* @return OperationInterface
77+
* @deprecated No longer used.
78+
* @see create()
7479
*/
7580
public function createByTopic($topicName, $entityParams, $groupId)
7681
{
@@ -91,8 +96,16 @@ public function createByTopic($topicName, $entityParams, $groupId)
9196
],
9297
];
9398

94-
/** @var \Magento\AsynchronousOperations\Api\Data\OperationInterface $operation */
99+
/** @var OperationInterface $operation */
95100
$operation = $this->operationFactory->create($data);
96101
return $this->entityManager->save($operation);
97102
}
103+
104+
/**
105+
* @inheritDoc
106+
*/
107+
public function create($topicName, $entityParams, $groupId, $operationId): OperationInterface
108+
{
109+
return $this->createByTopic($topicName, $entityParams, $groupId);
110+
}
98111
}

app/code/Magento/AsynchronousOperations/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<preference for="Magento\AsynchronousOperations\Api\Data\BulkOperationsStatusInterface" type="Magento\AsynchronousOperations\Model\BulkStatus\Short" />
1919
<preference for="Magento\AsynchronousOperations\Api\Data\OperationSearchResultsInterface" type="Magento\AsynchronousOperations\Model\OperationSearchResults" />
2020
<preference for="Magento\AsynchronousOperations\Api\OperationRepositoryInterface" type="Magento\AsynchronousOperations\Model\OperationRepository" />
21+
<preference for="Magento\AsynchronousOperations\Model\OperationRepositoryInterface" type="Magento\AsynchronousOperations\Model\ResourceModel\Operation\OperationRepository" />
2122
<type name="Magento\Framework\EntityManager\MetadataPool">
2223
<arguments>
2324
<argument name="metadata" xsi:type="array">

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/Block/Product/View.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ public function getQuantityValidators()
323323
*/
324324
public function getIdentities()
325325
{
326-
$identities = $this->getProduct()->getIdentities();
326+
$product = $this->getProduct();
327327

328-
return $identities;
328+
return $product ? $product->getIdentities() : [];
329329
}
330330

331331
/**

app/code/Magento/Catalog/Model/Category/DataProvider.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
* @api
4242
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
4343
* @SuppressWarnings(PHPMD.TooManyFields)
44+
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
4445
* @since 101.0.0
4546
*/
4647
class DataProvider extends ModifierPoolDataProvider
@@ -176,6 +177,10 @@ class DataProvider extends ModifierPoolDataProvider
176177
* @var AuthorizationInterface
177178
*/
178179
private $auth;
180+
/**
181+
* @var Image
182+
*/
183+
private $categoryImage;
179184

180185
/**
181186
* @param string $name
@@ -196,6 +201,7 @@ class DataProvider extends ModifierPoolDataProvider
196201
* @param ScopeOverriddenValue|null $scopeOverriddenValue
197202
* @param ArrayManager|null $arrayManager
198203
* @param FileInfo|null $fileInfo
204+
* @param Image|null $categoryImage
199205
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
200206
*/
201207
public function __construct(
@@ -216,7 +222,8 @@ public function __construct(
216222
?ArrayUtils $arrayUtils = null,
217223
ScopeOverriddenValue $scopeOverriddenValue = null,
218224
ArrayManager $arrayManager = null,
219-
FileInfo $fileInfo = null
225+
FileInfo $fileInfo = null,
226+
?Image $categoryImage = null
220227
) {
221228
$this->eavValidationRules = $eavValidationRules;
222229
$this->collection = $categoryCollectionFactory->create();
@@ -232,6 +239,7 @@ public function __construct(
232239
ObjectManager::getInstance()->get(ScopeOverriddenValue::class);
233240
$this->arrayManager = $arrayManager ?: ObjectManager::getInstance()->get(ArrayManager::class);
234241
$this->fileInfo = $fileInfo ?: ObjectManager::getInstance()->get(FileInfo::class);
242+
$this->categoryImage = $categoryImage ?? ObjectManager::getInstance()->get(Image::class);
235243

236244
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data, $pool);
237245
}
@@ -601,11 +609,7 @@ private function convertValues($category, $categoryData): array
601609
// phpcs:ignore Magento2.Functions.DiscouragedFunction
602610
$categoryData[$attributeCode][0]['name'] = basename($fileName);
603611

604-
if ($this->fileInfo->isBeginsWithMediaDirectoryPath($fileName)) {
605-
$categoryData[$attributeCode][0]['url'] = $fileName;
606-
} else {
607-
$categoryData[$attributeCode][0]['url'] = $category->getImageUrl($attributeCode);
608-
}
612+
$categoryData[$attributeCode][0]['url'] = $this->categoryImage->getUrl($category, $attributeCode);
609613

610614
$categoryData[$attributeCode][0]['size'] = isset($stat) ? $stat['size'] : 0;
611615
$categoryData[$attributeCode][0]['type'] = $mime;

app/code/Magento/Catalog/Model/Category/FileInfo.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,15 @@ private function getMediaDirectoryPathRelativeToBaseDirectoryPath(string $filePa
245245

246246
return $mediaDirectoryRelativeSubpath;
247247
}
248+
249+
/**
250+
* Get file relative path to media directory
251+
*
252+
* @param string $filename
253+
* @return string
254+
*/
255+
public function getRelativePathToMediaDirectory(string $filename): string
256+
{
257+
return $this->getFilePath($filename);
258+
}
248259
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model\Category;
9+
10+
use Magento\Catalog\Model\Category;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\UrlInterface;
13+
use Magento\Store\Model\StoreManagerInterface;
14+
15+
/**
16+
* Category Image Service
17+
*/
18+
class Image
19+
{
20+
private const ATTRIBUTE_NAME = 'image';
21+
/**
22+
* @var FileInfo
23+
*/
24+
private $fileInfo;
25+
/**
26+
* @var StoreManagerInterface
27+
*/
28+
private $storeManager;
29+
30+
/**
31+
* Initialize dependencies.
32+
*
33+
* @param FileInfo $fileInfo
34+
* @param StoreManagerInterface $storeManager
35+
*/
36+
public function __construct(
37+
FileInfo $fileInfo,
38+
StoreManagerInterface $storeManager
39+
) {
40+
$this->fileInfo = $fileInfo;
41+
$this->storeManager = $storeManager;
42+
}
43+
/**
44+
* Resolve category image URL
45+
*
46+
* @param Category $category
47+
* @param string $attributeCode
48+
* @return string
49+
* @throws LocalizedException
50+
*/
51+
public function getUrl(Category $category, string $attributeCode = self::ATTRIBUTE_NAME): string
52+
{
53+
$url = '';
54+
$image = $category->getData($attributeCode);
55+
if ($image) {
56+
if (is_string($image)) {
57+
$store = $this->storeManager->getStore();
58+
$mediaBaseUrl = $store->getBaseUrl(UrlInterface::URL_TYPE_MEDIA);
59+
if ($this->fileInfo->isBeginsWithMediaDirectoryPath($image)) {
60+
$relativePath = $this->fileInfo->getRelativePathToMediaDirectory($image);
61+
$url = rtrim($mediaBaseUrl, '/') . '/' . ltrim($relativePath, '/');
62+
} elseif (substr($image, 0, 1) !== '/') {
63+
$url = rtrim($mediaBaseUrl, '/') . '/' . ltrim(FileInfo::ENTITY_MEDIA_PATH, '/') . '/' . $image;
64+
} else {
65+
$url = $image;
66+
}
67+
} else {
68+
throw new LocalizedException(
69+
__('Something went wrong while getting the image url.')
70+
);
71+
}
72+
}
73+
return $url;
74+
}
75+
}

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/Product/Gallery/GalleryManagement.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public function create($sku, ProductAttributeMediaGalleryEntryInterface $entry)
6161
$existingMediaGalleryEntries = $product->getMediaGalleryEntries();
6262
$existingEntryIds = [];
6363
if ($existingMediaGalleryEntries == null) {
64+
// set all media types if not specified
65+
if ($entry->getTypes() == null) {
66+
$entry->setTypes(array_keys($product->getMediaAttributes()));
67+
}
6468
$existingMediaGalleryEntries = [$entry];
6569
} else {
6670
foreach ($existingMediaGalleryEntries as $existingEntries) {

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;

0 commit comments

Comments
 (0)