Skip to content

Commit 7e270ea

Browse files
author
Oleksandr Dubovyk
committed
Merge remote-tracking branch 'mpi/MC-17460' into pr_23_shtdwn
2 parents 643e6c4 + 52e1769 commit 7e270ea

File tree

12 files changed

+19
-118
lines changed

12 files changed

+19
-118
lines changed

app/code/Magento/SalesRule/Api/Data/CouponInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public function setUsagePerCustomer($usagePerCustomer);
9999
public function getTimesUsed();
100100

101101
/**
102+
* Set time used.
103+
*
102104
* @param int $timesUsed
103105
* @return $this
104106
*/
@@ -108,6 +110,7 @@ public function setTimesUsed($timesUsed);
108110
* Get expiration date
109111
*
110112
* @return string|null
113+
* @deprecated Coupon expiration must follow sales rule expiration date.
111114
*/
112115
public function getExpirationDate();
113116

@@ -116,6 +119,7 @@ public function getExpirationDate();
116119
*
117120
* @param string $expirationDate
118121
* @return $this
122+
* @deprecated Coupon expiration must follow sales rule expiration date.
119123
*/
120124
public function setExpirationDate($expirationDate);
121125

@@ -158,6 +162,8 @@ public function setCreatedAt($createdAt);
158162
public function getType();
159163

160164
/**
165+
* Set type of coupon.
166+
*
161167
* @param int $type
162168
* @return $this
163169
*/

