Skip to content

Commit 182c7e5

Browse files
committed
MC-35058: Error when trying to remove categories from product
1 parent 5fca50e commit 182c7e5

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,39 @@ public function testCreatingCodeIfRequestIsValid()
127127
$this->_modelObserver->execute($this->_eventObserverMock);
128128
}
129129

130+
/**
131+
* Test that code is not saving when request is empty
132+
*
133+
* @return void
134+
*/
135+
public function testCreatingCodeIfRequestIsEmpty(): void
136+
{
137+
$this->_helperMock->expects(
138+
$this->once()
139+
)->method(
140+
'isGoogleExperimentActive'
141+
)->with(
142+
$this->_storeId
143+
)->willReturn(
144+
true
145+
);
146+
147+
$this->_requestMock->expects(
148+
$this->exactly(3)
149+
)->method(
150+
'getParam'
151+
)->with(
152+
'google_experiment'
153+
)->willReturn(
154+
['code_id' => '', 'experiment_script' => '']
155+
);
156+
157+
$this->_codeMock->expects($this->never())->method('addData');
158+
$this->_codeMock->expects($this->never())->method('save');
159+
160+
$this->_modelObserver->execute($this->_eventObserverMock);
161+
}
162+
130163
/**
131164
* @param array $params
132165
* @dataProvider dataProviderWrongRequestForCreating

0 commit comments

Comments
 (0)