Skip to content

Commit de87bb3

Browse files
authored
ENGCOM-4153: Added label from store view #346
2 parents bbf013e + 3e37fd2 commit de87bb3

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

app/code/Magento/ConfigurableProductGraphQl/Model/Options/Collection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ private function fetch() : array
124124
$this->attributeMap[$productId][$attribute->getId()]['attribute_code']
125125
= $attribute->getProductAttribute()->getAttributeCode();
126126
$this->attributeMap[$productId][$attribute->getId()]['values'] = $attributeData['options'];
127+
$this->attributeMap[$productId][$attribute->getId()]['label']
128+
= $attribute->getProductAttribute()->getStoreLabel();
127129
}
128130

129131
return $this->attributeMap;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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\ConfigurableProduct;
9+
10+
use Magento\TestFramework\TestCase\GraphQlAbstract;
11+
12+
/**
13+
* Class ConfigurableProductFrontendLabelAttributeTest
14+
*
15+
* @package Magento\GraphQl\ConfigurableProduct
16+
*/
17+
class ConfigurableProductFrontendLabelAttributeTest extends GraphQlAbstract
18+
{
19+
/**
20+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_with_frontend_label_attribute.php
21+
*/
22+
public function testGetFrontendLabelAttribute()
23+
{
24+
$expectLabelValue = 'Default Store View label';
25+
$productSku = 'configurable';
26+
27+
$query = <<<QUERY
28+
{
29+
products(filter: {sku: {eq: "{$productSku}"}}) {
30+
items {
31+
name
32+
... on ConfigurableProduct{
33+
configurable_options{
34+
id
35+
label
36+
}
37+
}
38+
}
39+
}
40+
}
41+
QUERY;
42+
$response = $this->graphQlQuery($query);
43+
44+
$this->assertArrayHasKey('products', $response);
45+
$this->assertArrayHasKey('items', $response['products']);
46+
$this->assertArrayHasKey(0, $response['products']['items']);
47+
48+
$product = $response['products']['items'][0];
49+
$this->assertArrayHasKey('configurable_options', $product);
50+
$this->assertArrayHasKey(0, $product['configurable_options']);
51+
$this->assertArrayHasKey('label', $product['configurable_options'][0]);
52+
53+
$option = $product['configurable_options'][0];
54+
$this->assertEquals($expectLabelValue, $option['label']);
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
use Magento\Eav\Model\Entity\Attribute\FrontendLabel;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
11+
require __DIR__ . '/configurable_products.php';
12+
13+
// Add frontend label to created attribute:
14+
$frontendLabelAttribute = Bootstrap::getObjectManager()->get(FrontendLabel::class);
15+
$frontendLabelAttribute->setStoreId(1);
16+
$frontendLabelAttribute->setLabel('Default Store View label');
17+
18+
$frontendLabels = $attribute->getFrontendLabels();
19+
$frontendLabels[] = $frontendLabelAttribute;
20+
21+
$attribute->setFrontendLabels($frontendLabels);
22+
$attributeRepository->save($attribute);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
require __DIR__ . '/configurable_products_rollback.php';

0 commit comments

Comments
 (0)