Fix duplicate automatic email for same product

[MAILPOET-3254]

It was happening when a second order was placed which contained the same product and some additional product.
This commit is contained in:
wxa
2021-03-25 12:24:22 +03:00
committed by Veljko V
parent 599cfd5a8c
commit dd6aff01db
2 changed files with 40 additions and 7 deletions

View File

@ -128,17 +128,18 @@ class PurchasedProduct {
$schedulingCondition = function(Newsletter $automaticEmail) use ($orderedProducts, $subscriber) {
$meta = $automaticEmail->getMeta();
if (empty($meta['option'])) return false;
if ($this->repository->wasScheduledForSubscriber($automaticEmail->id, $subscriber->id)) {
$sentAllProducts = $this->repository->alreadySentAllProducts($automaticEmail->id, $subscriber->id, 'orderedProducts', $orderedProducts);
if ($sentAllProducts) return false;
}
$metaProducts = array_column($meta['option'], 'id');
$matchedProducts = array_intersect($metaProducts, $orderedProducts);
if (empty($matchedProducts)) return false;
return !empty($matchedProducts);
if ($this->repository->wasScheduledForSubscriber($automaticEmail->id, $subscriber->id)) {
$sentAllProducts = $this->repository->alreadySentAllProducts($automaticEmail->id, $subscriber->id, 'orderedProducts', $matchedProducts);
if ($sentAllProducts) return false;
}
return true;
};
$this->loggerFactory->getLogger(self::SLUG)->addInfo(