Skip to content

Commit 43fb133

Browse files
Merge branch '2.4-develop' into 2.4-dev
2 parents 88f63a6 + 3c3c8ed commit 43fb133

File tree

205 files changed

+6609
-929
lines changed

Some content is hidden

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

205 files changed

+6609
-929
lines changed

app/code/Magento/Bundle/view/adminhtml/ui_component/bundle_product_listing.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<label translate="true">Status</label>
5959
<dataScope>status</dataScope>
6060
<imports>
61-
<link name="visible">componentType = column, index = ${ $.index }:visible</link>
61+
<link name="visible">ns = ${ $.ns }, index = ${ $.index }:visible</link>
6262
</imports>
6363
</settings>
6464
</filterSelect>

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Catalog\Controller\Adminhtml\Product\Initialization;
88

99
use Magento\Backend\Helper\Js;
10+
use Magento\Catalog\Api\Data\CategoryLinkInterfaceFactory;
1011
use Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory as CustomOptionFactory;
1112
use Magento\Catalog\Api\Data\ProductLinkInterfaceFactory as ProductLinkFactory;
1213
use Magento\Catalog\Api\Data\ProductLinkTypeInterface;
@@ -115,6 +116,11 @@ class Helper
115116
*/
116117
private $dateTimeFilter;
117118

