Skip to content

Commit 5608e8e

Browse files
author
Yuri Kovsher
committed
MAGETWO-33814: Change parent class of Model\Exception sub-classes to Localized
1 parent 35d3fcc commit 5608e8e

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

app/code/Magento/Wishlist/Controller/Index/Cart.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,11 @@ public function execute()
166166
$redirectUrl = $refererUrl;
167167
}
168168
}
169-
} catch (\Magento\Framework\Model\Exception $e) {
170-
if ($e->getCode() == \Magento\Wishlist\Model\Item::EXCEPTION_CODE_NOT_SALABLE) {
171-
$this->messageManager->addError(__('This product(s) is out of stock.'));
172-
} elseif ($e->getCode() == \Magento\Wishlist\Model\Item::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS) {
173-
$this->messageManager->addNotice($e->getMessage());
174-
$redirectUrl = $configureUrl;
175-
} else {
176-
$this->messageManager->addNotice($e->getMessage());
177-
$redirectUrl = $configureUrl;
178-
}
169+
} catch (\Magento\Framework\Exception\Product\NotSalableException $e) {
170+
$this->messageManager->addError(__('This product(s) is out of stock.'));
171+
} catch (\Magento\Framework\Exception\LocalizedException $e) {
172+
$this->messageManager->addNotice($e->getMessage());
173+
$redirectUrl = $configureUrl;
179174
} catch (\Exception $e) {
180175
$this->messageManager->addException($e, __('Cannot add item to shopping cart'));
181176
}

app/code/Magento/Wishlist/Model/Item.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public function getProduct()
400400
* @param \Magento\Checkout\Model\Cart $cart
401401
* @param bool $delete delete the item after successful add to cart
402402
* @return bool
403-
* @throws \Magento\Framework\Model\Exception
403+
* @throws \Magento\Framework\Exception\Product\NotSalableException
404404
*/
405405
public function addToCart(\Magento\Checkout\Model\Cart $cart, $delete = false)
406406
{
@@ -428,7 +428,7 @@ public function addToCart(\Magento\Checkout\Model\Cart $cart, $delete = false)
428428
}
429429

430430
if (!$product->isSalable()) {
431-
throw new \Magento\Framework\Model\Exception(null, self::EXCEPTION_CODE_NOT_SALABLE);
431+
throw new \Magento\Framework\Exception\Product\NotSalableException(null);
432432
}
433433

434434
$buyRequest = $this->getBuyRequest();

dev/tests/unit/testsuite/Magento/Wishlist/Controller/Index/CartTest.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,7 @@ public function testExecuteWithoutQuantityArrayAndOutOfStock()
625625
$itemMock->expects($this->once())
626626
->method('addToCart')
627627
->with($this->checkoutCartMock, true)
628-
->willThrowException(
629-
new \Magento\Framework\Model\Exception(null, \Magento\Wishlist\Model\Item::EXCEPTION_CODE_NOT_SALABLE)
630-
);
628+
->willThrowException(new \Magento\Framework\Exception\Product\NotSalableException(null));
631629

632630
$this->messageManagerMock->expects($this->once())
633631
->method('addError')
@@ -788,12 +786,7 @@ public function testExecuteWithoutQuantityArrayAndConfigurable()
788786
$itemMock->expects($this->once())
789787
->method('addToCart')
790788
->with($this->checkoutCartMock, true)
791-
->willThrowException(
792-
new \Magento\Framework\Model\Exception(
793-
'message',
794-
\Magento\Wishlist\Model\Item::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS
795-
)
796-
);
789+
->willThrowException(new \Magento\Framework\Exception\LocalizedException('message'));
797790

798791
$this->messageManagerMock->expects($this->once())
799792
->method('addNotice')
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Exception\Product;
7+
8+
use Magento\Framework\Exception\LocalizedException;
9+
10+
class NotSalableException extends LocalizedException
11+
{
12+
}

0 commit comments

Comments
 (0)