Skip to content

Commit d08f7e3

Browse files
merge magento/2.3.3-develop into magento-obsessive-owls/MC-17700-squashed
2 parents d18dfe8 + 639e3ce commit d08f7e3

File tree

12 files changed

+329
-65
lines changed

12 files changed

+329
-65
lines changed

app/code/Magento/Catalog/Model/Product/Compare/ListCompare.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
*/
66
namespace Magento\Catalog\Model\Product\Compare;
77

8+
use Magento\Catalog\Model\ProductRepository;
89
use Magento\Catalog\Model\ResourceModel\Product\Compare\Item\Collection;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Exception\NoSuchEntityException;
912

1013
/**
1114
* Product Compare List Model
@@ -51,6 +54,11 @@ class ListCompare extends \Magento\Framework\DataObject
5154
*/
5255
protected $_compareItemFactory;
5356

57+
/**
58+
* @var ProductRepository
59+
*/
60+
private $productRepository;
61+
5462
/**
5563
* Constructor
5664
*
@@ -60,20 +68,23 @@ class ListCompare extends \Magento\Framework\DataObject
6068
* @param \Magento\Customer\Model\Session $customerSession
6169
* @param \Magento\Customer\Model\Visitor $customerVisitor
6270
* @param array $data
71+
* @param ProductRepository|null $productRepository
6372
*/
6473
public function __construct(
6574
\Magento\Catalog\Model\Product\Compare\ItemFactory $compareItemFactory,
6675
\Magento\Catalog\Model\ResourceModel\Product\Compare\Item\CollectionFactory $itemCollectionFactory,
6776
\Magento\Catalog\Model\ResourceModel\Product\Compare\Item $catalogProductCompareItem,
6877
\Magento\Customer\Model\Session $customerSession,
6978
\Magento\Customer\Model\Visitor $customerVisitor,
70-
array $data = []
79+
array $data = [],
80+
ProductRepository $productRepository = null
7181
) {
7282
$this->_compareItemFactory = $compareItemFactory;
7383
$this->_itemCollectionFactory = $itemCollectionFactory;
7484
$this->_catalogProductCompareItem = $catalogProductCompareItem;
7585
$this->_customerSession = $customerSession;
7686
$this->_customerVisitor = $customerVisitor;
87+
$this->productRepository = $productRepository ?: ObjectManager::getInstance()->create(ProductRepository::class);
7788
parent::__construct($data);
7889
}
7990

