Skip to content

Commit 0536a7e

Browse files
ENGCOM-1885: issue/14056 - Coupon API not working for guest user #15320
- Merge Pull Request #15320 from Hypo386/magento2:issue/14056 - Merged commits: 1. 6ad9c03 2. 8b7bb58
2 parents 10f84fd + 8b7bb58 commit 0536a7e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public function set($cartId, $couponCode)
5656
if (!$quote->getItemsCount()) {
5757
throw new NoSuchEntityException(__('Cart %1 doesn\'t contain products', $cartId));
5858
}
59+
if (!$quote->getStoreId()) {
60+
throw new NoSuchEntityException(__('Cart isn\'t assigned to correct store'));
61+
}
5962
$quote->getShippingAddress()->setCollectShippingRates(true);
6063

6164
try {

app/code/Magento/Quote/Test/Unit/Model/CouponManagementTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ protected function setUp()
4949
'save',
5050
'getShippingAddress',
5151
'getCouponCode',
52+
'getStoreId',
5253
'__wakeup'
5354
]);
5455
$this->quoteAddressMock = $this->createPartialMock(\Magento\Quote\Model\Quote\Address::class, [
@@ -100,6 +101,9 @@ public function testSetWhenCouldNotApplyCoupon()
100101
$cartId = 33;
101102
$couponCode = '153a-ABC';
102103

104+
$this->storeMock->expects($this->any())->method('getId')->will($this->returnValue(1));
105+
$this->quoteMock->expects($this->once())->method('getStoreId')->willReturn($this->returnValue(1));
106+
103107
$this->quoteRepositoryMock->expects($this->once())
104108
->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
105109
$this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(12));
@@ -127,6 +131,9 @@ public function testSetWhenCouponCodeIsInvalid()
127131
$cartId = 33;
128132
$couponCode = '153a-ABC';
129133

134+
$this->storeMock->expects($this->any())->method('getId')->will($this->returnValue(1));
135+
$this->quoteMock->expects($this->once())->method('getStoreId')->willReturn($this->returnValue(1));
136+
130137
$this->quoteRepositoryMock->expects($this->once())
131138
->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
132139
$this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(12));
@@ -146,6 +153,9 @@ public function testSet()
146153
$cartId = 33;
147154
$couponCode = '153a-ABC';
148155

156+
$this->storeMock->expects($this->any())->method('getId')->will($this->returnValue(1));
157+
$this->quoteMock->expects($this->once())->method('getStoreId')->willReturn($this->returnValue(1));
158+
149159
$this->quoteRepositoryMock->expects($this->once())
150160
->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
151161
$this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(12));

0 commit comments

Comments
 (0)