app/code/Magento/SalesRule/Model/Coupon.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Coupon extends \Magento\Framework\Model\AbstractExtensibleModel implements
2020
const KEY_USAGE_LIMIT = 'usage_limit';
2121
const KEY_USAGE_PER_CUSTOMER = 'usage_per_customer';
2222
const KEY_TIMES_USED = 'times_used';
23+
/**
24+
* @deprecated Coupon expiration must follow sales rule expiration date.
25+
*/
2326
const KEY_EXPIRATION_DATE = 'expiration_date';
2427
const KEY_IS_PRIMARY = 'is_primary';
2528
const KEY_CREATED_AT = 'created_at';
@@ -204,6 +207,7 @@ public function setTimesUsed($timesUsed)
204207
* Get expiration date
205208
*
206209
* @return string|null
210+
* @deprecated Coupon expiration must follow sales rule expiration date.
207211
*/
208212
public function getExpirationDate()
209213
{
@@ -215,6 +219,7 @@ public function getExpirationDate()
215219
*
216220
* @param string $expirationDate
217221
* @return $this
222+
* @deprecated Coupon expiration must follow sales rule expiration date.
218223
*/
219224
public function setExpirationDate($expirationDate)
220225
{

app/code/Magento/SalesRule/Model/Coupon/Massgenerator.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,10 @@ public function generatePool()
168168
++$attempt;
169169
} while ($this->getResource()->exists($code));
170170

171-
$expirationDate = $this->getToDate();
172-
if ($expirationDate instanceof \DateTimeInterface) {
173-
$expirationDate = $expirationDate->format('Y-m-d H:i:s');
174-
}
175-
176171
$coupon->setId(null)
177172
->setRuleId($this->getRuleId())
178173
->setUsageLimit($this->getUsesPerCoupon())
179174
->setUsagePerCustomer($this->getUsagePerCustomer())
180-
->setExpirationDate($expirationDate)
181175
->setCreatedAt($nowTimestamp)
182176
->setType(\Magento\SalesRule\Helper\Coupon::COUPON_TYPE_SPECIFIC_AUTOGENERATED)
183177
->setCode($code)

app/code/Magento/SalesRule/Model/CouponRepository.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ public function save(\Magento\SalesRule\Api\Data\CouponInterface $coupon)
118118
__('Specified rule does not allow auto generated coupons')
119119
);
120120
}
121-
$coupon->setExpirationDate($rule->getToDate());
122121
$coupon->setUsageLimit($rule->getUsesPerCoupon());
123122
$coupon->setUsagePerCustomer($rule->getUsesPerCustomer());
124123
} catch (\Exception $e) {

app/code/Magento/SalesRule/Model/ResourceModel/Coupon.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ protected function _construct()
3434
*/
3535
public function _beforeSave(AbstractModel $object)
3636
{
37-
if (!$object->getExpirationDate()) {
38-
$object->setExpirationDate(null);
39-
} elseif ($object->getExpirationDate() instanceof \DateTimeInterface) {
40-
$object->setExpirationDate(
41-
$object->getExpirationDate()->format('Y-m-d H:i:s')
42-
);
43-
}
44-
4537
// maintain single primary coupon per rule
4638
$object->setIsPrimary($object->getIsPrimary() ? 1 : null);
4739

@@ -51,10 +43,10 @@ public function _beforeSave(AbstractModel $object)
5143
/**
5244
* Load primary coupon (is_primary = 1) for specified rule
5345
*
54-
*
5546
* @param \Magento\SalesRule\Model\Coupon $object
5647
* @param \Magento\SalesRule\Model\Rule|int $rule
5748
* @return bool
49+
* @throws \Magento\Framework\Exception\LocalizedException
5850
*/
5951
public function loadPrimaryByRule(\Magento\SalesRule\Model\Coupon $object, $rule)
6052
{
@@ -126,13 +118,6 @@ public function updateSpecificCoupons(\Magento\SalesRule\Model\Rule $rule)
126118
$updateArray['usage_per_customer'] = $rule->getUsesPerCustomer();
127119
}
128120

129-
$ruleNewDate = new \DateTime($rule->getToDate());
130-
$ruleOldDate = new \DateTime($rule->getOrigData('to_date'));
131-
132-
if ($ruleNewDate != $ruleOldDate) {
133-
$updateArray['expiration_date'] = $rule->getToDate();
134-
}
135-
136121
if (!empty($updateArray)) {
137122
$this->getConnection()->update(
138123
$this->getTable('salesrule_coupon'),

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,6 @@ private function getCouponCodeSelect($couponCode)
231231

232232
$this->joinCouponTable($couponCode, $couponSelect);
233233

234-
$notExpired = $this->getConnection()->quoteInto(
235-
'(rule_coupons.expiration_date IS NULL OR rule_coupons.expiration_date >= ?)',
236-
$this->_date->date()->format('Y-m-d')
237-
);
238-
239234
$isAutogenerated =
240235
$this->getConnection()->quoteInto('main_table.coupon_type = ?', Rule::COUPON_TYPE_AUTO)
241236
. ' AND ' .
@@ -250,7 +245,7 @@ private function getCouponCodeSelect($couponCode)
250245
. ')';
251246

252247
$couponSelect->where(
253-
"$notExpired AND ($isAutogenerated OR $isValidSpecific)",
248+
"$isAutogenerated OR $isValidSpecific",
254249
null,
255250
Select::TYPE_CONDITION
256251
);

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,6 @@ public function afterSave()
296296
$this->getUsesPerCoupon() ? $this->getUsesPerCoupon() : null
297297
)->setUsagePerCustomer(
298298
$this->getUsesPerCustomer() ? $this->getUsesPerCustomer() : null
299-
)->setExpirationDate(
300-
$this->getToDate()
301299
)->save();
302300
} else {
303301
$this->getPrimaryCoupon()->delete();
@@ -498,8 +496,6 @@ public function acquireCoupon($saveNewlyCreated = true, $saveAttemptCount = 10)
498496
$this->getUsesPerCoupon() ? $this->getUsesPerCoupon() : null
499497
)->setUsagePerCustomer(
500498
$this->getUsesPerCustomer() ? $this->getUsesPerCustomer() : null
501-
)->setExpirationDate(
502-
$this->getToDate()
503499
)->setType(
504500
\Magento\SalesRule\Api\Data\CouponInterface::TYPE_GENERATED
505501
);

app/code/Magento/SalesRule/Test/Unit/Model/Coupon/MassgeneratorTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class MassgeneratorTest extends \PHPUnit\Framework\TestCase
2323
protected function setUp()
2424
{
2525
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
26-
$this->charset = str_split(md5((string)time()));
26+
$this->charset = str_split(sha1((string)time()));
2727
}
2828

2929
/**
@@ -103,24 +103,25 @@ public function testGeneratePool()
103103
$dateMock = $this->createPartialMock(\Magento\Framework\Stdlib\DateTime\DateTime::class, ['gmtTimestamp']);
104104
$dateTimeMock = $this->createPartialMock(\Magento\Framework\Stdlib\DateTime::class, ['formatDate']);
105105
$couponFactoryMock = $this->createPartialMock(\Magento\SalesRule\Model\CouponFactory::class, ['create']);
106-
$couponMock = $this->createPartialMock(\Magento\SalesRule\Model\Coupon::class, [
106+
$couponMock = $this->createPartialMock(
107+
\Magento\SalesRule\Model\Coupon::class,
108+
[
107109
'__wakeup',
108110
'setId',
109111
'setRuleId',
110112
'setUsageLimit',
111113
'setUsagePerCustomer',
112-
'setExpirationDate',
113114
'setCreatedAt',
114115
'setType',
115116
'setCode',
116117
'save'
117-
]);
118+
]
119+
);
118120

119121
$couponMock->expects($this->any())->method('setId')->will($this->returnSelf());
120122
$couponMock->expects($this->any())->method('setRuleId')->will($this->returnSelf());
121123
$couponMock->expects($this->any())->method('setUsageLimit')->will($this->returnSelf());
122124
$couponMock->expects($this->any())->method('setUsagePerCustomer')->will($this->returnSelf());
123-
$couponMock->expects($this->any())->method('setExpirationDate')->will($this->returnSelf());
124125
$couponMock->expects($this->any())->method('setCreatedAt')->will($this->returnSelf());
125126
$couponMock->expects($this->any())->method('setType')->will($this->returnSelf());
126127
$couponMock->expects($this->any())->method('setCode')->will($this->returnSelf());

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/ApplyCouponToCartTest.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -162,25 +162,6 @@ public function testApplyCouponToNonExistentCart()
162162
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
163163
}
164164

165-
/**
166-
* @magentoApiDataFixture Magento/Checkout/_files/discount_10percent_generalusers.php
167-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
168-
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
169-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
170-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
171-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/make_coupon_expired.php
172-
* @expectedException \Exception
173-
* @expectedExceptionMessage The coupon code isn't valid. Verify the code and try again.
174-
*/
175-
public function testApplyExpiredCoupon()
176-
{
177-
$couponCode = '2?ds5!2d';
178-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
179-
$query = $this->getQuery($maskedQuoteId, $couponCode);
180-
181-
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
182-
}
183-
184165
/**
185166
* Products in cart don't fit to the coupon
186167
*

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/ApplyCouponToCartTest.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,24 +128,6 @@ public function testApplyCouponToNonExistentCart()
128128
$this->graphQlMutation($query);
129129
}
130130

131-
/**
132-
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
133-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
134-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
135-
* @magentoApiDataFixture Magento/SalesRule/_files/coupon_code_with_wildcard.php
136-
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/make_coupon_expired.php
137-
* @expectedException \Exception
138-
* @expectedExceptionMessage The coupon code isn't valid. Verify the code and try again.
139-
*/
140-
public function testApplyExpiredCoupon()
141-
{
142-
$couponCode = '2?ds5!2d';
143-
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
144-
$query = $this->getQuery($maskedQuoteId, $couponCode);
145-
146-
$this->graphQlMutation($query);
147-
}
148-
149131
/**
150132
* Products in cart don't fit to the coupon
151133
*

0 commit comments

Comments
 (0)