Skip to content

Commit 4aea58a

Browse files
authored
Merge pull request #5841 from magento-tsg-csl3/2.3-develop-pr50
[TSG-CSL3] For 2.3 (pr50)
2 parents 991c362 + dc4c6bd commit 4aea58a

File tree

10 files changed

+459
-37
lines changed

10 files changed

+459
-37
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\CatalogGraphQl\DataProvider\Product\LayeredNavigation;
99

1010
use Magento\Framework\App\ResourceConnection;
11+
use Magento\Store\Model\Store;
1112

1213
/**
1314
* Fetch product attribute option data including attribute info
@@ -41,16 +42,18 @@ public function __construct(ResourceConnection $resourceConnection)
4142
* Get option data. Return list of attributes with option data
4243
*
4344
* @param array $optionIds
45+
* @param int|null $storeId
4446
* @param array $attributeCodes
4547
* @return array
4648
* @throws \Zend_Db_Statement_Exception
4749
*/
48-
public function getOptions(array $optionIds, array $attributeCodes = []): array
50+
public function getOptions(array $optionIds, ?int $storeId, array $attributeCodes = []): array
4951
{
5052
if (!$optionIds) {
5153
return [];
5254
}
5355

56+
$storeId = $storeId ?: Store::DEFAULT_STORE_ID;
5457
$connection = $this->resourceConnection->getConnection();
5558
$select = $connection->select()
5659
->from(
@@ -70,9 +73,21 @@ public function getOptions(array $optionIds, array $attributeCodes = []): array
7073
['option_value' => $this->resourceConnection->getTableName('eav_attribute_option_value')],
7174
'options.option_id = option_value.option_id',
7275
[
73-
'option_label' => 'option_value.value',
7476
'option_id' => 'option_value.option_id',
7577
]
78+
)->joinLeft(
79+
['option_value_store' => $this->resourceConnection->getTableName('eav_attribute_option_value')],
80+
"options.option_id = option_value_store.option_id AND option_value_store.store_id = {$storeId}",
81+
[
82+
'option_label' => $connection->getCheckSql(
83+
'option_value_store.value_id > 0',
84+
'option_value_store.value',
85+
'option_value.value'
86+
)
87+
]
88+
)->where(
89+
'a.attribute_id = options.attribute_id AND option_value.store_id = ?',
90+
Store::DEFAULT_STORE_ID
7691
);
7792

7893
$select->where('option_value.option_id IN (?)', $optionIds);

app/code/Magento/CatalogGraphQl/DataProvider/Product/LayeredNavigation/Builder/Attribute.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function __construct(
7171
*/
7272
public function build(AggregationInterface $aggregation, ?int $storeId): array
7373
{
74-
$attributeOptions = $this->getAttributeOptions($aggregation);
74+
$attributeOptions = $this->getAttributeOptions($aggregation, $storeId);
7575

7676
// build layer per attribute
7777
$result = [];
@@ -133,10 +133,11 @@ private function isBucketEmpty(?BucketInterface $bucket): bool
133133
* Get list of attributes with options
134134
*
135135
* @param AggregationInterface $aggregation
136+
* @param int|null $storeId
136137
* @return array
137138
* @throws \Zend_Db_Statement_Exception
138139
*/
139-
private function getAttributeOptions(AggregationInterface $aggregation): array
140+
private function getAttributeOptions(AggregationInterface $aggregation, ?int $storeId): array
140141
{
141142
$attributeOptionIds = [];
142143
$attributes = [];
@@ -154,6 +155,6 @@ function (AggregationValueInterface $value) {
154155
return [];
155156
}
156157

157-
return $this->attributeOptionProvider->getOptions(\array_merge(...$attributeOptionIds), $attributes);
158+
return $this->attributeOptionProvider->getOptions(\array_merge(...$attributeOptionIds), $storeId, $attributes);
158159
}
159160
}

app/code/Magento/Checkout/view/frontend/web/js/region-updater.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ define([
157157
regionInput = $(this.options.regionInputId),
158158
postcode = $(this.options.postcodeId),
159159
label = regionList.parent().siblings('label'),
160-
container = regionList.parents('div.field');
160+
container = regionList.parents('div.field'),
161+
regionsEntries,
162+
regionId,
163+
regionData;
161164

162165
this._clearError();
163166
this._checkRegionRequired(country);
@@ -168,8 +171,14 @@ define([
168171
// Populate state/province dropdown list if available or use input box
169172
if (this.options.regionJson[country]) {
170173
this._removeSelectOptions(regionList);
171-
$.each(this.options.regionJson[country], $.proxy(function (key, value) {
172-
this._renderSelectOption(regionList, key, value);
174+
regionsEntries = Object.entries(this.options.regionJson[country]);
175+
regionsEntries.sort(function (a, b) {
176+
return a[1].name > b[1].name ? 1 : -1;
177+
});
178+
$.each(regionsEntries, $.proxy(function (key, value) {
179+
regionId = value[0];
180+
regionData = value[1];
181+
this._renderSelectOption(regionList, regionId, regionData);
173182
}, this));
174183

175184
if (this.currentRegionOption) {

app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@
110110
<element name="PageSize" type="input" selector="input[name='parameters[page_size]']"/>
111111
<element name="ProductAttribute" type="multiselect" selector="select[name='parameters[show_attributes][]']" />
112112
<element name="ButtonToShow" type="multiselect" selector="select[name='parameters[show_buttons][]']"/>
113+
<element name="InputAnchorCustomText" type="input" selector="input[name='parameters[anchor_text]']"/>
114+
<element name="InputAnchorCustomTitle" type="input" selector="input[name='parameters[title]']"/>
113115
<!--Compare on Storefront-->
114116
<element name="ProductName" type="text" selector=".product.name.product-item-name" />
115117
<element name="CompareBtn" type="button" selector=".action.tocompare"/>

app/code/Magento/GoogleOptimizer/Observer/AbstractSave.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
* Copyright © Magento, Inc. All rights reserved.
66
* See COPYING.txt for license details.
77
*/
8+
declare(strict_types=1);
9+
810
namespace Magento\GoogleOptimizer\Observer;
911

1012
use Magento\Framework\Event\Observer;
1113
use Magento\Framework\Event\ObserverInterface;
1214

1315
/**
16+
* Abstract entity for saving codes
17+
*
1418
* @api
1519
* @since 100.0.2
1620
*/
@@ -96,7 +100,9 @@ protected function _processCode()
96100
$this->_initRequestParams();
97101

98102
if ($this->_isNewCode()) {
99-
$this->_saveCode();
103+
if (!$this->_isEmptyCode()) {
104+
$this->_saveCode();
105+
}
100106
} else {
101107
$this->_loadCode();
102108
if ($this->_isEmptyCode()) {
@@ -185,6 +191,8 @@ protected function _deleteCode()
185191
}
186192

187193
/**
194+
* Check data availability
195+
*
188196
* @return bool
189197
*/
190198
private function isDataAvailable()
@@ -194,6 +202,8 @@ private function isDataAvailable()
194202
}
195203

196204
/**
205+
* Get request data
206+
*
197207
* @return mixed
198208
*/
199209
private function getRequestData()

app/code/Magento/GoogleOptimizer/Test/Unit/Observer/Product/SaveGoogleExperimentScriptObserverTest.php

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,50 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\GoogleOptimizer\Test\Unit\Observer\Product;
79

8-
class SaveGoogleExperimentScriptObserverTest extends \PHPUnit\Framework\TestCase
10+
use Magento\Catalog\Model\Product;
11+
use Magento\Framework\App\RequestInterface;
12+
use Magento\Framework\Event;
13+
use Magento\Framework\Event\Observer;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
15+
use Magento\GoogleOptimizer\Helper\Data;
16+
use Magento\GoogleOptimizer\Model\Code;
17+
use Magento\GoogleOptimizer\Observer\Product\SaveGoogleExperimentScriptObserver;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
class SaveGoogleExperimentScriptObserverTest extends TestCase
922
{
1023
/**
11-
* @var \PHPUnit_Framework_MockObject_MockObject
24+
* @var MockObject
1225
*/
1326
protected $_helperMock;
1427

1528
/**
16-
* @var \PHPUnit_Framework_MockObject_MockObject
29+
* @var MockObject
1730
*/
1831
protected $_eventObserverMock;
1932

2033
/**
21-
* @var \PHPUnit_Framework_MockObject_MockObject
34+
* @var MockObject
2235
*/
2336
protected $_productMock;
2437

2538
/**
26-
* @var \PHPUnit_Framework_MockObject_MockObject
39+
* @var MockObject
2740
*/
2841
protected $_codeMock;
2942

3043
/**
31-
* @var \PHPUnit_Framework_MockObject_MockObject
44+
* @var MockObject
3245
*/
3346
protected $_requestMock;
3447

3548
/**
36-
* @var \Magento\GoogleOptimizer\Observer\Product\SaveGoogleExperimentScriptObserver
49+
* @var SaveGoogleExperimentScriptObserver
3750
*/
3851
protected $_modelObserver;
3952

@@ -44,8 +57,8 @@ class SaveGoogleExperimentScriptObserverTest extends \PHPUnit\Framework\TestCase
4457

4558
protected function setUp()
4659
{
47-
$this->_helperMock = $this->createMock(\Magento\GoogleOptimizer\Helper\Data::class);
48-
$this->_productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
60+
$this->_helperMock = $this->createMock(Data::class);
61+
$this->_productMock = $this->createMock(Product::class);
4962
$this->_storeId = 0;
5063
$this->_productMock->expects(
5164
$this->atLeastOnce()
@@ -54,16 +67,16 @@ protected function setUp()
5467
)->will(
5568
$this->returnValue($this->_storeId)
5669
);
57-
$event = $this->createPartialMock(\Magento\Framework\Event::class, ['getProduct']);
70+
$event = $this->createPartialMock(Event::class, ['getProduct']);
5871
$event->expects($this->once())->method('getProduct')->will($this->returnValue($this->_productMock));
59-
$this->_eventObserverMock = $this->createMock(\Magento\Framework\Event\Observer::class);
72+
$this->_eventObserverMock = $this->createMock(Observer::class);
6073
$this->_eventObserverMock->expects($this->once())->method('getEvent')->will($this->returnValue($event));
61-
$this->_codeMock = $this->createMock(\Magento\GoogleOptimizer\Model\Code::class);
62-
$this->_requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class);
74+
$this->_codeMock = $this->createMock(Code::class);
75+
$this->_requestMock = $this->createMock(RequestInterface::class);
6376

64-
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
77+
$objectManagerHelper = new ObjectManager($this);
6578
$this->_modelObserver = $objectManagerHelper->getObject(
66-
\Magento\GoogleOptimizer\Observer\Product\SaveGoogleExperimentScriptObserver::class,
79+
SaveGoogleExperimentScriptObserver::class,
6780
['helper' => $this->_helperMock, 'modelCode' => $this->_codeMock, 'request' => $this->_requestMock]
6881
);
6982
}
@@ -100,7 +113,7 @@ public function testCreatingCodeIfRequestIsValid()
100113
'addData'
101114
)->with(
102115
[
103-
'entity_type' => \Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_PRODUCT,
116+
'entity_type' => Code::ENTITY_TYPE_PRODUCT,
104117
'entity_id' => $productId,
105118
'store_id' => $this->_storeId,
106119
'experiment_script' => $experimentScript,
@@ -111,6 +124,39 @@ public function testCreatingCodeIfRequestIsValid()
111124
$this->_modelObserver->execute($this->_eventObserverMock);
112125
}
113126

127+
/**
128+
* Test that code is not saving when request is empty
129+
*
130+
* @return void
131+
*/
132+
public function testCreatingCodeIfRequestIsEmpty(): void
133+
{
134+
$this->_helperMock->expects(
135+
$this->once()
136+
)->method(
137+
'isGoogleExperimentActive'
138+
)->with(
139+
$this->_storeId
140+
)->will(
141+
$this->returnValue(true)
142+
);
143+
144+
$this->_requestMock->expects(
145+
$this->exactly(3)
146+
)->method(
147+
'getParam'
148+
)->with(
149+
'google_experiment'
150+
)->will(
151+
$this->returnValue(['code_id' => '', 'experiment_script' => ''])
152+
);
153+
154+
$this->_codeMock->expects($this->never())->method('addData');
155+
$this->_codeMock->expects($this->never())->method('save');
156+
157+
$this->_modelObserver->execute($this->_eventObserverMock);
158+
}
159+
114160
/**
115161
* @param array $params
116162
* @dataProvider dataProviderWrongRequestForCreating
@@ -190,7 +236,7 @@ public function testEditingCodeIfRequestIsValid()
190236
'addData'
191237
)->with(
192238
[
193-
'entity_type' => \Magento\GoogleOptimizer\Model\Code::ENTITY_TYPE_PRODUCT,
239+
'entity_type' => Code::ENTITY_TYPE_PRODUCT,
194240
'entity_id' => $productId,
195241
'store_id' => $this->_storeId,
196242
'experiment_script' => $experimentScript,

0 commit comments

Comments
 (0)