Skip to content

Commit 16fc50d

Browse files
authored
ENGCOM-4185: [Backport] MAGETWO-95819: Customer registration fields not translated #21081
2 parents 5c7f3f1 + 5f56b5c commit 16fc50d

File tree

2 files changed

+48
-11
lines changed

2 files changed

+48
-11
lines changed

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|null $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/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+
* Class 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',

0 commit comments

Comments
 (0)