Skip to content

Commit 3ef83db

Browse files
Oleksandr_HodzevychOleksandr_Hodzevych
authored andcommitted
MAGETWO-91659: Cannot set Phone Number not required
- Fixed checking is required field telephone
1 parent 5c70bb7 commit 3ef83db

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,4 +391,23 @@ public function isAttributeVisible($code)
391391
}
392392
return false;
393393
}
394+
395+
/**
396+
* Retrieve attribute required
397+
*
398+
* @param string $code
399+
* @return bool
400+
* @throws NoSuchEntityException
401+
* @throws \Magento\Framework\Exception\LocalizedException
402+
*/
403+
public function isAttributeRequired($code)
404+
{
405+
$attributeMetadata = $this->_addressMetadataService->getAttributeMetadata($code);
406+
407+
if ($attributeMetadata) {
408+
return $attributeMetadata->isRequired();
409+
}
410+
411+
return false;
412+
}
394413
}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,43 @@ public function isAttributeVisibleDataProvider()
414414
['invalid_code', false]
415415
];
416416
}
417+
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+
444+
/**
445+
* Data provider for test testIsAttributeRequire
446+
*
447+
* @return array
448+
*/
449+
public function isAttributeRequiredDataProvider()
450+
{
451+
return [
452+
['fax', true],
453+
['invalid_code', false]
454+
];
455+
}
417456
}

app/code/Magento/Customer/view/base/ui_component/customer_form.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,6 @@
486486
</item>
487487
</argument>
488488
<settings>
489-
<validation>
490-
<rule name="required-entry" xsi:type="boolean">true</rule>
491-
</validation>
492489
<dataType>text</dataType>
493490
</settings>
494491
</field>

0 commit comments

Comments
 (0)