Allow dynamic genration of coupon code for some newsletters

Those newsletters that allow updating their body html should
persist the couponId along side the Coupon block settings so
that on the next rendering attempt the same coupon code is
used

[MAILPOET-4763]
This commit is contained in:
Sam Najian
2023-01-19 17:27:24 +01:00
committed by Aschepikov
parent 6a14a3f7b1
commit 05e941e449
2 changed files with 10 additions and 4 deletions

View File

@@ -38,6 +38,14 @@ class NewsletterEntity {
const STATUS_SENDING = 'sending';
const STATUS_SENT = 'sent';
/**
* Newsletters that their body HTML can get re-generated
* @see NewsletterSaveController::updateQueue
*/
const TYPES_WITH_RESETTABLE_BODY = [
NewsletterEntity::TYPE_STANDARD,
];
// automatic newsletters status
const STATUS_ACTIVE = 'active';

View File

@@ -155,11 +155,9 @@ class CouponPreProcessor {
}
/**
* For some renders/send outs the coupon id shouldn't be persisted along the coupon block
* This is a placeholder method and should be augmented with more newsletter types that should dynamically get coupons
* and not have one single coupon saved along with the block's settings
* Only emails that can have their body-HTML re-generated should persist the generated couponId
*/
private function shouldPersist(NewsletterEntity $newsletter): bool {
return $newsletter->getType() !== NewsletterEntity::TYPE_AUTOMATIC;
return in_array($newsletter->getType(), NewsletterEntity::TYPES_WITH_RESETTABLE_BODY);
}
}