Skip to content

Commit 0f6795d

Browse files
author
Bohdan Korablov
committed
Merge remote-tracking branch 'mainline/2.2-develop' into MAGETWO-72477-2
2 parents f866101 + 96f9822 commit 0f6795d

File tree

13 files changed

+252
-27
lines changed

13 files changed

+252
-27
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,11 @@ public function reindex()
10941094
if ($this->flatState->isFlatEnabled()) {
10951095
$flatIndexer = $this->indexerRegistry->get(Indexer\Category\Flat\State::INDEXER_ID);
10961096
if (!$flatIndexer->isScheduled()) {
1097-
$flatIndexer->reindexRow($this->getId());
1097+
$idsList = [$this->getId()];
1098+
if ($this->dataHasChangedFor('url_key')) {
1099+
$idsList = array_merge($idsList, explode(',', $this->getAllChildren()));
1100+
}
1101+
$flatIndexer->reindexList($idsList);
10981102
}
10991103
}
11001104
$productIndexer = $this->indexerRegistry->get(Indexer\Category\Product::INDEXER_ID);

app/code/Magento/Catalog/Test/Unit/Model/CategoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public function testReindexFlatEnabled($flatScheduled, $productScheduled, $expec
318318
->will($this->returnValue(true));
319319

320320
$this->flatIndexer->expects($this->exactly(1))->method('isScheduled')->will($this->returnValue($flatScheduled));
321-
$this->flatIndexer->expects($this->exactly($expectedFlatReindexCalls))->method('reindexRow')->with('123');
321+
$this->flatIndexer->expects($this->exactly($expectedFlatReindexCalls))->method('reindexList')->with(['123']);
322322

323323
$this->productIndexer->expects($this->exactly(1))->method('isScheduled')->will($this->returnValue($productScheduled));
324324
$this->productIndexer->expects($this->exactly($expectedProductReindexCall))->method('reindexList')->with($pathIds);

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
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;
1112
use Magento\Directory\Model\Country\Format;
13+
use Magento\Framework\App\ObjectManager;
1214
use Magento\Framework\Exception\NoSuchEntityException;
1315

1416
/**
@@ -93,27 +95,35 @@ class Address extends \Magento\Framework\App\Helper\AbstractHelper
9395
*/
9496
protected $_addressConfig;
9597

98+
/**
99+
* @var AttributeResolver
100+
*/
101+
private $attributeResolver;
102+
96103
/**
97104
* @param \Magento\Framework\App\Helper\Context $context
98105
* @param \Magento\Framework\View\Element\BlockFactory $blockFactory
99106
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
100107
* @param CustomerMetadataInterface $customerMetadataService
101108
* @param AddressMetadataInterface $addressMetadataService
102109
* @param \Magento\Customer\Model\Address\Config $addressConfig
110+
* @param AttributeResolver|null $attributeResolver
103111
*/
104112
public function __construct(
105113
\Magento\Framework\App\Helper\Context $context,
106114
\Magento\Framework\View\Element\BlockFactory $blockFactory,
107115
\Magento\Store\Model\StoreManagerInterface $storeManager,
108116
CustomerMetadataInterface $customerMetadataService,
109117
AddressMetadataInterface $addressMetadataService,
110-
\Magento\Customer\Model\Address\Config $addressConfig
118+
\Magento\Customer\Model\Address\Config $addressConfig,
119+
AttributeResolver $attributeResolver = null
111120
) {
112121
$this->_blockFactory = $blockFactory;
113122
$this->_storeManager = $storeManager;
114123
$this->_customerMetadataService = $customerMetadataService;
115124
$this->_addressMetadataService = $addressMetadataService;
116125
$this->_addressConfig = $addressConfig;
126+
$this->attributeResolver = $attributeResolver ?: ObjectManager::getInstance()->get(AttributeResolver::class);
117127
parent::__construct($context);
118128
}
119129

@@ -391,4 +401,31 @@ public function isAttributeVisible($code)
391401
}
392402
return false;
393403
}
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+
}
394431
}

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

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