119+
/**
120+
* @var CategoryLinkInterfaceFactory
121+
*/
122+
private $categoryLinkFactory;
123+
118124
/**
119125
* Constructor
120126
*
@@ -132,6 +138,7 @@ class Helper
132138
* @param FormatInterface|null $localeFormat
133139
* @param ProductAuthorization|null $productAuthorization
134140
* @param DateTimeFilter|null $dateTimeFilter
141+
* @param CategoryLinkInterfaceFactory|null $categoryLinkFactory
135142
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
136143
*/
137144
public function __construct(
@@ -148,7 +155,8 @@ public function __construct(
148155
AttributeFilter $attributeFilter = null,
149156
FormatInterface $localeFormat = null,
150157
?ProductAuthorization $productAuthorization = null,
151-
?DateTimeFilter $dateTimeFilter = null
158+
?DateTimeFilter $dateTimeFilter = null,
159+
?CategoryLinkInterfaceFactory $categoryLinkFactory = null
152160
) {
153161
$this->request = $request;
154162
$this->storeManager = $storeManager;
@@ -166,6 +174,7 @@ public function __construct(
166174
$this->localeFormat = $localeFormat ?: $objectManager->get(FormatInterface::class);
167175
$this->productAuthorization = $productAuthorization ?? $objectManager->get(ProductAuthorization::class);
168176
$this->dateTimeFilter = $dateTimeFilter ?? $objectManager->get(DateTimeFilter::class);
177+
$this->categoryLinkFactory = $categoryLinkFactory ?? $objectManager->get(CategoryLinkInterfaceFactory::class);
169178
}
170179

171180
/**
@@ -238,6 +247,7 @@ public function initializeFromData(Product $product, array $productData)
238247

239248
$product = $this->setProductLinks($product);
240249
$product = $this->fillProductOptions($product, $productOptions);
250+
$this->setCategoryLinks($product);
241251

242252
$product->setCanSaveCustomOptions(
243253
!empty($productData['affect_product_custom_options']) && !$product->getOptionsReadonly()
@@ -484,4 +494,30 @@ function ($valueData) {
484494

485495
return $product->setOptions($customOptions);
486496
}
497+
498+
/**
499+
* Set category links based on initialized category ids
500+
*
501+
* @param Product $product
502+
*/
503+
private function setCategoryLinks(Product $product): void
504+
{
505+
$extensionAttributes = $product->getExtensionAttributes();
506+
$categoryLinks = [];
507+
foreach ((array) $extensionAttributes->getCategoryLinks() as $categoryLink) {
508+
$categoryLinks[$categoryLink->getCategoryId()] = $categoryLink;
509+
}
510+
511+
$newCategoryLinks = [];
512+
foreach ($product->getCategoryIds() as $categoryId) {
513+
$categoryLink = $categoryLinks[$categoryId] ??
514+
$this->categoryLinkFactory->create()
515+
->setCategoryId($categoryId)
516+
->setPosition(0);
517+
$newCategoryLinks[] = $categoryLink;
518+
}
519+
520+
$extensionAttributes->setCategoryLinks(!empty($newCategoryLinks) ? $newCategoryLinks : null);
521+
$product->setExtensionAttributes($extensionAttributes);
522+
}
487523
}

app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
use Magento\Framework\App\Request\DataPersistorInterface;
1616

1717
/**
18-
* Class Save
18+
* Product save controller
19+
*
1920
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2021
*/
2122
class Save extends \Magento\Catalog\Controller\Adminhtml\Product implements HttpPostActionInterface
@@ -141,10 +142,6 @@ public function execute()
141142
$canSaveCustomOptions = $product->getCanSaveCustomOptions();
142143
$product->save();
143144
$this->handleImageRemoveError($data, $product->getId());
144-
$this->categoryLinkManagement->assignProductToCategories(
145-
$product->getSku(),
146-
$product->getCategoryIds()
147-
);
148145
$productId = $product->getEntityId();
149146
$productAttributeSetId = $product->getAttributeSetId();
150147
$productTypeId = $product->getTypeId();

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

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,114 +5,116 @@
55
*/
66
namespace Magento\Catalog\Model;
77

8+
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Framework\Exception\LocalizedException;
810
use Magento\Framework\File\Uploader;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\File\Name;
13+
use Magento\Framework\Filesystem;
14+
use Magento\Framework\Filesystem\Directory\WriteInterface;
15+
use Magento\MediaStorage\Helper\File\Storage\Database;
16+
use Magento\MediaStorage\Model\File\UploaderFactory;
17+
use Magento\Store\Model\StoreManagerInterface;
18+
use Psr\Log\LoggerInterface;
919

1020
/**
1121
* Catalog image uploader
1222
*/
1323
class ImageUploader
1424
{
1525
/**
16-
* Core file storage database
17-
*
18-
* @var \Magento\MediaStorage\Helper\File\Storage\Database
26+
* @var Database
1927
*/
2028
protected $coreFileStorageDatabase;
2129

2230
/**
23-
* Media directory object (writable).
24-
*
25-
* @var \Magento\Framework\Filesystem\Directory\WriteInterface
31+
* @var WriteInterface
2632
*/
2733
protected $mediaDirectory;
2834

2935
/**
30-
* Uploader factory
31-
*
32-
* @var \Magento\MediaStorage\Model\File\UploaderFactory
36+
* @var UploaderFactory
3337
*/
3438
private $uploaderFactory;
3539

3640
/**
37-
* Store manager
38-
*
39-
* @var \Magento\Store\Model\StoreManagerInterface
41+
* @var StoreManagerInterface
4042
*/
4143
protected $storeManager;
4244

4345
/**
44-
* @var \Psr\Log\LoggerInterface
46+
* @var LoggerInterface
4547
*/
4648
protected $logger;
4749

4850
/**
49-
* Base tmp path
50-
*
5151
* @var string
5252
*/
5353
protected $baseTmpPath;
5454

5555
/**
56-
* Base path
57-
*
5856
* @var string
5957
*/
6058
protected $basePath;
6159

6260
/**
63-
* Allowed extensions
64-
*
6561
* @var string
6662
*/
6763
protected $allowedExtensions;
6864

6965
/**
70-
* List of allowed image mime types
71-
*
7266
* @var string[]
7367
*/
7468
private $allowedMimeTypes;
7569

7670
/**
77-
* ImageUploader constructor
71+
* @var Name
72+
*/
73+
private $fileNameLookup;
74+
75+
/**
76+
* ImageUploader constructor.
7877
*
79-
* @param \Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase
80-
* @param \Magento\Framework\Filesystem $filesystem
81-
* @param \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory
82-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
83-
* @param \Psr\Log\LoggerInterface $logger
78+
* @param Database $coreFileStorageDatabase
79+
* @param Filesystem $filesystem
80+
* @param UploaderFactory $uploaderFactory
81+
* @param StoreManagerInterface $storeManager
82+
* @param LoggerInterface $logger
8483
* @param string $baseTmpPath
8584
* @param string $basePath
8685
* @param string[] $allowedExtensions
8786
* @param string[] $allowedMimeTypes
87+
* @param Name|null $fileNameLookup
88+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8889
*/
8990
public function __construct(
90-
\Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase,
91-
\Magento\Framework\Filesystem $filesystem,
92-
\Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory,
93-
\Magento\Store\Model\StoreManagerInterface $storeManager,
94-
\Psr\Log\LoggerInterface $logger,
91+
Database $coreFileStorageDatabase,
92+
Filesystem $filesystem,
93+
UploaderFactory $uploaderFactory,
94+
StoreManagerInterface $storeManager,
95+
LoggerInterface $logger,
9596
$baseTmpPath,
9697
$basePath,
9798
$allowedExtensions,
98-
$allowedMimeTypes = []
99+
$allowedMimeTypes = [],
100+
Name $fileNameLookup = null
99101
) {
100102
$this->coreFileStorageDatabase = $coreFileStorageDatabase;
101-
$this->mediaDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA);
103+
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
102104
$this->uploaderFactory = $uploaderFactory;
103105
$this->storeManager = $storeManager;
104106
$this->logger = $logger;
105107
$this->baseTmpPath = $baseTmpPath;
106108
$this->basePath = $basePath;
107109
$this->allowedExtensions = $allowedExtensions;
108110
$this->allowedMimeTypes = $allowedMimeTypes;
111+
$this->fileNameLookup = $fileNameLookup ?? ObjectManager::getInstance()->get(Name::class);
109112
}
110113

111114
/**
112115
* Set base tmp path
113116
*
114117
* @param string $baseTmpPath
115-
*
116118
* @return void
117119
*/
118120
public function setBaseTmpPath($baseTmpPath)
@@ -124,7 +126,6 @@ public function setBaseTmpPath($baseTmpPath)
124126
* Set base path
125127
*
126128
* @param string $basePath
127-
*
128129
* @return void
129130
*/
130131
public function setBasePath($basePath)
@@ -136,7 +137,6 @@ public function setBasePath($basePath)
136137
* Set allowed extensions
137138
*
138139
* @param string[] $allowedExtensions
139-
*
140140
* @return void
141141
*/
142142
public function setAllowedExtensions($allowedExtensions)
@@ -179,7 +179,6 @@ public function getAllowedExtensions()
179179
*
180180
* @param string $path
181181
* @param string $imageName
182-
*
183182
* @return string
184183
*/
185184
public function getFilePath($path, $imageName)
@@ -194,7 +193,7 @@ public function getFilePath($path, $imageName)
194193
* @param bool $returnRelativePath
195194
* @return string
196195
*
197-
* @throws \Magento\Framework\Exception\LocalizedException
196+
* @throws LocalizedException
198197
*/
199198
public function moveFileFromTmp($imageName, $returnRelativePath = false)
200199
{
@@ -203,7 +202,7 @@ public function moveFileFromTmp($imageName, $returnRelativePath = false)
203202

204203
$baseImagePath = $this->getFilePath(
205204
$basePath,
206-
Uploader::getNewFileName(
205+
$this->fileNameLookup->getNewFileName(
207206
$this->mediaDirectory->getAbsolutePath(
208207
$this->getFilePath($basePath, $imageName)
209208
)
@@ -222,10 +221,7 @@ public function moveFileFromTmp($imageName, $returnRelativePath = false)
222221
);
223222
} catch (\Exception $e) {
224223
$this->logger->critical($e);
225-
throw new \Magento\Framework\Exception\LocalizedException(
226-
__('Something went wrong while saving the file(s).'),
227-
$e
228-
);
224+
throw new LocalizedException(__('Something went wrong while saving the file(s).'), $e);
229225
}
230226

231227
return $returnRelativePath ? $baseImagePath : $imageName;
@@ -235,10 +231,9 @@ public function moveFileFromTmp($imageName, $returnRelativePath = false)
235231
* Checking file for save and save it to tmp dir
236232
*
237233
* @param string $fileId
238-
*
239234
* @return string[]
240235
*
241-
* @throws \Magento\Framework\Exception\LocalizedException
236+
* @throws LocalizedException
242237
*/
243238
public function saveFileToTmpDir($fileId)
244239
{
@@ -249,15 +244,13 @@ public function saveFileToTmpDir($fileId)
249244
$uploader->setAllowedExtensions($this->getAllowedExtensions());
250245
$uploader->setAllowRenameFiles(true);
251246
if (!$uploader->checkMimeType($this->allowedMimeTypes)) {
252-
throw new \Magento\Framework\Exception\LocalizedException(__('File validation failed.'));
247+
throw new LocalizedException(__('File validation failed.'));
253248
}
254249
$result = $uploader->save($this->mediaDirectory->getAbsolutePath($baseTmpPath));
255250
unset($result['path']);
256251

257252
if (!$result) {
258-
throw new \Magento\Framework\Exception\LocalizedException(
259-
__('File can not be saved to the destination folder.')
260-
);
253+
throw new LocalizedException(__('File can not be saved to the destination folder.'));
261254
}
262255

263256
/**
@@ -277,7 +270,7 @@ public function saveFileToTmpDir($fileId)
277270
$this->coreFileStorageDatabase->saveFile($relativePath);
278271
} catch (\Exception $e) {
279272
$this->logger->critical($e);
280-
throw new \Magento\Framework\Exception\LocalizedException(
273+
throw new LocalizedException(
281274
__('Something went wrong while saving the file(s).'),
282275
$e
283276
);

0 commit comments

Comments
 (0)