Skip to content

Commit b9e15e2

Browse files
committed
ACP2E-2428: Coupon code whitespace issue in checkout page
- trimming coupon codes before adding to quote
1 parent cacc2ad commit b9e15e2

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function set($cartId, $couponCode)
5757
{
5858
/** @var $quoteIdMask QuoteIdMask */
5959
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
60-
return $this->couponManagement->set($quoteIdMask->getQuoteId(), $couponCode);
60+
return $this->couponManagement->set($quoteIdMask->getQuoteId(), trim($couponCode));
6161
}
6262

6363
/**

app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected function setUp(): void
5656
$objectManager = new ObjectManager($this);
5757
$this->couponManagementMock = $this->getMockForAbstractClass(CouponManagementInterface::class);
5858

59-
$this->couponCode = 'test_coupon_code';
59+
$this->couponCode = ' test_coupon_code';
6060
$this->maskedCartId = 'f216207248d65c789b17be8545e0aa73';
6161
$this->cartId = 123;
6262

@@ -83,7 +83,10 @@ public function testGet()
8383

8484
public function testSet()
8585
{
86-
$this->couponManagementMock->expects($this->once())->method('set')->willReturn(true);
86+
$this->couponManagementMock->expects($this->once())
87+
->method('set')
88+
->with($this->cartId, trim($this->couponCode))
89+
->willReturn(true);
8790
$this->assertTrue($this->model->set($this->maskedCartId, $this->couponCode));
8891
}
8992

app/code/Magento/SalesRule/view/frontend/web/js/view/payment/discount.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ define([
6060
*/
6161
validate: function () {
6262
var form = '#discount-form';
63-
63+
$(form + " input[type='text']").each(function () {
64+
$(this).val($(this).val().trim());
65+
})
6466
return $(form).validation() && $(form).validation('isValid');
6567
}
6668
});

0 commit comments

Comments
 (0)