Skip to content

Commit 3efdf07

Browse files
merge magento/2.3-develop into magento-chaika/MC-19894-19152
2 parents 5341814 + ab19a3d commit 3efdf07

File tree

90 files changed

+2632
-434
lines changed

Some content is hidden

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

90 files changed

+2632
-434
lines changed

app/code/Magento/Authorizenet/Test/Unit/Model/DirectpostTest.php

Lines changed: 340 additions & 250 deletions
Large diffs are not rendered by default.

app/code/Magento/Backend/Model/Locale/Resolver.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
/**
99
* Backend locale model
10+
*
1011
* @api
1112
* @since 100.0.2
13+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1214
*/
1315
class Resolver extends \Magento\Framework\Locale\Resolver
1416
{
@@ -40,7 +42,7 @@ class Resolver extends \Magento\Framework\Locale\Resolver
4042
* @param Manager $localeManager
4143
* @param \Magento\Framework\App\RequestInterface $request
4244
* @param \Magento\Framework\Validator\Locale $localeValidator
43-
* @param null $locale
45+
* @param string|null $locale
4446
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
4547
*/
4648
public function __construct(
@@ -76,7 +78,7 @@ public function setLocale($locale = null)
7678
$sessionLocale = $this->_session->getSessionLocale();
7779
$userLocale = $this->_localeManager->getUserInterfaceLocale();
7880

79-
$localeCodes = array_filter([$forceLocale, $sessionLocale, $userLocale]);
81+
$localeCodes = array_filter([$forceLocale, $locale, $sessionLocale, $userLocale]);
8082

8183
if (count($localeCodes)) {
8284
$locale = reset($localeCodes);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
11+
<entity name="AdminGeneralSetStoreNameConfigData">
12+
<data key="path">general/store_information/name</data>
13+
<data key="value">New Store Information</data>
14+
</entity>
15+
<entity name="AdminGeneralSetStorePhoneConfigData">
16+
<data key="path">general/store_information/phone</data>
17+
</entity>
18+
<entity name="AdminGeneralSetCountryConfigData">
19+
<data key="path">general/store_information/country_id</data>
20+
</entity>
21+
<entity name="AdminGeneralSetCityConfigData">
22+
<data key="path">general/store_information/city</data>
23+
</entity>
24+
<entity name="AdminGeneralSetPostcodeConfigData">
25+
<data key="path">general/store_information/postcode</data>
26+
</entity>
27+
<entity name="AdminGeneralSetStreetAddressConfigData">
28+
<data key="path">general/store_information/street_line1</data>
29+
</entity>
30+
<entity name="AdminGeneralSetStreetAddress2ConfigData">
31+
<data key="path">general/store_information/street_line2</data>
32+
</entity>
33+
</entities>

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

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Model\Category;
79

810
use Magento\Catalog\Api\Data\CategoryInterface;
@@ -20,6 +22,7 @@
2022
use Magento\Framework\Exception\NoSuchEntityException;
2123
use Magento\Framework\Filesystem;
2224
use Magento\Framework\Stdlib\ArrayManager;
25+
use Magento\Framework\Stdlib\ArrayUtils;
2326
use Magento\Store\Model\Store;
2427
use Magento\Store\Model\StoreManagerInterface;
2528
use Magento\Ui\Component\Form\Field;
@@ -28,10 +31,9 @@
2831
use Magento\Framework\AuthorizationInterface;
2932

3033
/**
31-
* Class DataProvider
34+
* Category form data provider.
3235
*
3336
* @api
34-
*
3537
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3638
* @SuppressWarnings(PHPMD.TooManyFields)
3739
* @since 101.0.0
@@ -52,6 +54,7 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
5254

5355
/**
5456
* EAV attribute properties to fetch from meta storage
57+
*
5558
* @var array
5659
* @since 101.0.0
5760
*/
@@ -143,6 +146,11 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
143146
*/
144147
private $arrayManager;
145148

149+
/**
150+
* @var ArrayUtils
151+
*/
152+
private $arrayUtils;
153+
146154
/**
147155
* @var Filesystem
148156
*/
@@ -154,8 +162,6 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
154162
private $auth;
155163

156164
/**
157-
* DataProvider constructor
158-
*
159165
* @param string $name
160166
* @param string $primaryFieldName
161167
* @param string $requestFieldName
@@ -170,6 +176,8 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
170176
* @param array $data
171177
* @param PoolInterface|null $pool
172178
* @param AuthorizationInterface|null $auth
179+
* @param ArrayUtils|null $arrayUtils
180+
* @throws \Magento\Framework\Exception\LocalizedException
173181
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
174182
*/
175183
public function __construct(
@@ -186,7 +194,8 @@ public function __construct(
186194
array $meta = [],
187195
array $data = [],
188196
PoolInterface $pool = null,
189-
?AuthorizationInterface $auth = null
197+
?AuthorizationInterface $auth = null,
198+
?ArrayUtils $arrayUtils = null
190199
) {
191200
$this->eavValidationRules = $eavValidationRules;
192201
$this->collection = $categoryCollectionFactory->create();
@@ -197,6 +206,7 @@ public function __construct(
197206
$this->request = $request;
198207
$this->categoryFactory = $categoryFactory;
199208
$this->auth = $auth ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
209+
$this->arrayUtils = $arrayUtils ?? ObjectManager::getInstance()->get(ArrayUtils::class);
200210

201211
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data, $pool);
202212
}
@@ -226,7 +236,7 @@ public function getMeta()
226236
* @param array $meta
227237
* @return array
228238
*/
229-
private function addUseDefaultValueCheckbox(Category $category, array $meta)
239+
private function addUseDefaultValueCheckbox(Category $category, array $meta): array
230240
{
231241
/** @var EavAttributeInterface $attribute */
232242
foreach ($category->getAttributes() as $attribute) {
@@ -290,7 +300,7 @@ public function prepareMeta($meta)
290300
* @param array $fieldsMeta
291301
* @return array
292302
*/
293-
private function prepareFieldsMeta($fieldsMap, $fieldsMeta)
303+
private function prepareFieldsMeta(array $fieldsMap, array $fieldsMeta): array
294304
{
295305
$canEditDesign = $this->auth->isAllowed('Magento_Catalog::edit_category_design');
296306

@@ -350,6 +360,8 @@ public function getAttributesMeta(Type $entityType)
350360
{
351361
$meta = [];
352362
$attributes = $entityType->getAttributeCollection();
363+
$fields = $this->getFields();
364+
$category = $this->getCurrentCategory();
353365
/* @var EavAttribute $attribute */
354366
foreach ($attributes as $attribute) {
355367
$code = $attribute->getAttributeCode();
@@ -374,6 +386,16 @@ public function getAttributesMeta(Type $entityType)
374386

375387
$meta[$code]['scopeLabel'] = $this->getScopeLabel($attribute);
376388
$meta[$code]['componentType'] = Field::NAME;
389+
390+
// disable fields
391+
if ($category) {
392+
$attributeIsLocked = $category->isLockedAttribute($code);
393+
$meta[$code]['disabled'] = $attributeIsLocked;
394+
$hasUseConfigField = (bool) array_search('use_config.' . $code, $fields, true);
395+
if ($hasUseConfigField && $meta[$code]['disabled']) {
396+
$meta['use_config.' . $code]['disabled'] = true;
397+
}
398+
}
377399
}
378400

379401
$result = [];
@@ -505,7 +527,7 @@ protected function filterFields($categoryData)
505527
* @param array $categoryData
506528
* @return array
507529
*/
508-
private function convertValues($category, $categoryData)
530+
private function convertValues($category, $categoryData): array
509531
{
510532
foreach ($category->getAttributes() as $attributeCode => $attribute) {
511533
if (!isset($categoryData[$attributeCode])) {
@@ -616,13 +638,24 @@ protected function getFieldsMap()
616638
];
617639
}
618640

641+
/**
642+
* Return list of fields names.
643+
*
644+
* @return array
645+
*/
646+
private function getFields(): array
647+
{
648+
$fieldsMap = $this->getFieldsMap();
649+
return $this->arrayUtils->flatten($fieldsMap);
650+
}
651+
619652
/**
620653
* Retrieve scope overridden value
621654
*
622655
* @return ScopeOverriddenValue
623656
* @deprecated 101.1.0
624657
*/
625-
private function getScopeOverriddenValue()
658+
private function getScopeOverriddenValue(): ScopeOverriddenValue
626659
{
627660
if (null === $this->scopeOverriddenValue) {
628661
$this->scopeOverriddenValue = \Magento\Framework\App\ObjectManager::getInstance()->get(
@@ -639,7 +672,7 @@ private function getScopeOverriddenValue()
639672
* @return ArrayManager
640673
* @deprecated 101.1.0
641674
*/
642-
private function getArrayManager()
675+
private function getArrayManager(): ArrayManager
643676
{
644677
if (null === $this->arrayManager) {
645678
$this->arrayManager = \Magento\Framework\App\ObjectManager::getInstance()->get(
@@ -657,7 +690,7 @@ private function getArrayManager()
657690
*
658691
* @deprecated 101.1.0
659692
*/
660-
private function getFileInfo()
693+
private function getFileInfo(): FileInfo
661694
{
662695
if ($this->fileInfo === null) {
663696
$this->fileInfo = ObjectManager::getInstance()->get(FileInfo::class);

app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Model\Product\Gallery;
79

10+
use Magento\Catalog\Api\Data\ProductInterface;
811
use Magento\Framework\App\Filesystem\DirectoryList;
12+
use Magento\Framework\App\ObjectManager;
913
use Magento\Framework\EntityManager\Operation\ExtensionInterface;
1014
use Magento\MediaStorage\Model\File\Uploader as FileUploader;
15+
use Magento\Store\Model\StoreManagerInterface;
1116

1217
/**
1318
* Create handler for catalog product gallery
@@ -74,6 +79,16 @@ class CreateHandler implements ExtensionInterface
7479
*/
7580
private $mediaAttributeCodes;
7681

82+
/**
83+
* @var array
84+
*/
85+
private $imagesGallery;
86+
87+
/**
88+
* @var \Magento\Store\Model\StoreManagerInterface
89+
*/
90+
private $storeManager;
91+
7792
/**
7893
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
7994
* @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository
@@ -82,6 +97,8 @@ class CreateHandler implements ExtensionInterface
8297
* @param \Magento\Catalog\Model\Product\Media\Config $mediaConfig
8398
* @param \Magento\Framework\Filesystem $filesystem
8499
* @param \Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDb
100+
* @param \Magento\Store\Model\StoreManagerInterface|null $storeManager
101+
* @throws \Magento\Framework\Exception\FileSystemException
85102
*/
86103
public function __construct(
87104
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
@@ -90,7 +107,8 @@ public function __construct(
90107
\Magento\Framework\Json\Helper\Data $jsonHelper,
91108
\Magento\Catalog\Model\Product\Media\Config $mediaConfig,
92109
\Magento\Framework\Filesystem $filesystem,
93-
\Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDb
110+
\Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDb,
111+
\Magento\Store\Model\StoreManagerInterface $storeManager = null
94112
) {
95113
$this->metadata = $metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
96114
$this->attributeRepository = $attributeRepository;
@@ -99,6 +117,7 @@ public function __construct(
99117
$this->mediaConfig = $mediaConfig;
100118
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
101119
$this->fileStorageDb = $fileStorageDb;
120+
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
102121
}
103122

104123
/**
@@ -137,6 +156,10 @@ public function execute($product, $arguments = [])
137156

138157
if ($product->getIsDuplicate() != true) {
139158
foreach ($value['images'] as &$image) {
159+
if (!empty($image['removed']) && !$this->canRemoveImage($product, $image['file'])) {
160+
$image['removed'] = '';
161+
}
162+
140163
if (!empty($image['removed'])) {
141164
$clearImages[] = $image['file'];
142165
} elseif (empty($image['value_id'])) {
@@ -152,6 +175,10 @@ public function execute($product, $arguments = [])
152175
// For duplicating we need copy original images.
153176
$duplicate = [];
154177
foreach ($value['images'] as &$image) {
178+
if (!empty($image['removed']) && !$this->canRemoveImage($product, $image['file'])) {
179+
$image['removed'] = '';
180+
}
181+
155182
if (empty($image['value_id']) || !empty($image['removed'])) {
156183
continue;
157184
}
@@ -538,4 +565,46 @@ private function processMediaAttributeLabel(
538565
);
539566
}
540567
}
568+
569+
/**
570+
* Get product images for all stores
571+
*
572+
* @param ProductInterface $product
573+
* @return array
574+
*/
575+
private function getImagesForAllStores(ProductInterface $product)
576+
{
577+
if ($this->imagesGallery === null) {
578+
$storeIds = array_keys($this->storeManager->getStores());
579+
$storeIds[] = 0;
580+
581+
$this->imagesGallery = $this->resourceModel->getProductImages($product, $storeIds);
582+
}
583+
584+
return $this->imagesGallery;
585+
}
586+
587+
/**
588+
* Check possibility to remove image
589+
*
590+
* @param ProductInterface $product
591+
* @param string $imageFile
592+
* @return bool
593+
*/
594+
private function canRemoveImage(ProductInterface $product, string $imageFile) :bool
595+
{
596+
$canRemoveImage = true;
597+
$gallery = $this->getImagesForAllStores($product);
598+
$storeId = $product->getStoreId();
599+
600+
if (!empty($gallery)) {
601+
foreach ($gallery as $image) {
602+
if ($image['filepath'] === $imageFile && (int) $image['store_id'] !== $storeId) {
603+
$canRemoveImage = false;
604+
}
605+
}
606+
}
607+
608+
return $canRemoveImage;
609+
}
541610
}

0 commit comments

Comments
 (0)