You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 satır
2.5KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Notification;
  3. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  4. use Lc\SovBundle\Notification\MailMailjetNotification as SovMailMailjetNotification;
  5. use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
  6. use Lc\SovBundle\Repository\Site\SiteStore;
  7. use Lc\SovBundle\Solver\Setting\SettingSolver;
  8. use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
  9. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  10. use Twig\Environment;
  11. class MailMailjetNotification extends SovMailMailjetNotification
  12. {
  13. protected MerchantResolver $merchantResolver;
  14. public function __construct(
  15. MailjetTransport $mailjetTransport,
  16. Environment $templating,
  17. ParameterBagInterface $parameterBag,
  18. SettingSolver $settingSolver,
  19. MerchantResolver $merchantResolver,
  20. SiteStore $siteStore
  21. ) {
  22. parent::__construct($mailjetTransport, $templating, $parameterBag, $settingSolver, $siteStore);
  23. $this->merchantResolver = $merchantResolver;
  24. }
  25. public function send($params = [])
  26. {
  27. $merchantCurrent = $this->merchantResolver->getCurrent();
  28. $merchantConfigEmailFrom = $this->settingSolver->getSettingValue(
  29. $merchantCurrent,
  30. MerchantSettingDefinition::SETTING_EMAIL_FROM
  31. );
  32. $emailFrom = (isset($params[self::FROM_EMAIL]) && $params[self::FROM_EMAIL] && strlen(
  33. $params[self::FROM_EMAIL]
  34. )) ? $params[self::FROM_EMAIL] : $merchantConfigEmailFrom;
  35. $merchantConfigEmailFromName = $this->settingSolver->getSettingValue(
  36. $merchantCurrent,
  37. MerchantSettingDefinition::SETTING_EMAIL_FROM_NAME
  38. );
  39. $emailFromName = isset($params[self::FROM_NAME]) ?? $merchantConfigEmailFromName;
  40. $merchantConfigEmailSubjectPrefix = $this->settingSolver->getSettingValue(
  41. $merchantCurrent,
  42. MerchantSettingDefinition::SETTING_EMAIL_SUBJECT_PREFIX
  43. );
  44. $emailSubjectPrefix = isset($params[self::SUBJECT_PREFIX]) ?? $merchantConfigEmailSubjectPrefix;
  45. if ($emailSubjectPrefix && strlen($emailSubjectPrefix)) {
  46. $emailSubjectPrefix .= ' ';
  47. }
  48. return parent::send(
  49. array_merge($params, [
  50. self::FROM_EMAIL => $emailFrom,
  51. self::FROM_NAME => $emailFromName,
  52. self::SUBJECT_PREFIX => $emailSubjectPrefix
  53. ])
  54. );
  55. }
  56. }