99
use Magento\Customer\Api\AddressMetadataInterface;
10+
use Magento\Customer\Api\AddressMetadataManagementInterface;
1011
use Magento\Customer\Api\CustomerMetadataInterface;
1112

1213
/**
@@ -35,6 +36,9 @@ class AddressTest extends \PHPUnit\Framework\TestCase
3536
/** @var \Magento\Customer\Model\Address\Config|\PHPUnit_Framework_MockObject_MockObject */
3637
protected $addressConfig;
3738

39+
/** @var \Magento\Customer\Model\Metadata\AttributeResolver|\PHPUnit_Framework_MockObject_MockObject */
40+
protected $attributeResolver;
41+
3842
/** @var \PHPUnit_Framework_MockObject_MockObject|AddressMetadataInterface */
3943
private $addressMetadataService;
4044

@@ -51,6 +55,7 @@ protected function setUp()
5155
$this->customerMetadataService = $arguments['customerMetadataService'];
5256
$this->addressConfig = $arguments['addressConfig'];
5357
$this->addressMetadataService = $arguments['addressMetadataService'];
58+
$this->attributeResolver = $arguments['attributeResolver'];
5459

5560
$this->helper = $objectManagerHelper->getObject($className, $arguments);
5661
}
@@ -322,9 +327,11 @@ public function testGetFormatTypeRenderer($code, $result)
322327
$this->addressConfig->expects($this->once())
323328
->method('getFormatByCode')
324329
->with($code)
325-
->will($this->returnValue(
326-
new \Magento\Framework\DataObject($result !== null ? ['renderer' => $result] : [])
327-
));
330+
->will(
331+
$this->returnValue(
332+
new \Magento\Framework\DataObject($result !== null ? ['renderer' => $result] : [])
333+
)
334+
);
328335
$this->assertEquals($result, $this->helper->getFormatTypeRenderer($code));
329336
}
330337

@@ -334,7 +341,7 @@ public function getFormatTypeRendererDataProvider()
334341
->disableOriginalConstructor()->getMock();
335342
return [
336343
['valid_code', $renderer],
337-
['invalid_code', null]
344+
['invalid_code', null],
338345
];
339346
}
340347

@@ -355,9 +362,11 @@ public function testGetFormat($code, $result)
355362
$this->addressConfig->expects($this->once())
356363
->method('getFormatByCode')
357364
->with($code)
358-
->will($this->returnValue(
359-
new \Magento\Framework\DataObject(!empty($result) ? ['renderer' => $renderer] : [])
360-
));
365+
->will(
366+
$this->returnValue(
367+
new \Magento\Framework\DataObject(!empty($result) ? ['renderer' => $renderer] : [])
368+
)
369+
);
361370

362371
$this->assertEquals($result, $this->helper->getFormat($code));
363372
}
@@ -366,7 +375,7 @@ public function getFormatDataProvider()
366375
{
367376
return [
368377
['valid_code', ['key' => 'value']],
369-
['invalid_code', '']
378+
['invalid_code', ''],
370379
];
371380
}
372381

@@ -396,7 +405,71 @@ public function isAttributeVisibleDataProvider()
396405
{
397406
return [
398407
['fax', true],
399-
['invalid_code', false]
408+
['invalid_code', false],
409+
];
410+
}
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+
],
400473
];
401474
}
402475
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Swagger\Block;
7+
8+
use Magento\Framework\View\Element\Template;
9+
10+
/**
11+
* Class Index
12+
*
13+
* @api
14+
*/
15+
class Index extends Template
16+
{
17+
/**
18+
* @return mixed|string
19+
*/
20+
private function getParamStore()
21+
{
22+
return ($this->getRequest()->getParam('store')) ? $this->getRequest()->getParam('store') : 'all';
23+
}
24+
25+
/**
26+
* @return string
27+
*/
28+
public function getSchemaUrl()
29+
{
30+
return rtrim($this->getBaseUrl(), '/') . '/rest/' . $this->getParamStore() . '/schema?services=all';
31+
}
32+
}

