Skip to content

Commit c38ae90

Browse files
authored
Merge pull request #1612 from magento-mpi/MPI-PR-2.2.1
[MPI] Bugfixes 2.2.1
2 parents 1b97a2e + e9ab863 commit c38ae90

File tree

17 files changed

+471
-129
lines changed

17 files changed

+471
-129
lines changed

app/code/Magento/Config/Block/System/Config/Form.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Config\App\Config\Type\System;
99
use Magento\Config\Model\Config\Reader\Source\Deployed\SettingChecker;
1010
use Magento\Config\Model\Config\Structure\ElementVisibilityInterface;
11+
use Magento\Framework\App\Config\Data\ProcessorInterface;
1112
use Magento\Framework\App\Config\ScopeConfigInterface;
1213
use Magento\Framework\App\DeploymentConfig;
1314
use Magento\Framework\App\ObjectManager;
@@ -429,6 +430,18 @@ private function getFieldData(\Magento\Config\Model\Config\Structure\Element\Fie
429430
if ($data === null) {
430431
$path = $field->getConfigPath() !== null ? $field->getConfigPath() : $path;
431432
$data = $this->getConfigValue($path);
433+
if ($field->hasBackendModel()) {
434+
$backendModel = $field->getBackendModel();
435+
// Backend models which implement ProcessorInterface are processed by ScopeConfigInterface
436+
if (!$backendModel instanceof ProcessorInterface) {
437+
$backendModel->setPath($path)
438+
->setValue($data)
439+
->setWebsite($this->getWebsiteCode())
440+
->setStore($this->getStoreCode())
441+
->afterLoad();
442+
$data = $backendModel->getValue();
443+
}
444+
}
432445
}
433446

434447
return $data;

app/code/Magento/Config/Model/Config/Backend/Serialized.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
*/
66
namespace Magento\Config\Model\Config\Backend;
77

8-
use Magento\Framework\App\Config\Data\ProcessorInterface;
98
use Magento\Framework\App\ObjectManager;
109
use Magento\Framework\Serialize\Serializer\Json;
1110

1211
/**
1312
* @api
1413
* @since 100.0.2
1514
*/
16-
class Serialized extends \Magento\Framework\App\Config\Value implements ProcessorInterface
15+
class Serialized extends \Magento\Framework\App\Config\Value
1716
{
1817
/**
1918
* @var Json
@@ -68,12 +67,4 @@ public function beforeSave()
6867
parent::beforeSave();
6968
return $this;
7069
}
71-
72-
/**
73-
* @inheritdoc
74-
*/
75-
public function processValue($value)
76-
{
77-
return empty($value) ? '' : $this->serializer->unserialize($value);
78-
}
7970
}

app/code/Magento/Config/Test/Unit/Block/System/Config/FormTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ public function initFieldsDataProvider()
548548
false,
549549
'some_value',
550550
null,
551-
0,
551+
1,
552552
false,
553553
false,
554554
false
@@ -560,7 +560,7 @@ public function initFieldsDataProvider()
560560
true,
561561
'Config Value',
562562
null,
563-
0,
563+
1,
564564
true,
565565
false,
566566
true

app/code/Magento/Customer/Block/Address/Edit.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
*/
66
namespace Magento\Customer\Block\Address;
77

8+
use Magento\Customer\Model\AttributeChecker;
89
use Magento\Framework\Exception\NoSuchEntityException;
10+
use Magento\Framework\App\ObjectManager;
911

1012
/**
1113
* Customer address edit block
@@ -46,6 +48,11 @@ class Edit extends \Magento\Directory\Block\Data
4648
*/
4749
protected $dataObjectHelper;
4850

51+
/**
52+
* @var AttributeChecker
53+
*/
54+
private $attributeChecker;
55+
4956
/**
5057
* Constructor
5158
*
@@ -61,7 +68,7 @@ class Edit extends \Magento\Directory\Block\Data
6168
* @param \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer
6269
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
6370
* @param array $data
64-
*
71+
* @param AttributeChecker $attributeChecker
6572
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6673
*/
6774
public function __construct(
@@ -76,13 +83,16 @@ public function __construct(
7683
\Magento\Customer\Api\Data\AddressInterfaceFactory $addressDataFactory,
7784
\Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer,
7885
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
79-
array $data = []
86+
array $data = [],
87+
AttributeChecker $attributeChecker = null
8088
) {
8189
$this->_customerSession = $customerSession;
8290
$this->_addressRepository = $addressRepository;
8391
$this->addressDataFactory = $addressDataFactory;
8492
$this->currentCustomer = $currentCustomer;
8593
$this->dataObjectHelper = $dataObjectHelper;
94+
$this->attributeChecker = $attributeChecker ?: ObjectManager::getInstance()->get(AttributeChecker::class);
95+
8696
parent::__construct(
8797
$context,
8898
$directoryHelper,
@@ -352,4 +362,16 @@ public function getConfig($path)
352362
{
353363
return $this->_scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
354364
}
365+
366+
/**
367+
* Checks whether it is allowed to show an attribute on the form.
368+
*
369+
* @param string $attributeCode
370+
* @param string $formName
371+
* @return bool
372+
*/
373+
public function isAttributeAllowedOnForm($attributeCode, $formName)
374+
{
375+
return $this->attributeChecker->isAttributeAllowedOnForm($attributeCode, $formName);
376+
}
355377
}

app/code/Magento/Customer/Helper/Address.php

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
use Magento\Customer\Api\AddressMetadataInterface;
99
use Magento\Customer\Api\CustomerMetadataInterface;
1010
use Magento\Customer\Api\Data\AttributeMetadataInterface;
11-
use Magento\Customer\Model\Metadata\AttributeResolver;
1211
use Magento\Directory\Model\Country\Format;
13-
use Magento\Framework\App\ObjectManager;
1412
use Magento\Framework\Exception\NoSuchEntityException;
1513

1614
/**
@@ -95,35 +93,27 @@ class Address extends \Magento\Framework\App\Helper\AbstractHelper
9593
*/
9694
protected $_addressConfig;
9795

98-
/**
99-
* @var AttributeResolver
100-
*/
101-
private $attributeResolver;
102-
10396
/**
10497
* @param \Magento\Framework\App\Helper\Context $context
10598
* @param \Magento\Framework\View\Element\BlockFactory $blockFactory
10699
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
107100
* @param CustomerMetadataInterface $customerMetadataService
108101
* @param AddressMetadataInterface $addressMetadataService
109102
* @param \Magento\Customer\Model\Address\Config $addressConfig
110-
* @param AttributeResolver|null $attributeResolver
111103
*/
112104
public function __construct(
113105
\Magento\Framework\App\Helper\Context $context,
114106
\Magento\Framework\View\Element\BlockFactory $blockFactory,
115107
\Magento\Store\Model\StoreManagerInterface $storeManager,
116108
CustomerMetadataInterface $customerMetadataService,
117109
AddressMetadataInterface $addressMetadataService,
118-
\Magento\Customer\Model\Address\Config $addressConfig,
119-
AttributeResolver $attributeResolver = null
110+
\Magento\Customer\Model\Address\Config $addressConfig
120111
) {
121112
$this->_blockFactory = $blockFactory;
122113
$this->_storeManager = $storeManager;
123114
$this->_customerMetadataService = $customerMetadataService;
124115
$this->_addressMetadataService = $addressMetadataService;
125116
$this->_addressConfig = $addressConfig;
126-
$this->attributeResolver = $attributeResolver ?: ObjectManager::getInstance()->get(AttributeResolver::class);
127117
parent::__construct($context);
128118
}
129119

@@ -401,31 +391,4 @@ public function isAttributeVisible($code)
401391
}
402392
return false;
403393
}
404-
405-
/**
406-
* Checks whether it is allowed to show an attribute on the form
407-
*
408-
* This check relies on the attribute's property 'getUsedInForms' which contains a list of forms
409-
* where allowed to render specified attribute.
410-
*
411-
* @param string $attributeCode
412-
* @param string $formName
413-
* @return bool
414-
*/
415-
public function isAttributeAllowedOnForm($attributeCode, $formName)
416-
{
417-
$isAllowed = false;
418-
$attributeMetadata = $this->_addressMetadataService->getAttributeMetadata($attributeCode);
419-
if ($attributeMetadata) {
420-
/** @var \Magento\Customer\Model\Attribute $attribute */
421-
$attribute = $this->attributeResolver->getModelByAttribute(
422-
\Magento\Customer\Api\AddressMetadataManagementInterface::ENTITY_TYPE_ADDRESS,
423-
$attributeMetadata
424-
);
425-
$usedInForms = $attribute->getUsedInForms();
426-
$isAllowed = in_array($formName, $usedInForms, true);
427-
}
428-
429-
return $isAllowed;
430-
}
431394
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Model;
7+
8+
use Magento\Customer\Api\AddressMetadataInterface;
9+
use Magento\Customer\Api\AddressMetadataManagementInterface;
10+
use Magento\Customer\Model\Metadata\AttributeResolver;
11+
use Magento\Framework\App\Helper\Context;
12+
13+
/**
14+
* Customer attribute checker.
15+
*/
16+
class AttributeChecker
17+
{
18+
/**
19+
* @var AddressMetadataInterface
20+
*/
21+
private $addressMetadata;
22+
23+
/**
24+
* @var AttributeResolver
25+
*/
26+
private $attributeResolver;
27+
28+
/**
29+
* @param AddressMetadataInterface $addressMetadata
30+
* @param AttributeResolver $attributeResolver
31+
*/
32+
public function __construct(
33+
AddressMetadataInterface $addressMetadata,
34+
AttributeResolver $attributeResolver
35+
) {
36+
$this->addressMetadata = $addressMetadata;
37+
$this->attributeResolver = $attributeResolver;
38+
}
39+
40+
/**
41+
* Checks whether it is allowed to show an attribute on the form
42+
*
43+
* This check relies on the attribute's property 'getUsedInForms' which contains a list of forms
44+
* where allowed to render specified attribute.
45+
*
46+
* @param string $attributeCode
47+
* @param string $formName
48+
* @return bool
49+
*/
50+
public function isAttributeAllowedOnForm($attributeCode, $formName)
51+
{
52+
$isAllowed = false;
53+
$attributeMetadata = $this->addressMetadata->getAttributeMetadata($attributeCode);
54+
if ($attributeMetadata) {
55+
/** @var Attribute $attribute */
56+
$attribute = $this->attributeResolver->getModelByAttribute(
57+
AddressMetadataManagementInterface::ENTITY_TYPE_ADDRESS,
58+
$attributeMetadata
59+
);
60+
$usedInForms = $attribute->getUsedInForms();
61+
$isAllowed = in_array($formName, $usedInForms, true);
62+
}
63+
64+
return $isAllowed;
65+
}
66+
}

app/code/Magento/Customer/Test/Unit/Helper/AddressTest.php

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace Magento\Customer\Test\Unit\Helper;
88

99
use Magento\Customer\Api\AddressMetadataInterface;
10-
use Magento\Customer\Api\AddressMetadataManagementInterface;
1110
use Magento\Customer\Api\CustomerMetadataInterface;
1211

1312
/**
@@ -36,9 +35,6 @@ class AddressTest extends \PHPUnit\Framework\TestCase
3635
/** @var \Magento\Customer\Model\Address\Config|\PHPUnit_Framework_MockObject_MockObject */
3736
protected $addressConfig;
3837

39-
/** @var \Magento\Customer\Model\Metadata\AttributeResolver|\PHPUnit_Framework_MockObject_MockObject */
40-
protected $attributeResolver;
41-
4238
/** @var \PHPUnit_Framework_MockObject_MockObject|AddressMetadataInterface */
4339
private $addressMetadataService;
4440

@@ -55,7 +51,6 @@ protected function setUp()
5551
$this->customerMetadataService = $arguments['customerMetadataService'];
5652
$this->addressConfig = $arguments['addressConfig'];
5753
$this->addressMetadataService = $arguments['addressMetadataService'];
58-
$this->attributeResolver = $arguments['attributeResolver'];
5954

6055
$this->helper = $objectManagerHelper->getObject($className, $arguments);
6156
}
@@ -408,68 +403,4 @@ public function isAttributeVisibleDataProvider()
408403
['invalid_code', false],
409404
];
410405
}
411-
412-
/**
413-
* @dataProvider attributeOnFormDataProvider
414-
* @param bool $isAllowed
415-
* @param bool $isMetadataExists
416-
* @param string $attributeCode
417-
* @param string $formName
418-
* @param array $attributeFormsList
419-
*/
420-
public function testIsAttributeAllowedOnForm(
421-
$isAllowed,
422-
$isMetadataExists,
423-
$attributeCode,
424-
$formName,
425-
array $attributeFormsList
426-
) {
427-
$attributeMetadata = null;
428-
if ($isMetadataExists) {
429-
$attributeMetadata = $this->getMockBuilder(\Magento\Customer\Api\Data\AttributeMetadataInterface::class)
430-
->getMockForAbstractClass();
431-
$attribute = $this->getMockBuilder(\Magento\Customer\Model\Attribute::class)
432-
->disableOriginalConstructor()
433-
->getMock();
434-
$this->attributeResolver->expects($this->once())
435-
->method('getModelByAttribute')
436-
->with(AddressMetadataManagementInterface::ENTITY_TYPE_ADDRESS, $attributeMetadata)
437-
->willReturn($attribute);
438-
$attribute->expects($this->once())
439-
->method('getUsedInForms')
440-
->willReturn($attributeFormsList);
441-
}
442-
$this->addressMetadataService->expects($this->once())
443-
->method('getAttributeMetadata')
444-
->with($attributeCode)
445-
->willReturn($attributeMetadata);
446-
$this->assertEquals($isAllowed, $this->helper->isAttributeAllowedOnForm($attributeCode, $formName));
447-
}
448-
449-
public function attributeOnFormDataProvider()
450-
{
451-
return [
452-
'metadata not exists' => [
453-
'isAllowed' => false,
454-
'isMetadataExists' => false,
455-
'attributeCode' => 'attribute_code',
456-
'formName' => 'form_name',
457-
'attributeFormsList' => [],
458-
],
459-
'form not in the list' => [
460-
'isAllowed' => false,
461-
'isMetadataExists' => true,
462-
'attributeCode' => 'attribute_code',
463-
'formName' => 'form_name',
464-
'attributeFormsList' => ['form_1', 'form_2'],
465-
],
466-
'allowed' => [
467-
'isAllowed' => true,
468-
'isMetadataExists' => true,
469-
'attributeCode' => 'attribute_code',
470-
'formName' => 'form_name',
471-
'attributeFormsList' => ['form_name', 'form_1', 'form_2'],
472-
],
473-
];
474-
}
475406
}

0 commit comments

Comments
 (0)