@@ -82,6 +93,7 @@ public function __construct(
8293
*
8394
* @param int|\Magento\Catalog\Model\Product $product
8495
* @return $this
96+
* @throws \Exception
8597
*/
8698
public function addProduct($product)
8799
{
@@ -90,14 +102,33 @@ public function addProduct($product)
90102
$this->_addVisitorToItem($item);
91103
$item->loadByProduct($product);
92104

93-
if (!$item->getId()) {
105+
if (!$item->getId() && $this->productExists($product)) {
94106
$item->addProductData($product);
95107
$item->save();
96108
}
97109

98110
return $this;
99111
}
100112

113+
/**
114+
* Check product exists.
115+
*
116+
* @param int|\Magento\Catalog\Model\Product $product
117+
* @return bool
118+
*/
119+
private function productExists($product)
120+
{
121+
if ($product instanceof \Magento\Catalog\Model\Product && $product->getId()) {
122+
return true;
123+
}
124+
try {
125+
$product = $this->productRepository->getById((int)$product);
126+
return !empty($product->getId());
127+
} catch (NoSuchEntityException $e) {
128+
return false;
129+
}
130+
}
131+
101132
/**
102133
* Add products to compare list
103134
*

app/code/Magento/Email/Block/Adminhtml/Template/Preview.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

7-
/**
8-
* Adminhtml system template preview block
9-
*
10-
* @author Magento Core Team <core@magentocommerce.com>
11-
*/
128
namespace Magento\Email\Block\Adminhtml\Template;
139

1410
/**
@@ -55,16 +51,12 @@ public function __construct(
5551
* Prepare html output
5652
*
5753
* @return string
58-
* @throws \Magento\Framework\Exception\LocalizedException
54+
* @throws \Exception
5955
*/
6056
protected function _toHtml()
6157
{
6258
$request = $this->getRequest();
6359

64-
if (!$request instanceof \Magento\Framework\App\RequestSafetyInterface || !$request->isSafeMethod()) {
65-
throw new \Magento\Framework\Exception\LocalizedException(__('Wrong request.'));
66-
}
67-
6860
$storeId = $this->getAnyStoreView()->getId();
6961
/** @var $template \Magento\Email\Model\Template */
7062
$template = $this->_emailFactory->create();

app/code/Magento/Email/Controller/Adminhtml/Email/Template/Popup.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
namespace Magento\Email\Controller\Adminhtml\Email\Template;
99

10-
use Magento\Framework\App\Action\HttpGetActionInterface;
10+
use Magento\Framework\App\Action\HttpPostActionInterface;
1111

1212
/**
1313
* Rendering popup email template.
1414
*/
15-
class Popup extends \Magento\Backend\App\Action implements HttpGetActionInterface
15+
class Popup extends \Magento\Backend\App\Action implements HttpPostActionInterface
1616
{
1717
/**
1818
* @var \Magento\Framework\View\Result\PageFactory

app/code/Magento/Email/Controller/Adminhtml/Email/Template/Preview.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,28 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
declare(strict_types=1);
8+
79
namespace Magento\Email\Controller\Adminhtml\Email\Template;
810

11+
use Magento\Email\Controller\Adminhtml\Email\Template;
912
use Magento\Framework\App\Action\HttpGetActionInterface;
13+
use Magento\Framework\App\Action\HttpPostActionInterface;
1014

1115
/**
1216
* Rendering email template preview.
1317
*/
14-
class Preview extends \Magento\Email\Controller\Adminhtml\Email\Template implements HttpGetActionInterface
18+
class Preview extends Template implements HttpGetActionInterface, HttpPostActionInterface
1519
{
1620
/**
1721
* Preview transactional email action.
18-
*
19-
* @return void
2022
*/
2123
public function execute()
2224
{
2325
try {
2426
$this->_view->loadLayout();
2527
$this->_view->getPage()->getConfig()->getTitle()->prepend(__('Email Preview'));
2628
$this->_view->renderLayout();
27-
$this->getResponse()->setHeader('Content-Security-Policy', "script-src 'self'");
2829
} catch (\Exception $e) {
2930
$this->messageManager->addErrorMessage(
3031
__('An error occurred. The email template can not be opened for preview.')

app/code/Magento/Email/Test/Unit/Block/Adminhtml/Template/PreviewTest.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,6 @@ protected function setUp()
152152
*/
153153
public function testToHtml($requestParamMap)
154154
{
155-
$this->request->expects($this->atLeastOnce())
156-
->method('isSafeMethod')
157-
->willReturn(true);
158155
$this->request->expects($this->any())
159156
->method('getParam')
160157
->willReturnMap($requestParamMap);
@@ -171,24 +168,6 @@ public function testToHtml($requestParamMap)
171168
$this->assertEquals(self::MALICIOUS_TEXT, $this->preview->toHtml());
172169
}
173170

174-
/**
175-
* @expectedException \Magento\Framework\Exception\LocalizedException
176-
*/
177-
public function testToHtmlWithException()
178-
{
179-
$this->request->expects($this->atLeastOnce())
180-
->method('isSafeMethod')
181-
->willReturn(false);
182-
$this->template
183-
->expects($this->never())
184-
->method('getDesignConfig');
185-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
186-
$this->expectExceptionMessage(
187-
(string)__('Wrong request.')
188-
);
189-
$this->preview->toHtml();
190-
}
191-
192171
/**
193172
* Data provider
194173
*

app/code/Magento/Email/Test/Unit/Controller/Adminhtml/Email/Template/PreviewTest.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ class PreviewTest extends \PHPUnit\Framework\TestCase
5454
*/
5555
protected $pageTitleMock;
5656

57-
/**
58-
* @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject
59-
*/
60-
protected $responseMock;
61-
6257
protected function setUp()
6358
{
6459
$objectManager = new ObjectManager($this);
@@ -84,16 +79,11 @@ protected function setUp()
8479
->disableOriginalConstructor()
8580
->getMock();
8681

87-
$this->responseMock = $this->getMockBuilder(\Magento\Framework\App\ResponseInterface::class)
88-
->setMethods(['setHeader'])
89-
->getMockForAbstractClass();
90-
9182
$this->context = $objectManager->getObject(
9283
\Magento\Backend\App\Action\Context::class,
9384
[
9485
'request' => $this->requestMock,
95-
'view' => $this->viewMock,
96-
'response' => $this->responseMock
86+
'view' => $this->viewMock
9787
]
9888
);
9989
$this->object = $objectManager->getObject(
@@ -118,9 +108,6 @@ public function testExecute()
118108
$this->pageTitleMock->expects($this->once())
119109
->method('prepend')
120110
->willReturnSelf();
121-
$this->responseMock->expects($this->once())
122-
->method('setHeader')
123-
->with('Content-Security-Policy', "script-src 'self'");
124111

125112
$this->assertNull($this->object->execute());
126113
}

0 commit comments

Comments
 (0)