app/code/Magento/Swagger/view/frontend/layout/swagger_index_index.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<referenceContainer name="page.wrapper" remove="true"/>
4646
<referenceBlock name="requirejs-config" remove="true"/>
4747
<referenceContainer name="root">
48-
<block name="swaggerUiContent" class="Magento\Framework\View\Element\Template" template="Magento_Swagger::swagger-ui/index.phtml"/>
48+
<block name="swaggerUiContent" class="Magento\Swagger\Block\Index" template="Magento_Swagger::swagger-ui/index.phtml"/>
4949
</referenceContainer>
5050
</body>
5151
</page>

app/code/Magento/Swagger/view/frontend/templates/swagger-ui/index.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
/** @var \Magento\Framework\View\Element\Template $block */
1616

17-
$schemaUrl = rtrim($block->getBaseUrl(), '/') . '/rest/all/schema?services=all';
17+
$schemaUrl = $block->getSchemaUrl();
1818
?>
1919

2020
<div id='header'>

app/code/Magento/Theme/Model/Design/Config/Validator.php

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,8 @@ public function validate(DesignConfigInterface $designConfig)
6464
}
6565

6666
foreach ($elements as $name => $data) {
67-
// Load template object by configured template id
68-
$template = $this->templateFactory->create();
69-
$template->emulateDesign($designConfig->getScopeId());
7067
$templateId = $data['value'];
71-
if (is_numeric($templateId)) {
72-
$template->load($templateId);
73-
} else {
74-
$template->loadDefault($templateId);
75-
}
76-
$text = $template->getTemplateText();
77-
$template->revertDesign();
68+
$text = $this->getTemplateText($templateId, $designConfig);
7869
// Check if template body has a reference to the same config path
7970
if (preg_match_all(Template::CONSTRUCTION_TEMPLATE_PATTERN, $text, $constructions, PREG_SET_ORDER)) {
8071
foreach ($constructions as $construction) {
@@ -94,6 +85,42 @@ public function validate(DesignConfigInterface $designConfig)
9485
}
9586
}
9687

88+
/**
89+
* Returns store identifier if is store scope
90+
*
91+
* @param DesignConfigInterface $designConfig
92+
* @return string|bool
93+
*/
94+
private function getScopeId(DesignConfigInterface $designConfig)
95+
{
96+
if ($designConfig->getScope() == 'stores') {
97+
return $designConfig->getScopeId();
98+
}
99+
return false;
100+
}
101+
102+
/**
103+
* Load template text in configured scope
104+
*
105+
* @param integer|string $templateId
106+
* @param DesignConfigInterface $designConfig
107+
* @return string
108+
*/
109+
private function getTemplateText($templateId, DesignConfigInterface $designConfig)
110+
{
111+
// Load template object by configured template id
112+
$template = $this->templateFactory->create();
113+
$template->emulateDesign($this->getScopeId($designConfig));
114+
if (is_numeric($templateId)) {
115+
$template->load($templateId);
116+
} else {
117+
$template->loadDefault($templateId);
118+
}
119+
$text = $template->getTemplateText();
120+
$template->revertDesign();
121+
return $text;
122+
}
123+
97124
/**
98125
* Return associative array of parameters.
99126
*

dev/tests/functional/tests/app/Magento/Customer/Test/Block/Address/Edit.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ class Edit extends Form
3030
*/
3131
protected $vatFieldId = 'vat_id';
3232

33+
/**
34+
* Locator for address simple (input, textarea, not multiple fields) attribute
35+
*
36+
* @var string
37+
*/
38+
private $addressSimpleAttribute = "[name='%s']";
39+
3340
/**
3441
* Edit customer address
3542
*
@@ -77,4 +84,15 @@ protected function dataMapping(array $fields = null, $parent = null)
7784
}
7885
return parent::dataMapping($fields, $parent);
7986
}
87+
88+
/**
89+
* Check if Customer Address Simple(input, textarea, not multiple fields) Attribute visible
90+
*
91+
* @param string $attributeCode
92+
* @return bool
93+
*/
94+
public function isAddressSimpleAttributeVisible($attributeCode)
95+
{
96+
return $this->_rootElement->find(sprintf($this->addressSimpleAttribute, $attributeCode))->isVisible();
97+
}
8098
}

0 commit comments

Comments
 (0)