Skip to content

Commit a225a11

Browse files
author
Stanislav Idolov
authored
ENGCOM-2201: issue/14056 - Coupon API not working for guest user #16562
2 parents e0a3b0e + 456a24c commit a225a11

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
@@ -55,6 +55,9 @@ public function set($cartId, $couponCode)
5555
if (!$quote->getItemsCount()) {
5656
throw new NoSuchEntityException(__('The "%1" Cart doesn\'t contain products.', $cartId));
5757
}
58+
if (!$quote->getStoreId()) {
59+
throw new NoSuchEntityException(__('Cart isn\'t assigned to correct store'));
60+
}
5861
$quote->getShippingAddress()->setCollectShippingRates(true);
5962

6063
try {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ protected function setUp()
4747
'save',
4848
'getShippingAddress',
4949
'getCouponCode',
50+
'getStoreId',
5051
'__wakeup'
5152
]);
5253
$this->quoteAddressMock = $this->createPartialMock(\Magento\Quote\Model\Quote\Address::class, [
@@ -98,6 +99,9 @@ public function testSetWhenCouldNotApplyCoupon()
9899
$cartId = 33;
99100
$couponCode = '153a-ABC';
100101

102+
$this->storeMock->expects($this->any())->method('getId')->will($this->returnValue(1));
103+
$this->quoteMock->expects($this->once())->method('getStoreId')->willReturn($this->returnValue(1));
104+
101105
$this->quoteRepositoryMock->expects($this->once())
102106
->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
103107
$this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(12));
@@ -125,6 +129,9 @@ public function testSetWhenCouponCodeIsInvalid()
125129
$cartId = 33;
126130
$couponCode = '153a-ABC';
127131

132+
$this->storeMock->expects($this->any())->method('getId')->will($this->returnValue(1));
133+
$this->quoteMock->expects($this->once())->method('getStoreId')->willReturn($this->returnValue(1));
134+
128135
$this->quoteRepositoryMock->expects($this->once())
129136
->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
130137
$this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(12));
@@ -144,6 +151,9 @@ public function testSet()
144151
$cartId = 33;
145152
$couponCode = '153a-ABC';
146153

154+
$this->storeMock->expects($this->any())->method('getId')->will($this->returnValue(1));
155+
$this->quoteMock->expects($this->once())->method('getStoreId')->willReturn($this->returnValue(1));
156+
147157
$this->quoteRepositoryMock->expects($this->once())
148158
->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
149159
$this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(12));

0 commit comments

Comments
 (0)