Skip to content

Commit 2b4d501

Browse files
author
Vaha
committed
250 - added label from store view
1 parent 8dfe26a commit 2b4d501

File tree

4 files changed

+87
-0
lines changed

4 files changed

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

0 commit comments

Comments
 (0)