Skip to content

Commit 2e4d79e

Browse files
committed
MC-17460: Coupon's expiration date and time do not match staging update end_date after creating a staging update
1 parent 1e58f70 commit 2e4d79e

File tree

8 files changed

+8
-34
lines changed

8 files changed

+8
-34
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public function setTimesUsed($timesUsed);
108108
* Get expiration date
109109
*
110110
* @return string|null
111+
* @deprecated Coupon expiration must follow sales rule expiration date.
111112
*/
112113
public function getExpirationDate();
113114

@@ -116,6 +117,7 @@ public function getExpirationDate();
116117
*
117118
* @param string $expirationDate
118119
* @return $this
120+
* @deprecated Coupon expiration must follow sales rule expiration date.
119121
*/
120122
public function setExpirationDate($expirationDate);
121123

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: 0 additions & 15 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

@@ -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: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ public function testGeneratePool()
109109
'setRuleId',
110110
'setUsageLimit',
111111
'setUsagePerCustomer',
112-
'setExpirationDate',
113112
'setCreatedAt',
114113
'setType',
115114
'setCode',
@@ -120,7 +119,6 @@ public function testGeneratePool()
120119
$couponMock->expects($this->any())->method('setRuleId')->will($this->returnSelf());
121120
$couponMock->expects($this->any())->method('setUsageLimit')->will($this->returnSelf());
122121
$couponMock->expects($this->any())->method('setUsagePerCustomer')->will($this->returnSelf());
123-
$couponMock->expects($this->any())->method('setExpirationDate')->will($this->returnSelf());
124122
$couponMock->expects($this->any())->method('setCreatedAt')->will($this->returnSelf());
125123
$couponMock->expects($this->any())->method('setType')->will($this->returnSelf());
126124
$couponMock->expects($this->any())->method('setCode')->will($this->returnSelf());

0 commit comments

Comments
 (0)