Skip to content

Commit 3d56733

Browse files
committed
Merge remote-tracking branch 'magento2/develop' into PR-11082016
2 parents da140ca + bbd4b4c commit 3d56733

File tree

63 files changed

+1538
-497
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1538
-497
lines changed

app/code/Magento/CatalogUrlRewrite/Observer/CategoryUrlPathAutogeneratorObserver.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,18 @@ public function __construct(
4242
/**
4343
* @param \Magento\Framework\Event\Observer $observer
4444
* @return void
45+
* @throws \Magento\Framework\Exception\LocalizedException
4546
*/
4647
public function execute(\Magento\Framework\Event\Observer $observer)
4748
{
4849
/** @var Category $category */
4950
$category = $observer->getEvent()->getCategory();
5051
if ($category->getUrlKey() !== false) {
51-
$category->setUrlKey($this->categoryUrlPathGenerator->getUrlKey($category))
52+
$resultUrlKey = $this->categoryUrlPathGenerator->getUrlKey($category);
53+
if (empty($resultUrlKey)) {
54+
throw new \Magento\Framework\Exception\LocalizedException(__('Invalid URL key'));
55+
}
56+
$category->setUrlKey($resultUrlKey)
5257
->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($category));
5358
if (!$category->isObjectNew()) {
5459
$category->getResource()->saveAttribute($category, 'url_path');

app/code/Magento/Checkout/Controller/Cart/CouponPost.php

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,17 @@ public function execute()
9090

9191
if ($codeLength) {
9292
$escaper = $this->_objectManager->get(\Magento\Framework\Escaper::class);
93+
$coupon = $this->couponFactory->create();
94+
$coupon->load($couponCode, 'code');
9395
if (!$itemsCount) {
94-
if ($isCodeLengthValid) {
95-
$coupon = $this->couponFactory->create();
96-
$coupon->load($couponCode, 'code');
97-
if ($coupon->getId()) {
98-
$this->_checkoutSession->getQuote()->setCouponCode($couponCode)->save();
99-
$this->messageManager->addSuccess(
100-
__(
101-
'You used coupon code "%1".',
102-
$escaper->escapeHtml($couponCode)
103-
)
104-
);
105-
} else {
106-
$this->messageManager->addError(
107-
__(
108-
'The coupon code "%1" is not valid.',
109-
$escaper->escapeHtml($couponCode)
110-
)
111-
);
112-
}
96+
if ($isCodeLengthValid && $coupon->getId()) {
97+
$this->_checkoutSession->getQuote()->setCouponCode($couponCode)->save();
98+
$this->messageManager->addSuccess(
99+
__(
100+
'You used coupon code "%1".',
101+
$escaper->escapeHtml($couponCode)
102+
)
103+
);
113104
} else {
114105
$this->messageManager->addError(
115106
__(
@@ -119,7 +110,7 @@ public function execute()
119110
);
120111
}
121112
} else {
122-
if ($isCodeLengthValid && $couponCode == $cartQuote->getCouponCode()) {
113+
if ($isCodeLengthValid && $coupon->getId() && $couponCode == $cartQuote->getCouponCode()) {
123114
$this->messageManager->addSuccess(
124115
__(
125116
'You used coupon code "%1".',

app/code/Magento/Checkout/Test/Unit/Controller/Cart/CouponPostTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ class CouponPostTest extends \PHPUnit_Framework_TestCase
6969
*/
7070
protected $quoteRepository;
7171

72+
/**
73+
* @var \PHPUnit_Framework_MockObject_MockObject
74+
*/
75+
private $redirect;
76+
77+
/**
78+
* @var \PHPUnit_Framework_MockObject_MockObject
79+
*/
80+
private $redirectFactory;
81+
7282
/**
7383
* @return void
7484
*/
@@ -204,6 +214,12 @@ public function testExecuteWithGoodCouponAndItems()
204214
->method('getCouponCode')
205215
->willReturn('OLDCODE');
206216

217+
$coupon = $this->getMock(\Magento\SalesRule\Model\Coupon::class, [], [], '', false);
218+
$this->couponFactory->expects($this->once())
219+
->method('create')
220+
->willReturn($coupon);
221+
$coupon->expects($this->once())->method('load')->willReturnSelf();
222+
$coupon->expects($this->once())->method('getId')->willReturn(1);
207223
$this->quote->expects($this->any())
208224
->method('getItemsCount')
209225
->willReturn(1);

app/code/Magento/Cms/Controller/Adminhtml/Page/Save.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,38 @@ class Save extends \Magento\Backend\App\Action
3030
*/
3131
protected $dataPersistor;
3232

33+
/**
34+
* @var \Magento\Cms\Model\PageFactory
35+
*/
36+
private $pageFactory;
37+
38+
/**
39+
* @var \Magento\Cms\Api\PageRepositoryInterface
40+
*/
41+
private $pageRepository;
42+
3343
/**
3444
* @param Action\Context $context
3545
* @param PostDataProcessor $dataProcessor
3646
* @param DataPersistorInterface $dataPersistor
47+
* @param \Magento\Cms\Model\PageFactory $pageFactory
48+
* @param \Magento\Cms\Api\PageRepositoryInterface $pageRepository
49+
*
3750
*/
3851
public function __construct(
3952
Action\Context $context,
4053
PostDataProcessor $dataProcessor,
41-
DataPersistorInterface $dataPersistor
54+
DataPersistorInterface $dataPersistor,
55+
\Magento\Cms\Model\PageFactory $pageFactory = null,
56+
\Magento\Cms\Api\PageRepositoryInterface $pageRepository = null
4257
) {
4358
$this->dataProcessor = $dataProcessor;
4459
$this->dataPersistor = $dataPersistor;
60+
$this->pageFactory = $pageFactory
61+
?: \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Cms\Model\PageFactory::class);
62+
$this->pageRepository = $pageRepository
63+
?: \Magento\Framework\App\ObjectManager::getInstance()
64+
->get(\Magento\Cms\Api\PageRepositoryInterface::class);
4565
parent::__construct($context);
4666
}
4767

@@ -66,7 +86,7 @@ public function execute()
6686
}
6787

6888
/** @var \Magento\Cms\Model\Page $model */
69-
$model = $this->_objectManager->create(\Magento\Cms\Model\Page::class);
89+
$model = $this->pageFactory->create();
7090

7191
$id = $this->getRequest()->getParam('page_id');
7292
if ($id) {
@@ -85,7 +105,7 @@ public function execute()
85105
}
86106

87107
try {
88-
$model->save();
108+
$this->pageRepository->save($model);
89109
$this->messageManager->addSuccess(__('You saved the page.'));
90110
$this->dataPersistor->clear('cms_page');
91111
if ($this->getRequest()->getParam('back')) {

0 commit comments

Comments
 (0)