|
- <?php
-
- namespace Lc\CaracoleBundle\Notification;
-
- use Lc\CaracoleBundle\Resolver\MerchantResolver;
- use Lc\SovBundle\Notification\MailMailjetNotification as SovMailMailjetNotification;
- use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
- use Lc\SovBundle\Repository\Site\SiteStore;
- use Lc\SovBundle\Solver\Setting\SettingSolver;
- use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
- use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
- use Twig\Environment;
-
- class MailMailjetNotification extends SovMailMailjetNotification
- {
- protected MerchantResolver $merchantResolver;
-
- const MERCHANT = 'merchant';
-
- public function __construct(
- MailjetTransport $mailjetTransport,
- Environment $templating,
- ParameterBagInterface $parameterBag,
- SettingSolver $settingSolver,
- MerchantResolver $merchantResolver,
- SiteStore $siteStore
- ) {
- parent::__construct($mailjetTransport, $templating, $parameterBag, $settingSolver, $siteStore);
- $this->merchantResolver = $merchantResolver;
- }
-
- public function send($params = [])
- {
- $merchant = isset($params[self::MERCHANT]) ? $params[self::MERCHANT] : $this->merchantResolver->getCurrent();
-
- $merchantConfigEmailFrom = $this->settingSolver->getSettingValue(
- $merchant,
- MerchantSettingDefinition::SETTING_EMAIL_FROM
- );
- $emailFrom = (isset($params[self::FROM_EMAIL]) && $params[self::FROM_EMAIL] && strlen(
- $params[self::FROM_EMAIL]
- )) ? $params[self::FROM_EMAIL] : $merchantConfigEmailFrom;
-
- $merchantConfigEmailFromName = $this->settingSolver->getSettingValue(
- $merchant,
- MerchantSettingDefinition::SETTING_EMAIL_FROM_NAME
- );
- $emailFromName = isset($params[self::FROM_NAME]) ? $params[self::FROM_NAME] : $merchantConfigEmailFromName;
-
- $merchantConfigEmailSubjectPrefix = $this->settingSolver->getSettingValue(
- $merchant,
- MerchantSettingDefinition::SETTING_EMAIL_SUBJECT_PREFIX
- );
- $emailSubjectPrefix = isset($params[self::SUBJECT_PREFIX]) ? $params[self::SUBJECT_PREFIX] : $merchantConfigEmailSubjectPrefix;
- if ($emailSubjectPrefix && strlen($emailSubjectPrefix)) {
- $emailSubjectPrefix .= ' ';
- }
-
- return parent::send(
- array_merge($params, [
- self::FROM_EMAIL => $emailFrom,
- self::FROM_NAME => $emailFromName,
- self::SUBJECT_PREFIX => $emailSubjectPrefix
- ])
- );
- }
- }
|