Skip to content

Commit be49d90

Browse files
authored
Merge pull request #5460 from magento-tsg-csl3/2.4-develop-pr17
[TSG-CSL3] For 2.4 (pr17)
2 parents 8eb9deb + a544049 commit be49d90

File tree

34 files changed

+1356
-122
lines changed

34 files changed

+1356
-122
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/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/Test/Unit/Model/Category/DataProviderTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Catalog\Model\Category\Attribute\Backend\Image;
1111
use Magento\Catalog\Model\Category\DataProvider;
1212
use Magento\Catalog\Model\Category\FileInfo;
13+
use Magento\Catalog\Model\Category\Image as CategoryImage;
1314
use Magento\Catalog\Model\CategoryFactory;
1415
use Magento\Catalog\Model\ResourceModel\Category\Collection;
1516
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
@@ -98,6 +99,11 @@ class DataProviderTest extends TestCase
9899
*/
99100
private $auth;
100101

102+
/**
103+
* @var CategoryImage|MockObject
104+
*/
105+
private $categoryImage;
106+
101107
/**
102108
* @inheritDoc
103109
*/
@@ -155,6 +161,11 @@ protected function setUp()
155161
$this->arrayUtils = $this->getMockBuilder(ArrayUtils::class)
156162
->setMethods(['flatten'])
157163
->disableOriginalConstructor()->getMock();
164+
165+
$this->categoryImage = $this->createPartialMock(
166+
CategoryImage::class,
167+
['getUrl']
168+
);
158169
}
159170

160171
/**
@@ -185,7 +196,8 @@ private function getModel()
185196
'categoryFactory' => $this->categoryFactory,
186197
'pool' => $this->modifierPool,
187198
'auth' => $this->auth,
188-
'arrayUtils' => $this->arrayUtils
199+
'arrayUtils' => $this->arrayUtils,
200+
'categoryImage' => $this->categoryImage,
189201
]
190202
);
191203

@@ -324,8 +336,8 @@ public function testGetData()
324336
$categoryMock->expects($this->once())
325337
->method('getAttributes')
326338
->willReturn(['image' => $attributeMock]);
327-
$categoryMock->expects($this->once())
328-
->method('getImageUrl')
339+
$this->categoryImage->expects($this->once())
340+
->method('getUrl')
329341
->willReturn($categoryUrl);
330342

331343
$this->registry->expects($this->once())

0 commit comments

Comments
 (0)