Skip to content

Commit 4ef4824

Browse files
Merge remote-tracking branch 'remotes/github/MAGETWO-95819' into EPAM-PR-33
2 parents 1d41678 + 37c429c commit 4ef4824

File tree

15 files changed

+140
-34
lines changed

15 files changed

+140
-34
lines changed

app/code/Magento/Cms/Test/Mftf/Section/StorefrontHeaderSection.xml

Lines changed: 0 additions & 13 deletions
This file was deleted.

app/code/Magento/Customer/Block/Widget/Dob.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct(
6161
}
6262

6363
/**
64-
* @return void
64+
* @inheritdoc
6565
*/
6666
public function _construct()
6767
{
@@ -70,6 +70,8 @@ public function _construct()
7070
}
7171

7272
/**
73+
* Check if dob attribute enabled in system
74+
*
7375
* @return bool
7476
*/
7577
public function isEnabled()
@@ -79,6 +81,8 @@ public function isEnabled()
7981
}
8082

8183
/**
84+
* Check if dob attribute marked as required
85+
*
8286
* @return bool
8387
*/
8488
public function isRequired()
@@ -88,6 +92,8 @@ public function isRequired()
8892
}
8993

9094
/**
95+
* Set date
96+
*
9197
* @param string $date
9298
* @return $this
9399
*/
@@ -135,6 +141,8 @@ protected function applyOutputFilter($value)
135141
}
136142

137143
/**
144+
* Get day
145+
*
138146
* @return string|bool
139147
*/
140148
public function getDay()
@@ -143,6 +151,8 @@ public function getDay()
143151
}
144152

145153
/**
154+
* Get month
155+
*
146156
* @return string|bool
147157
*/
148158
public function getMonth()
@@ -151,6 +161,8 @@ public function getMonth()
151161
}
152162

153163
/**
164+
* Get year
165+
*
154166
* @return string|bool
155167
*/
156168
public function getYear()
@@ -168,6 +180,19 @@ public function getLabel()
168180
return __('Date of Birth');
169181
}
170182

183+
/**
184+
* Retrieve store attribute label
185+
*
186+
* @param string $attributeCode
187+
*
188+
* @return string
189+
*/
190+
public function getStoreLabel($attributeCode)
191+
{
192+
$attribute = $this->_getAttribute($attributeCode);
193+
return $attribute ? __($attribute->getStoreLabel()) : '';
194+
}
195+
171196
/**
172197
* Create correct date field
173198
*

app/code/Magento/Customer/Block/Widget/Gender.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function _construct()
6464

6565
/**
6666
* Check if gender attribute enabled in system
67+
*
6768
* @return bool
6869
*/
6970
public function isEnabled()
@@ -73,13 +74,27 @@ public function isEnabled()
7374

7475
/**
7576
* Check if gender attribute marked as required
77+
*
7678
* @return bool
7779
*/
7880
public function isRequired()
7981
{
8082
return $this->_getAttribute('gender') ? (bool)$this->_getAttribute('gender')->isRequired() : false;
8183
}
8284

85+
/**
86+
* Retrieve store attribute label
87+
*
88+
* @param string $attributeCode
89+
*
90+
* @return string
91+
*/
92+
public function getStoreLabel($attributeCode)
93+
{
94+
$attribute = $this->_getAttribute($attributeCode);
95+
return $attribute ? __($attribute->getStoreLabel()) : '';
96+
}
97+
8398
/**
8499
* Get current customer from session
85100
*
@@ -92,6 +107,7 @@ public function getCustomer()
92107

93108
/**
94109
* Returns options from gender attribute
110+
*
95111
* @return OptionInterface[]
96112
*/
97113
public function getGenderOptions()

