Skip to content

Commit 2cf900d

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-93692' into 2.3-develop
2 parents ace38cd + 203dcd1 commit 2cf900d

File tree

4 files changed

+126
-2
lines changed

4 files changed

+126
-2
lines changed

app/code/Magento/SalesRule/Model/ResourceModel/Rule/Collection.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\SalesRule\Model\ResourceModel\Rule;
88

9+
use Magento\Framework\DB\Select;
910
use Magento\Framework\Serialize\Serializer\Json;
1011
use Magento\Quote\Model\Quote\Address;
1112

@@ -209,7 +210,9 @@ public function setValidationFilter(
209210
$andWhereCondition = implode(' AND ', $andWhereConditions);
210211

211212
$select->where(
212-
$noCouponWhereCondition . ' OR ((' . $orWhereCondition . ') AND ' . $andWhereCondition . ')'
213+
$noCouponWhereCondition . ' OR ((' . $orWhereCondition . ') AND ' . $andWhereCondition . ')',
214+
null,
215+
Select::TYPE_CONDITION
213216
);
214217
} else {
215218
$this->addFieldToFilter(
@@ -320,7 +323,7 @@ public function addAttributeInConditionFilter($attributeCode)
320323
$this->getSelect()->where(
321324
sprintf('(%s OR %s)', $cCond, $aCond),
322325
null,
323-
\Magento\Framework\DB\Select::TYPE_CONDITION
326+
Select::TYPE_CONDITION
324327
);
325328

326329
return $this;

dev/tests/integration/testsuite/Magento/SalesRule/Model/Rule/Action/Discount/CartFixedTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,36 @@ public function applyFixedDiscountDataProvider(): array
9393
];
9494
}
9595

96+
/**
97+
* Tests that coupon with wildcard symbols in code can be successfully applied.
98+
*
99+
* @magentoDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php
100+
*/
101+
public function testCouponCodeWithWildcard()
102+
{
103+
$expectedDiscount = '-5.00';
104+
$couponCode = '2?ds5!2d';
105+
$cartId = $this->cartManagement->createEmptyCart();
106+
$productPrice = 10;
107+
108+
$product = $this->createProduct($productPrice);
109+
110+
/** @var CartItemInterface $quoteItem */
111+
$quoteItem = Bootstrap::getObjectManager()->create(CartItemInterface::class);
112+
$quoteItem->setQuoteId($cartId);
113+
$quoteItem->setProduct($product);
114+
$quoteItem->setQty(1);
115+
$this->cartItemRepository->save($quoteItem);
116+
117+
$this->couponManagement->set($cartId, $couponCode);
118+
119+
/** @var GuestCartTotalRepositoryInterface $cartTotalRepository */
120+
$cartTotalRepository = Bootstrap::getObjectManager()->get(GuestCartTotalRepositoryInterface::class);
121+
$total = $cartTotalRepository->get($cartId);
122+
123+
$this->assertEquals($expectedDiscount, $total->getBaseDiscountAmount());
124+
}
125+
96126
/**
97127
* Returns simple product with given price.
98128
*
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Customer\Model\GroupManagement;
9+
use Magento\SalesRule\Api\CouponRepositoryInterface;
10+
use Magento\SalesRule\Model\Coupon;
11+
use Magento\SalesRule\Model\Rule;
12+
use Magento\Store\Model\StoreManagerInterface;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
15+
$objectManager = Bootstrap::getObjectManager();
16+
17+
/** @var Rule $salesRule */
18+
$salesRule = $objectManager->create(Rule::class);
19+
$salesRule->setData(
20+
[
21+
'name' => '5$ fixed discount on whole cart',
22+
'is_active' => 1,
23+
'customer_group_ids' => [GroupManagement::NOT_LOGGED_IN_ID],
24+
'coupon_type' => Rule::COUPON_TYPE_SPECIFIC,
25+
'conditions' => [],
26+
'simple_action' => Rule::CART_FIXED_ACTION,
27+
'discount_amount' => 5,
28+
'discount_step' => 0,
29+
'stop_rules_processing' => 1,
30+
'website_ids' => [
31+
$objectManager->get(StoreManagerInterface::class)->getWebsite()->getId(),
32+
],
33+
]
34+
);
35+
$objectManager->get(\Magento\SalesRule\Model\ResourceModel\Rule::class)->save($salesRule);
36+
37+
// Create coupon and assign "15$ fixed discount" rule to this coupon.
38+
$coupon = $objectManager->create(Coupon::class);
39+
$coupon->setRuleId($salesRule->getId())
40+
->setCode('2?ds5!2d')
41+
->setType(0);
42+
43+
/** @var CouponRepositoryInterface $couponRepository */
44+
$couponRepository = $objectManager->get(CouponRepositoryInterface::class);
45+
$couponRepository->save($coupon);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Framework\Api\SearchCriteriaBuilder;
9+
use Magento\SalesRule\Api\CouponRepositoryInterface;
10+
use Magento\SalesRule\Api\RuleRepositoryInterface;
11+
use Magento\SalesRule\Model\Coupon;
12+
use Magento\SalesRule\Model\Rule;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
15+
$objectManager = Bootstrap::getObjectManager();
16+
17+
/** @var Rule $salesRule */
18+
$salesRule = getSalesRule('5$ fixed discount on whole cart');
19+
if ($salesRule !== null) {
20+
/** @var RuleRepositoryInterface $ruleRepository */
21+
$ruleRepository = $objectManager->get(RuleRepositoryInterface::class);
22+
$ruleRepository->deleteById($salesRule->getRuleId());
23+
}
24+
25+
$coupon = $objectManager->create(Coupon::class);
26+
$coupon->loadByCode('2?ds5!2d');
27+
if ($coupon->getCouponId()) {
28+
/** @var CouponRepositoryInterface $couponRepository */
29+
$couponRepository = $objectManager->get(CouponRepositoryInterface::class);
30+
$couponRepository->deleteById($coupon->getCouponId());
31+
}
32+
33+
function getSalesRule(string $name)
34+
{
35+
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
36+
$searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class);
37+
$searchCriteria = $searchCriteriaBuilder->addFilter('name', $name)
38+
->create();
39+
40+
/** @var RuleRepositoryInterface $ruleRepository */
41+
$ruleRepository = Bootstrap::getObjectManager()->get(RuleRepositoryInterface::class);
42+
$items = $ruleRepository->getList($searchCriteria)
43+
->getItems();
44+
45+
return array_pop($items);
46+
}

0 commit comments

Comments
 (0)