Skip to content

Commit eb99f9c

Browse files
committed
Merge branch '2.3-develop' of github.com:magento/magento2ce into 2.3-pangolin-removeComposer
2 parents ca82ac3 + b6c47a2 commit eb99f9c

File tree

19 files changed

+744
-35
lines changed

19 files changed

+744
-35
lines changed

app/code/Magento/Quote/Model/Quote.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ public function getAllVisibleItems()
13991399
{
14001400
$items = [];
14011401
foreach ($this->getItemsCollection() as $item) {
1402-
if (!$item->isDeleted() && !$item->getParentItemId()) {
1402+
if (!$item->isDeleted() && !$item->getParentItemId() && !$item->getParentItem()) {
14031403
$items[] = $item;
14041404
}
14051405
}

app/code/Magento/Quote/Model/QuoteRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ protected function loadQuote($loadMethod, $loadField, $identifier, array $shared
212212
if ($sharedStoreIds) {
213213
$quote->setSharedStoreIds($sharedStoreIds);
214214
}
215-
$quote->$loadMethod($identifier)->setStoreId($this->storeManager->getStore()->getId());
215+
$quote->setStoreId($this->storeManager->getStore()->getId())->$loadMethod($identifier);
216216
if (!$quote->getId()) {
217217
throw NoSuchEntityException::singleField($loadField, $identifier);
218218
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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\Quote\Plugin;
9+
10+
use Magento\Checkout\Model\Session;
11+
use Magento\Quote\Model\QuoteRepository;
12+
use Magento\Store\Api\Data\StoreInterface;
13+
use Magento\Store\Api\StoreCookieManagerInterface;
14+
15+
/**
16+
* Updates quote store id.
17+
*/
18+
class UpdateQuoteStore
19+
{
20+
/**
21+
* @var QuoteRepository
22+
*/
23+
private $quoteRepository;
24+
25+
/**
26+
* @var Session
27+
*/
28+
private $checkoutSession;
29+
30+
/**
31+
* @param QuoteRepository $quoteRepository
32+
* @param Session $checkoutSession
33+
*/
34+
public function __construct(
35+
QuoteRepository $quoteRepository,
36+
Session $checkoutSession
37+
) {
38+
$this->quoteRepository = $quoteRepository;
39+
$this->checkoutSession = $checkoutSession;
40+
}
41+
42+
/**
43+
* Update store id in active quote after store view switching.
44+
*
45+
* @param StoreCookieManagerInterface $subject
46+
* @param null $result
47+
* @param StoreInterface $store
48+
* @return void
49+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
50+
*/
51+
public function afterSetStoreCookie(
52+
StoreCookieManagerInterface $subject,
53+
$result,
54+
StoreInterface $store
55+
) {
56+
$storeCodeFromCookie = $subject->getStoreCodeFromCookie();
57+
if (null === $storeCodeFromCookie) {
58+
return;
59+
}
60+
61+
$quote = $this->checkoutSession->getQuote();
62+
if ($quote->getIsActive() && $store->getCode() != $storeCodeFromCookie) {
63+
$quote->setStoreId(
64+
$store->getId()
65+
);
66+
$this->quoteRepository->save($quote);
67+
}
68+
}
69+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\Quote\Plugin\UpdateQuoteStore">
10+
<arguments>
11+
<argument name="quoteRepository" xsi:type="object">Magento\Quote\Model\QuoteRepository\Proxy</argument>
12+
<argument name="checkoutSession" xsi:type="object">Magento\Checkout\Model\Session\Proxy</argument>
13+
</arguments>
14+
</type>
15+
<type name="Magento\Store\Api\StoreCookieManagerInterface">
16+
<plugin name="update_quote_store_after_switch_store_view" type="Magento\Quote\Plugin\UpdateQuoteStore"/>
17+
</type>
18+
</config>

app/code/Magento/Signifyd/Controller/Webhooks/Handler.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\Framework\App\Action\Action;
99
use Magento\Framework\App\Action\Context;
10+
use Magento\Framework\App\Request\InvalidRequestException;
11+
use Magento\Framework\App\RequestInterface;
1012
use Magento\Framework\Exception\LocalizedException;
1113
use Magento\Signifyd\Api\CaseRepositoryInterface;
1214
use Magento\Signifyd\Model\CaseServices\UpdatingServiceFactory;
@@ -21,7 +23,7 @@
2123
*
2224
* @see https://www.signifyd.com/docs/api/#/reference/webhooks/
2325
*/
24-
class Handler extends Action
26+
class Handler extends Action implements \Magento\Framework\App\CsrfAwareActionInterface
2527
{
2628
/**
2729
* Event topic of test webhook request.
@@ -136,4 +138,20 @@ public function execute()
136138
$this->logger->critical($e);
137139
}
138140
}
141+
142+
/**
143+
* @inheritDoc
144+
*/
145+
public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException
146+
{
147+
return null;
148+
}
149+
150+
/**
151+
* @inheritDoc
152+
*/
153+
public function validateForCsrf(RequestInterface $request): ?bool
154+
{
155+
return true;
156+
}
139157
}

app/code/Magento/Theme/Controller/Result/MessagePlugin.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
*/
66
namespace Magento\Theme\Controller\Result;
77

8+
use Magento\Framework\App\ObjectManager;
89
use Magento\Framework\Controller\Result\Json;
910
use Magento\Framework\Controller\ResultInterface;
1011
use Magento\Framework\Message\MessageInterface;
12+
use Magento\Framework\Translate\Inline\ParserInterface;
13+
use Magento\Framework\Translate\InlineInterface;
1114

1215
/**
1316
* Plugin for putting messages to cookies
@@ -44,26 +47,34 @@ class MessagePlugin
4447
*/
4548
private $serializer;
4649

50+
/**
51+
* @var InlineInterface
52+
*/
53+
private $inlineTranslate;
54+
4755
/**
4856
* @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager
4957
* @param \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory
5058
* @param \Magento\Framework\Message\ManagerInterface $messageManager
5159
* @param \Magento\Framework\View\Element\Message\InterpretationStrategyInterface $interpretationStrategy
5260
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
61+
* @param InlineInterface|null $inlineTranslate
5362
*/
5463
public function __construct(
5564
\Magento\Framework\Stdlib\CookieManagerInterface $cookieManager,
5665
\Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory,
5766
\Magento\Framework\Message\ManagerInterface $messageManager,
5867
\Magento\Framework\View\Element\Message\InterpretationStrategyInterface $interpretationStrategy,
59-
\Magento\Framework\Serialize\Serializer\Json $serializer = null
68+
\Magento\Framework\Serialize\Serializer\Json $serializer = null,
69+
InlineInterface $inlineTranslate = null
6070
) {
6171
$this->cookieManager = $cookieManager;
6272
$this->cookieMetadataFactory = $cookieMetadataFactory;
6373
$this->messageManager = $messageManager;
64-
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
74+
$this->serializer = $serializer ?: ObjectManager::getInstance()
6575
->get(\Magento\Framework\Serialize\Serializer\Json::class);
6676
$this->interpretationStrategy = $interpretationStrategy;
77+
$this->inlineTranslate = $inlineTranslate ?: ObjectManager::getInstance()->get(InlineInterface::class);
6778
}
6879

6980
/**
@@ -112,6 +123,12 @@ public function afterRenderResult(
112123
private function setCookie(array $messages)
113124
{
114125
if (!empty($messages)) {
126+
if ($this->inlineTranslate->isAllowed()) {
127+
foreach ($messages as &$message) {
128+
$message['text'] = $this->convertMessageText($message['text']);
129+
}
130+
}
131+
115132
$publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata();
116133
$publicCookieMetadata->setDurationOneYear();
117134
$publicCookieMetadata->setPath('/');
@@ -125,6 +142,21 @@ private function setCookie(array $messages)
125142
}
126143
}
127144

145+
/**
146+
* Replace wrapping translation with html body.
147+
*
148+
* @param string $text
149+
* @return string
150+
*/
151+
private function convertMessageText(string $text): string
152+
{
153+
if (preg_match('#' . ParserInterface::REGEXP_TOKEN . '#', $text, $matches)) {
154+
$text = $matches[1];
155+
}
156+
157+
return $text;
158+
}
159+
128160
/**
129161
* Return messages array and clean message manager messages
130162
*

app/code/Magento/Theme/Test/Unit/Controller/Result/MessagePluginTest.php

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
1515
use Magento\Framework\Stdlib\Cookie\PublicCookieMetadata;
1616
use Magento\Framework\Stdlib\CookieManagerInterface;
17+
use Magento\Framework\Translate\InlineInterface;
1718
use Magento\Framework\View\Element\Message\InterpretationStrategyInterface;
1819
use Magento\Theme\Controller\Result\MessagePlugin;
1920

@@ -40,6 +41,9 @@ class MessagePluginTest extends \PHPUnit\Framework\TestCase
4041
/** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
4142
private $serializerMock;
4243

44+
/** @var InlineInterface|\PHPUnit_Framework_MockObject_MockObject */
45+
private $inlineTranslateMock;
46+
4347
protected function setUp()
4448
{
4549
$this->cookieManagerMock = $this->getMockBuilder(CookieManagerInterface::class)
@@ -53,13 +57,15 @@ protected function setUp()
5357
->getMockForAbstractClass();
5458
$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
5559
->getMock();
60+
$this->inlineTranslateMock = $this->getMockBuilder(InlineInterface::class)->getMockForAbstractClass();
5661

5762
$this->model = new MessagePlugin(
5863
$this->cookieManagerMock,
5964
$this->cookieMetadataFactoryMock,
6065
$this->managerMock,
6166
$this->interpretationStrategyMock,
62-
$this->serializerMock
67+
$this->serializerMock,
68+
$this->inlineTranslateMock
6369
);
6470
}
6571

@@ -450,4 +456,93 @@ function ($data) {
450456

451457
$this->assertEquals($resultMock, $this->model->afterRenderResult($resultMock, $resultMock));
452458
}
459+
460+
/**
461+
* @return void
462+
*/
463+
public function testAfterRenderResultWithAllowedInlineTranslate(): void
464+
{
465+
$messageType = 'message1type';
466+
$messageText = '{{{message1text}}{{message1text}}{{message1text}}{{theme/luma}}}';
467+
$expectedMessages = [
468+
[
469+
'type' => $messageType,
470+
'text' => 'message1text',
471+
],
472+
];
473+
474+
/** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $resultMock */
475+
$resultMock = $this->getMockBuilder(Redirect::class)
476+
->disableOriginalConstructor()
477+
->getMock();
478+
479+
/** @var PublicCookieMetadata|\PHPUnit_Framework_MockObject_MockObject $cookieMetadataMock */
480+
$cookieMetadataMock = $this->getMockBuilder(PublicCookieMetadata::class)
481+
->disableOriginalConstructor()
482+
->getMock();
483+
484+
$this->cookieMetadataFactoryMock->expects($this->once())
485+
->method('createPublicCookieMetadata')
486+
->willReturn($cookieMetadataMock);
487+
488+
$this->cookieManagerMock->expects($this->once())
489+
->method('setPublicCookie')
490+
->with(
491+
MessagePlugin::MESSAGES_COOKIES_NAME,
492+
json_encode($expectedMessages),
493+
$cookieMetadataMock
494+
);
495+
$this->cookieManagerMock->expects($this->once())
496+
->method('getCookie')
497+
->with(
498+
MessagePlugin::MESSAGES_COOKIES_NAME
499+
)
500+
->willReturn(json_encode([]));
501+
502+
$this->serializerMock->expects($this->once())
503+
->method('unserialize')
504+
->willReturnCallback(
505+
function ($data) {
506+
return json_decode($data, true);
507+
}
508+
);
509+
$this->serializerMock->expects($this->once())
510+
->method('serialize')
511+
->willReturnCallback(
512+
function ($data) {
513+
return json_encode($data);
514+
}
515+
);
516+
517+
/** @var MessageInterface|\PHPUnit_Framework_MockObject_MockObject $messageMock */
518+
$messageMock = $this->getMockBuilder(MessageInterface::class)
519+
->getMock();
520+
$messageMock->expects($this->once())
521+
->method('getType')
522+
->willReturn($messageType);
523+
524+
$this->interpretationStrategyMock->expects($this->once())
525+
->method('interpret')
526+
->with($messageMock)
527+
->willReturn($messageText);
528+
529+
$this->inlineTranslateMock->expects($this->once())
530+
->method('isAllowed')
531+
->willReturn(true);
532+
533+
/** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */
534+
$collectionMock = $this->getMockBuilder(Collection::class)
535+
->disableOriginalConstructor()
536+
->getMock();
537+
$collectionMock->expects($this->once())
538+
->method('getItems')
539+
->willReturn([$messageMock]);
540+
541+
$this->managerMock->expects($this->once())
542+
->method('getMessages')
543+
->with(true, null)
544+
->willReturn($collectionMock);
545+
546+
$this->assertEquals($resultMock, $this->model->afterRenderResult($resultMock, $resultMock));
547+
}
453548
}

app/code/Magento/Weee/Model/Tax.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,20 @@ public function getProductWeeeAttributes(
248248
$round = true
249249
) {
250250
$result = [];
251-
252-
$websiteId = $this->_storeManager->getWebsite($website)->getId();
251+
$websiteId = null;
253252
/** @var \Magento\Store\Model\Store $store */
254-
$store = $this->_storeManager->getWebsite($website)->getDefaultGroup()->getDefaultStore();
253+
$store = null;
254+
if (!$website) {
255+
$store = $product->getStore();
256+
if ($store) {
257+
$websiteId = $store->getWebsiteId();
258+
}
259+
}
260+
if (!$websiteId) {
261+
$websiteObject = $this->_storeManager->getWebsite($website);
262+
$websiteId = $websiteObject->getId();
263+
$store = $websiteObject->getDefaultGroup()->getDefaultStore();
264+
}
255265

256266
$allWeee = $this->getWeeeTaxAttributeCodes($store);
257267
if (!$allWeee) {

0 commit comments

Comments
 (0)