app/code/Magento/Customer/Block/Widget/Taxvat.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,17 @@ public function isRequired()
6363
{
6464
return $this->_getAttribute('taxvat') ? (bool)$this->_getAttribute('taxvat')->isRequired() : false;
6565
}
66+
67+
/**
68+
* Retrieve store attribute label
69+
*
70+
* @param string $attributeCode
71+
*
72+
* @return string
73+
*/
74+
public function getStoreLabel($attributeCode)
75+
{
76+
$attribute = $this->_getAttribute($attributeCode);
77+
return $attribute ? __($attribute->getStoreLabel()) : '';
78+
}
6679
}

app/code/Magento/Customer/Model/Metadata/AttributeMetadataCache.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\App\Cache\StateInterface;
1313
use Magento\Framework\App\CacheInterface;
1414
use Magento\Framework\Serialize\SerializerInterface;
15+
use Magento\Store\Model\StoreManagerInterface;
1516

1617
/**
1718
* Cache for attribute metadata
@@ -53,24 +54,33 @@ class AttributeMetadataCache
5354
*/
5455
private $serializer;
5556

57+
/**
58+
* @var StoreManagerInterface
59+
*/
60+
private $storeManager;
61+
5662
/**
5763
* Constructor
5864
*
5965
* @param CacheInterface $cache
6066
* @param StateInterface $state
6167
* @param SerializerInterface $serializer
6268
* @param AttributeMetadataHydrator $attributeMetadataHydrator
69+
* @param StoreManagerInterface $storeManager
6370
*/
6471
public function __construct(
6572
CacheInterface $cache,
6673
StateInterface $state,
6774
SerializerInterface $serializer,
68-
AttributeMetadataHydrator $attributeMetadataHydrator
75+
AttributeMetadataHydrator $attributeMetadataHydrator,
76+
StoreManagerInterface $storeManager = null
6977
) {
7078
$this->cache = $cache;
7179
$this->state = $state;
7280
$this->serializer = $serializer;
7381
$this->attributeMetadataHydrator = $attributeMetadataHydrator;
82+
$this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance()
83+
->get(StoreManagerInterface::class);
7484
}
7585

