選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

MailMailjetNotification.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. }