Skip to content

Commit f468817

Browse files
committed
MC-13877: Refactor MAGETWO-91659 fix that does not match BC requirements
1 parent f6876dd commit f468817

File tree

3 files changed

+21
-47
lines changed

3 files changed

+21
-47
lines changed

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

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

8+
use Magento\Framework\Exception\LocalizedException;
89
use Magento\Framework\Exception\NoSuchEntityException;
910

1011
/**
@@ -46,6 +47,11 @@ class Edit extends \Magento\Directory\Block\Data
4647
*/
4748
protected $dataObjectHelper;
4849

50+
/**
51+
* @var \Magento\Customer\Api\AddressMetadataInterface
52+
*/
53+
private $addressMetadata;
54+
4955
/**
5056
* Constructor
5157
*
@@ -61,6 +67,7 @@ class Edit extends \Magento\Directory\Block\Data
6167
* @param \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer
6268
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
6369
* @param array $data
70+
* @param \Magento\Customer\Api\AddressMetadataInterface|null $addressMetadata
6471
*
6572
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6673
*/
@@ -76,13 +83,15 @@ 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+
\Magento\Customer\Api\AddressMetadataInterface $addressMetadata = null
8088
) {
8189
$this->_customerSession = $customerSession;
8290
$this->_addressRepository = $addressRepository;
8391
$this->addressDataFactory = $addressDataFactory;
8492
$this->currentCustomer = $currentCustomer;
8593
$this->dataObjectHelper = $dataObjectHelper;
94+
$this->addressMetadata = $addressMetadata;
8695
parent::__construct(
8796
$context,
8897
$directoryHelper,
@@ -138,7 +147,17 @@ protected function _prepareLayout()
138147
\Magento\Customer\Api\Data\AddressInterface::class
139148
);
140149
}
141-
150+
$precheckAttributes = $this->getData('check_attributes_on_render');
151+
$requiredAttributesPrechecked = [];
152+
if (!empty($precheckAttributes) && is_array($precheckAttributes)) {
153+
foreach ($precheckAttributes as $attributeCode) {
154+
$attributeMetadata = $this->addressMetadata->getAttributeMetadata($attributeCode);
155+
if ($attributeMetadata && $attributeMetadata->isRequired()) {
156+
$requiredAttributesPrechecked[$attributeCode] = $attributeCode;
157+
}
158+
}
159+
}
160+
$this->setData('required_attributed_prechecked', $requiredAttributesPrechecked);
142161
return $this;
143162
}
144163

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -417,23 +417,4 @@ public function isAttributeVisible($code)
417417
}
418418
return false;
419419
}
420-
421-
/**
422-
* Retrieve attribute required
423-
*
424-
* @param string $code
425-
* @return bool
426-
* @throws NoSuchEntityException
427-
* @throws \Magento\Framework\Exception\LocalizedException
428-
*/
429-
public function isAttributeRequired($code)
430-
{
431-
$attributeMetadata = $this->_addressMetadataService->getAttributeMetadata($code);
432-
433-
if ($attributeMetadata) {
434-
return $attributeMetadata->isRequired();
435-
}
436-
437-
return false;
438-
}
439420
}

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

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -415,32 +415,6 @@ public function isAttributeVisibleDataProvider()
415415
];
416416
}
417417

418-
/**
419-
* Test is required filed by attribute code
420-
*
421-
* @param string $attributeCode
422-
* @param bool $isMetadataExists
423-
* @dataProvider isAttributeRequiredDataProvider
424-
* @covers \Magento\Customer\Helper\Address::isAttributeRequired()
425-
* @return void
426-
*/
427-
public function testIsAttributeRequired($attributeCode, $isMetadataExists)
428-
{
429-
$attributeMetadata = null;
430-
if ($isMetadataExists) {
431-
$attributeMetadata = $this->getMockBuilder(\Magento\Customer\Api\Data\AttributeMetadataInterface::class)
432-
->getMockForAbstractClass();
433-
$attributeMetadata->expects($this->once())
434-
->method('isRequired')
435-
->willReturn(true);
436-
}
437-
$this->addressMetadataService->expects($this->once())
438-
->method('getAttributeMetadata')
439-
->with($attributeCode)
440-
->willReturn($attributeMetadata);
441-
$this->assertEquals($isMetadataExists, $this->helper->isAttributeRequired($attributeCode));
442-
}
443-
444418
/**
445419
* Data provider for test testIsAttributeRequire
446420
*

0 commit comments

Comments
 (0)