Skip to content

Commit fac43c2

Browse files
author
Prabhu Ram
committed
Merge remote-tracking branch 'origin/MC-37727-attribute-labels' into honey-pr-bundle
2 parents 70d0862 + 29b379f commit fac43c2

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed

app/code/Magento/CatalogGraphQl/DataProvider/Product/LayeredNavigation/AttributeOptionProvider.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ public function getOptions(array $optionIds, ?int $storeId, array $attributeCode
6464
'attribute_label' => 'a.frontend_label',
6565
]
6666
)
67+
->joinLeft(
68+
['attribute_label' => $this->resourceConnection->getTableName('eav_attribute_label')],
69+
"a.attribute_id = attribute_label.attribute_id AND attribute_label.store_id = {$storeId}",
70+
[
71+
'attribute_store_label' => 'attribute_label.value',
72+
]
73+
)
6774
->joinLeft(
6875
['options' => $this->resourceConnection->getTableName('eav_attribute_option')],
6976
'a.attribute_id = options.attribute_id',
@@ -119,7 +126,7 @@ private function formatResult(\Magento\Framework\DB\Select $select): array
119126
$result[$option['attribute_code']] = [
120127
'attribute_id' => $option['attribute_id'],
121128
'attribute_code' => $option['attribute_code'],
122-
'attribute_label' => $option['attribute_label'],
129+
'attribute_label' => $option['attribute_store_label'] ? $option['attribute_store_label'] : $option['attribute_label'],
123130
'options' => [],
124131
];
125132
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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\GraphQl\Catalog;
9+
10+
use Exception;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\TestFramework\TestCase\GraphQlAbstract;
13+
14+
class ProductAttributeStoreTest extends GraphQlAbstract
15+
{
16+
/**
17+
* Test that custom attribute labels are returned respecting store
18+
*
19+
* @magentoApiDataFixture Magento/Store/_files/store.php
20+
* @magentoApiDataFixture Magento/Catalog/_files/products_with_layered_navigation_attribute_store_options.php
21+
* @throws LocalizedException
22+
*/
23+
public function testAttributeStoreLabels(): void
24+
{
25+
$this->attributeLabelTest('Test Configurable Default Store');
26+
$this->attributeLabelTest('Test Configurable Test Store', ['Store' => 'test']);
27+
}
28+
29+
/**
30+
* @param $expectedLabel
31+
* @param array $headers
32+
* @throws LocalizedException
33+
* @throws Exception
34+
*/
35+
private function attributeLabelTest($expectedLabel, array $headers = []): void
36+
{
37+
$query = <<<QUERY
38+
{
39+
products(search:"Simple",
40+
pageSize: 3
41+
currentPage: 1
42+
)
43+
{
44+
aggregations
45+
{
46+
attribute_code
47+
label
48+
}
49+
}
50+
}
51+
QUERY;
52+
$response = $this->graphQlQuery($query, [], '', $headers);
53+
$this->assertNotEmpty($response['products']['aggregations']);
54+
$attributes = $response['products']['aggregations'];
55+
foreach ($attributes as $attribute) {
56+
if ($attribute['attribute_code'] === 'test_configurable') {
57+
$this->assertEquals($expectedLabel, $attribute['label']);
58+
}
59+
}
60+
}
61+
}

dev/tests/integration/testsuite/Magento/Catalog/_files/products_with_layered_navigation_attribute_store_options.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
'is_visible_on_front' => 1,
5151
'used_in_product_listing' => 1,
5252
'used_for_sort_by' => 1,
53-
'frontend_label' => ['Test Configurable'],
53+
'frontend_label' => [
54+
Store::DEFAULT_STORE_ID => 'Test Configurable Admin Store',
55+
Store::DISTRO_STORE_ID => 'Test Configurable Default Store',
56+
$store->getId() => 'Test Configurable Test Store'
57+
],
5458
'backend_type' => 'int',
5559
'option' => [
5660
'value' => ['option_0' => [

dev/tests/integration/testsuite/Magento/Catalog/_files/products_with_layered_navigation_attribute_store_options_rollback.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424
}
2525
}
2626

27-
$productCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
28-
->get(\Magento\Catalog\Model\ResourceModel\Product\Collection::class);
29-
foreach ($productCollection as $product) {
30-
$product->delete();
31-
}
32-
3327
/** @var $category \Magento\Catalog\Model\Category */
3428
$category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Category::class);
3529
$category->load(333);

0 commit comments

Comments
 (0)