7686
/**
@@ -82,19 +92,20 @@ public function __construct(
8292
*/
8393
public function load($entityType, $suffix = '')
8494
{
85-
if (isset($this->attributes[$entityType . $suffix])) {
86-
return $this->attributes[$entityType . $suffix];
95+
$storeId = $this->storeManager->getStore()->getId();
96+
if (isset($this->attributes[$entityType . $suffix . $storeId])) {
97+
return $this->attributes[$entityType . $suffix . $storeId];
8798
}
8899
if ($this->isEnabled()) {
89-
$cacheKey = self::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix;
100+
$cacheKey = self::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix . $storeId;
90101
$serializedData = $this->cache->load($cacheKey);
91102
if ($serializedData) {
92103
$attributesData = $this->serializer->unserialize($serializedData);
93104
$attributes = [];
94105
foreach ($attributesData as $key => $attributeData) {
95106
$attributes[$key] = $this->attributeMetadataHydrator->hydrate($attributeData);
96107
}
97-
$this->attributes[$entityType . $suffix] = $attributes;
108+
$this->attributes[$entityType . $suffix . $storeId] = $attributes;
98109
return $attributes;
99110
}
100111
}
@@ -111,9 +122,10 @@ public function load($entityType, $suffix = '')
111122
*/
112123
public function save($entityType, array $attributes, $suffix = '')
113124
{
114-
$this->attributes[$entityType . $suffix] = $attributes;
125+
$storeId = $this->storeManager->getStore()->getId();
126+
$this->attributes[$entityType . $suffix . $storeId] = $attributes;
115127
if ($this->isEnabled()) {
116-
$cacheKey = self::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix;
128+
$cacheKey = self::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix . $storeId;
117129
$attributesData = [];
118130
foreach ($attributes as $key => $attribute) {
119131
$attributesData[$key] = $this->attributeMetadataHydrator->extract($attribute);

app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerCreateFormSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<section name="StorefrontCustomerCreateFormSection">
1212
<element name="firstnameField" type="input" selector="#firstname"/>
1313
<element name="lastnameField" type="input" selector="#lastname"/>
14+
<element name="lastnameLabel" type="text" selector="//label[@for='lastname']"/>
1415
<element name="emailField" type="input" selector="#email_address"/>
1516
<element name="passwordField" type="input" selector="#password"/>
1617
<element name="confirmPasswordField" type="input" selector="#password-confirmation"/>

app/code/Magento/Customer/Test/Unit/Model/Metadata/AttributeMetadataCacheTest.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
use Magento\Framework\App\CacheInterface;
1616
use Magento\Framework\Serialize\SerializerInterface;
1717
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
18+
use Magento\Store\Api\Data\StoreInterface;
19+
use Magento\Store\Model\StoreManagerInterface;
1820

21+
/**
22+
* AttributeMetadataCache Test
23+
*
24+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
25+
*/
1926
class AttributeMetadataCacheTest extends \PHPUnit\Framework\TestCase
2027
{
2128
/**
@@ -43,20 +50,35 @@ class AttributeMetadataCacheTest extends \PHPUnit\Framework\TestCase
4350
*/
4451
private $attributeMetadataCache;
4552

53+
/**
54+
* @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject
55+
*/
56+
private $storeMock;
57+
58+
/**
59+
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
60+
*/
61+
private $storeManagerMock;
62+
4663
protected function setUp()
4764
{
4865
$objectManager = new ObjectManager($this);
4966
$this->cacheMock = $this->createMock(CacheInterface::class);
5067
$this->stateMock = $this->createMock(StateInterface::class);
5168
$this->serializerMock = $this->createMock(SerializerInterface::class);
5269
$this->attributeMetadataHydratorMock = $this->createMock(AttributeMetadataHydrator::class);
70+
$this->storeMock = $this->createMock(StoreInterface::class);
71+
$this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
72+
$this->storeManagerMock->method('getStore')->willReturn($this->storeMock);
73+
$this->storeMock->method('getId')->willReturn(1);
5374
$this->attributeMetadataCache = $objectManager->getObject(
5475
AttributeMetadataCache::class,
5576
[
5677
'cache' => $this->cacheMock,
5778
'state' => $this->stateMock,
5879
'serializer' => $this->serializerMock,
59-
'attributeMetadataHydrator' => $this->attributeMetadataHydratorMock
80+
'attributeMetadataHydrator' => $this->attributeMetadataHydratorMock,
81+
'storeManager' => $this->storeManagerMock
6082
]
6183
);
6284
}
@@ -80,7 +102,8 @@ public function testLoadNoCache()
80102
{
81103
$entityType = 'EntityType';
82104
$suffix = 'none';
83-
$cacheKey = AttributeMetadataCache::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix;
105+
$storeId = 1;
106+
$cacheKey = AttributeMetadataCache::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix . $storeId;
84107
$this->stateMock->expects($this->once())
85108
->method('isEnabled')
86109
->with(Type::TYPE_IDENTIFIER)
@@ -96,7 +119,8 @@ public function testLoad()
96119
{
97120
$entityType = 'EntityType';
98121
$suffix = 'none';
99-
$cacheKey = AttributeMetadataCache::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix;
122+
$storeId = 1;
123+
$cacheKey = AttributeMetadataCache::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix . $storeId;
100124
$serializedString = 'serialized string';
101125
$attributeMetadataOneData = [
102126
'attribute_code' => 'attribute_code',
@@ -156,7 +180,8 @@ public function testSave()
156180
{
157181
$entityType = 'EntityType';
158182
$suffix = 'none';
159-
$cacheKey = AttributeMetadataCache::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix;
183+
$storeId = 1;
184+
$cacheKey = AttributeMetadataCache::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix . $storeId;
160185
$serializedString = 'serialized string';
161186
$attributeMetadataOneData = [
162187
'attribute_code' => 'attribute_code',

app/code/Magento/Customer/view/frontend/templates/widget/dob.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ $fieldCssClass = 'field date field-' . $block->getHtmlId();
2929
$fieldCssClass .= $block->isRequired() ? ' required' : '';
3030
?>
3131
<div class="<?= $block->escapeHtmlAttr($fieldCssClass) ?>">
32-
<label class="label" for="<?= $block->escapeHtmlAttr($block->getHtmlId()) ?>"><span><?= $block->escapeHtml($block->getLabel()) ?></span></label>
32+
<label class="label" for="<?= $block->escapeHtmlAttr($block->getHtmlId()) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('dob')) ?></span></label>
3333
<div class="control customer-dob">
3434
<?= $block->getFieldHtml() ?>
3535
<?php if ($_message = $block->getAdditionalDescription()) : ?>

app/code/Magento/Customer/view/frontend/templates/widget/gender.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
/** @var \Magento\Customer\Block\Widget\Gender $block */
1010
?>
1111
<div class="field gender<?php if ($block->isRequired()) echo ' required' ?>">
12-
<label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('gender')) ?>"><span><?= $block->escapeHtml(__('Gender')) ?></span></label>
12+
<label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('gender')) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('gender')) ?></span></label>
1313
<div class="control">
14-
<select id="<?= $block->escapeHtmlAttr($block->getFieldId('gender')) ?>" name="<?= $block->escapeHtmlAttr($block->getFieldName('gender')) ?>" title="<?= $block->escapeHtmlAttr(__('Gender')) ?>"<?php if ($block->isRequired()):?> class="validate-select" data-validate="{required:true}"<?php endif; ?>>
14+
<select id="<?= $block->escapeHtmlAttr($block->getFieldId('gender')) ?>" name="<?= $block->escapeHtmlAttr($block->getFieldName('gender')) ?>" title="<?= $block->escapeHtmlAttr($block->getStoreLabel('gender')) ?>"<?php if ($block->isRequired()):?> class="validate-select" data-validate="{required:true}"<?php endif; ?>>
1515
<?php $options = $block->getGenderOptions(); ?>
1616
<?php $value = $block->getGender();?>
1717
<?php foreach ($options as $option):?>

app/code/Magento/Customer/view/frontend/templates/widget/taxvat.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
/** @var \Magento\Customer\Block\Widget\Taxvat $block */
1010
?>
1111
<div class="field taxvat<?php if ($block->isRequired()) echo ' required'; ?>">
12-
<label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('taxvat')) ?>"><span><?= $block->escapeHtml(__('Tax/VAT number')) ?></span></label>
12+
<label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('taxvat')) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('taxvat')) ?></span></label>
1313
<div class="control">
14-
<input type="text" id="<?= $block->escapeHtmlAttr($block->getFieldId('taxvat')) ?>" name="<?= $block->escapeHtmlAttr($block->getFieldName('taxvat')) ?>" value="<?= $block->escapeHtmlAttr($block->getTaxvat()) ?>" title="<?= $block->escapeHtmlAttr(__('Tax/VAT number')) ?>" class="input-text <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('taxvat')) ?>" <?php if ($block->isRequired()) echo ' data-validate="{required:true}"' ?>>
14+
<input type="text" id="<?= $block->escapeHtmlAttr($block->getFieldId('taxvat')) ?>" name="<?= $block->escapeHtmlAttr($block->getFieldName('taxvat')) ?>" value="<?= $block->escapeHtmlAttr($block->getTaxvat()) ?>" title="<?= $block->escapeHtmlAttr($block->getStoreLabel('taxvat')) ?>" class="input-text <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('taxvat')) ?>" <?php if ($block->isRequired()) echo ' data-validate="{required:true}"' ?>>
1515
</div>
1616
</div>

0 commit comments

Comments
 (0)