Skip to content

Commit f9be9cd

Browse files
authored
Align renewal notification meta key with 14-day default
1 parent 378b6bd commit f9be9cd

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/Subscriptions/SubscriptionsNotificationsController.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ private function meets_notification_requirements( Subscription $subscription ) {
148148
* If a notification has already been sent in the past 2 weeks, it no longer
149149
* makes sense to send a notification.
150150
*/
151-
$notification_date_string = $subscription->get_meta( 'notification_date_1_week' );
151+
$notification_date_string = $subscription->get_meta( 'notification_date_renewal' );
152+
153+
if ( empty( $notification_date_string ) ) {
154+
$notification_date_string = $subscription->get_meta( 'notification_date_1_week' );
155+
}
152156

153157
if ( $notification_date_string ) {
154158
$notification_date = new DateTime( $notification_date_string );
@@ -251,7 +255,10 @@ public function send_subscription_renewal_notification( Subscription $subscripti
251255
*/
252256
\do_action( 'pronamic_subscription_renewal_notice_' . $source, $subscription );
253257

254-
$subscription->set_meta( 'notification_date_1_week', \gmdate( DATE_ATOM ) );
258+
$notification_date = \gmdate( DATE_ATOM );
259+
260+
$subscription->set_meta( 'notification_date_renewal', $notification_date );
261+
$subscription->set_meta( 'notification_date_1_week', $notification_date );
255262
}
256263

257264
/**

tests/src/Subscriptions/SubscriptionsNotificationsControllerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ public function test_no_notification_within_2_weeks() {
9292

9393
$phase = new SubscriptionPhase(
9494
$subscription,
95-
new \DateTime( '-1 week midnight', new \DateTimeZone( 'GMT' ) ),
95+
new \DateTime( '-3 weeks midnight', new \DateTimeZone( 'GMT' ) ),
9696
new SubscriptionInterval( 'P1M' ),
9797
new Money( '10', 'EUR' )
9898
);
9999

100100
$subscription->add_phase( $phase );
101-
$subscription->set_meta( 'notification_date_1_week', \gmdate( DATE_ATOM, \strtotime( '-8 days' ) ) );
101+
$subscription->set_meta( 'notification_date_renewal', \gmdate( DATE_ATOM, \strtotime( '-8 days' ) ) );
102102
$subscription->save();
103103

104104
$notifications_controller->send_subscription_renewal_notification( $subscription );

0 commit comments

Comments
 (0)