Skip to content

Commit e88fa0c

Browse files
committed
Merge branch 'ACP2E-38' of https://github.com/magento-l3/magento2ce into PR1-21-01-2022
2 parents 8e3b513 + db2b6d0 commit e88fa0c

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

app/code/Magento/Checkout/Model/Layout/DepersonalizePlugin.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class DepersonalizePlugin
2828
*/
2929
private $checkoutSession;
3030

31+
/**
32+
* @var int
33+
*/
34+
private $quoteId;
35+
3136
/**
3237
* @param DepersonalizeChecker $depersonalizeChecker
3338
* @param CheckoutSession $checkoutSession
@@ -41,6 +46,19 @@ public function __construct(
4146
$this->checkoutSession = $checkoutSession;
4247
}
4348

49+
/**
50+
* Resolve quote data if the depersonalization is needed.
51+
*
52+
* @param LayoutInterface $subject
53+
* @return void
54+
*/
55+
public function beforeGenerateXml(LayoutInterface $subject)
56+
{
57+
if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
58+
$this->quoteId = $this->checkoutSession->getQuoteId();
59+
}
60+
}
61+
4462
/**
4563
* Change sensitive customer data if the depersonalization is needed.
4664
*
@@ -51,6 +69,7 @@ public function afterGenerateElements(LayoutInterface $subject)
5169
{
5270
if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
5371
$this->checkoutSession->clearStorage();
72+
$this->checkoutSession->setQuoteId($this->quoteId);
5473
}
5574
}
5675
}

app/code/Magento/Checkout/Test/Unit/Model/Layout/DepersonalizePluginTest.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ class DepersonalizePluginTest extends TestCase
4646
protected function setUp(): void
4747
{
4848
$this->layoutMock = $this->getMockForAbstractClass(LayoutInterface::class);
49-
$this->checkoutSessionMock = $this->createPartialMock(CheckoutSession::class, ['clearStorage']);
49+
$this->checkoutSessionMock = $this->createPartialMock(
50+
CheckoutSession::class,
51+
['clearStorage', 'setQuoteId', 'getQuoteId']
52+
);
5053
$this->depersonalizeCheckerMock = $this->createMock(DepersonalizeChecker::class);
5154

5255
$this->plugin = (new ObjectManagerHelper($this))->getObject(
@@ -70,6 +73,10 @@ public function testAfterGenerateElements(): void
7073
->expects($this->once())
7174
->method('clearStorage')
7275
->willReturnSelf();
76+
$this->checkoutSessionMock
77+
->expects($this->once())
78+
->method('setQuoteId')
79+
->willReturn(1);
7380

7481
$this->assertEmpty($this->plugin->afterGenerateElements($this->layoutMock));
7582
}
@@ -86,7 +93,43 @@ public function testAfterGenerateElementsNoDepersonalize(): void
8693
->expects($this->never())
8794
->method('clearStorage')
8895
->willReturnSelf();
96+
$this->checkoutSessionMock
97+
->expects($this->never())
98+
->method('setQuoteId')
99+
->willReturn(1);
89100

90101
$this->assertEmpty($this->plugin->afterGenerateElements($this->layoutMock));
91102
}
103+
104+
/**
105+
* Test beforeGenerateElements method when depersonalization is needed.
106+
*
107+
* @return void
108+
*/
109+
public function testBeforeGenerateXml(): void
110+
{
111+
$this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(true);
112+
$this->checkoutSessionMock
113+
->expects($this->once())
114+
->method('getQuoteId')
115+
->willReturn(1);
116+
117+
$this->assertEmpty($this->plugin->beforeGenerateXml($this->layoutMock));
118+
}
119+
120+
/**
121+
* Test beforeGenerateElements method when depersonalization is not needed.
122+
*
123+
* @return void
124+
*/
125+
public function testBeforeGenerateXmlNoDepersonalize(): void
126+
{
127+
$this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(false);
128+
$this->checkoutSessionMock
129+
->expects($this->never())
130+
->method('getQuoteId')
131+
->willReturn(1);
132+
133+
$this->assertEmpty($this->plugin->beforeGenerateXml($this->layoutMock));
134+
}
92135
}

0 commit comments

Comments
 (0)