Skip to content

Commit 3378823

Browse files
ENGCOM-8465: Customer Attributes Options with option group fixed #30421
- Merge Pull Request #30421 from nitishcs6/magento2:customer-select-option-fix - Merged commits: 1. b5a64c7 2. 57a4510 3. 9dc798f 4. 55f6ce9 5. d22f7f1 6. 6eff507
2 parents 26acabe + 6eff507 commit 3378823

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

app/code/Magento/Customer/Ui/Component/Listing/AttributeRepository.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,13 @@ protected function getOptionArray(array $options)
143143
{
144144
/** @var \Magento\Customer\Api\Data\OptionInterface $option */
145145
foreach ($options as &$option) {
146+
$value = $option->getValue();
147+
if (is_array($option->getOptions())) {
148+
$value = $this->getOptionArray($option->getOptions());
149+
}
146150
$option = [
147151
'label' => (string)$option->getLabel(),
148-
'value' => $option->getValue(),
152+
'value' => $value,
149153
'__disableTmpl' => true
150154
];
151155
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Ui\Component\Listing;
9+
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
use PHPUnit\Framework\TestCase;
12+
13+
/**
14+
* Test for \Magento\Customer\Ui\Component\Listing\AttributeRepository.
15+
*
16+
* @magentoAppArea adminhtml
17+
*/
18+
class AttributeRepositoryTest extends TestCase
19+
{
20+
/**
21+
* @var AttributeRepository
22+
*/
23+
private $model;
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
protected function setUp(): void
29+
{
30+
$this->model = Bootstrap::getObjectManager()->create(AttributeRepository::class);
31+
}
32+
33+
/**
34+
* Test for get store_id option array
35+
*
36+
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
37+
* @return void
38+
*/
39+
public function testGetOptionArray(): void
40+
{
41+
$result = $this->model->getMetadataByCode('store_id');
42+
43+
$this->assertTrue(isset($result['options']['1']['value']));
44+
$this->assertEquals(
45+
['Default Store View', 'Fixture Store'],
46+
$this->getStoreViewLabels($result['options'][1]['value'])
47+
);
48+
}
49+
50+
/**
51+
* Returns prepared store view labels
52+
*
53+
* @param array $storeViewsData
54+
* @return array
55+
*/
56+
private function getStoreViewLabels(array $storeViewsData): array
57+
{
58+
$result = [];
59+
foreach ($storeViewsData as $storeView) {
60+
$result[] = str_replace("\xc2\xa0", '', $storeView['label']);
61+
}
62+
63+
return $result;
64+
}
65+
}

0 commit comments

Comments
 (0)