Skip to content

Commit

Permalink
- updated email SendProcessor to do not send emails or try to send em…
Browse files Browse the repository at this point in the history
…ails when the recipients array is empty

- updated validation groups for the Order entity to be able to save Orders without a Customer for the commerce group
  • Loading branch information
24198 committed Jun 5, 2020
1 parent c9bb1d0 commit e2a0f48
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
25 changes: 25 additions & 0 deletions src/Marello/Bundle/NotificationBundle/Email/SendProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public function sendNotification($templateName, array $recipients, $entity, arra
)
);
}

if ($this->recipientsNullOrEmpty($recipients)) {
return;
}

$emailModel = $this->emailTemplateManager->getLocalizedModel($template, $entity);
if (null === $emailModel) {
$emailModel = $this->createEmailModel($template);
Expand Down Expand Up @@ -240,4 +245,24 @@ private function getTemplateContentType(EmailTemplateInterface $emailTemplate)
? EmailTemplateModel::CONTENT_TYPE_HTML
: EmailTemplateModel::CONTENT_TYPE_TEXT;
}

/**
* check if recipients are available for sending out the email notification
* @param array $recipients
* @return bool
*/
private function recipientsNullOrEmpty(array $recipients)
{
if (empty($recipients)) {
return true;
}

foreach ($recipients as $recipient) {
if (null === $recipient) {
return true;
}
}

return false;
}
}
16 changes: 8 additions & 8 deletions src/Marello/Bundle/OrderBundle/Resources/config/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ Marello\Bundle\OrderBundle\Entity\OrderItem:
Marello\Bundle\OrderBundle\Entity\Order:
properties:
customer:
- NotBlank: ~
- NotBlank: { groups: [Default] }
salesChannel:
- NotBlank: ~
- NotBlank: { groups: [Default, commerce] }
paymentMethod:
- NotBlank: ~
- NotBlank: { groups: [Default, commerce] }
shippingMethod:
- NotBlank: ~
- NotBlank: { groups: [Default, commerce] }
billingAddress:
- NotBlank:
message: 'marello.order.address.validation.billing_not_blank'
- NotBlank: { groups: [Default, commerce], message: 'marello.order.address.validation.billing_not_blank' }

shippingAddress:
- NotBlank:
message: 'marello.order.address.validation.shipping_not_blank'
- NotBlank: { groups: [Default, commerce], message: 'marello.order.address.validation.shipping_not_blank' }

0 comments on commit e2a0f48

Please sign in to comment.