Skip to content

Commit d90dc8a

Browse files
ENGCOM-7244: Customer attribute frontend labels not using the store label values on the frontend #27064
- Merge Pull Request #27064 from nntoan/magento2:fallback-to-storelabels-customer-attributes - Merged commits: 1. fdec82c 2. 9a7d68d 3. 0bf66d9 4. 9b6e058 5. aa148c3 6. 4c110b7 7. 705b5be 8. 5749b24 9. d4ba184 10. cec82da 11. 2f0dae9 12. 88da24a 13. e99e6e1 14. 5bc8bba 15. 9f20b7f 16. b1480fb 17. 05fbd1f 18. ef806a5 19. dec273f 20. 458ce8d 21. 8848c6a 22. 53498e1 23. 893641c 24. 48411f9 25. b4f98d6 26. 040c23d 27. fc9b841 28. 6a912c2 29. e9b4cf0
2 parents 679cd33 + e9b4cf0 commit d90dc8a

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

app/code/Magento/Customer/Block/DataProviders/AddressAttributeData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getFrontendLabel(string $attributeCode): string
5252
{
5353
try {
5454
$attribute = $this->addressMetadata->getAttributeMetadata($attributeCode);
55-
$frontendLabel = $attribute->getFrontendLabel();
55+
$frontendLabel = $attribute->getStoreLabel() ?: $attribute->getFrontendLabel();
5656
} catch (NoSuchEntityException $e) {
5757
$frontendLabel = '';
5858
}

dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,22 @@ public function testFaxEnabled(): void
138138
$this->assertStringContainsString('title="Fax"', $block->toHtml());
139139
}
140140

141+
/**
142+
* @magentoDataFixture Magento/Customer/_files/attribute_city_store_label_address.php
143+
*/
144+
public function testCityWithStoreLabel(): void
145+
{
146+
/** @var \Magento\Customer\Block\Form\Register $block */
147+
$block = Bootstrap::getObjectManager()->create(
148+
Register::class
149+
)->setTemplate('Magento_Customer::form/register.phtml')
150+
->setShowAddressFields(true);
151+
$this->setAttributeDataProvider($block);
152+
153+
$this->assertStringNotContainsString('title="City"', $block->toHtml());
154+
$this->assertStringContainsString('title="Suburb"', $block->toHtml());
155+
}
156+
141157
/**
142158
* @inheritdoc
143159
*/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
//@codingStandardsIgnoreFile
7+
/** @var \Magento\Customer\Model\Attribute $model */
8+
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Attribute::class);
9+
/** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
10+
$storeManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Store\Model\StoreManager::class);
11+
$model->loadByCode('customer_address', 'city');
12+
$storeLabels = $model->getStoreLabels();
13+
$stores = $storeManager->getStores();
14+
/** @var \Magento\Store\Api\Data\WebsiteInterface $website */
15+
foreach ($stores as $store) {
16+
$storeLabels[$store->getId()] = 'Suburb';
17+
}
18+
$model->setStoreLabels($storeLabels);
19+
$model->save();

0 commit comments

Comments
 (0)