emailBuilder = $this->loadService(EmailBuilder::class); $this->productSolver = $this->loadService(ProductSolver::class); $this->distributionSolver = $this->loadService(DistributionSolver::class); $this->producerSolver = $this->loadService(ProducerSolver::class); } public function createEmail( string $subject, string $message, bool $integrateProductList, Producer $producer = null, Distribution $distribution = null ): Email { $messageAutoText = '' ; $messageAutoHtml = '' ; $messageAutoHtml .= ' '; if($distribution) { $messageAutoText = ' ' ; $messageAutoHtml .= '

' ; $linkOrder = $this->distributionSolver->getLinkOrder($distribution); $dateOrder = strftime('%A %d %B %Y', strtotime($distribution->date)) ; $messageAutoHtml .= 'Passer ma commande du '.$dateOrder.'' ; $messageAutoText .= 'Suivez ce lien pour passer votre commande du '.$dateOrder.' : '.$linkOrder ; if($integrateProductList) { $productsArray = Product::find() ->where([ 'id_producer' => $producer->id, ]) ->andWhere('status >= :status') ->addParams(['status' => Product::STATUS_OFFLINE]) ->innerJoinWith(['productDistribution' => function($query) use($distribution) { $query->andOnCondition([ 'product_distribution.id_distribution' => $distribution->id, 'product_distribution.active' => 1 ]); }]) ->orderBy('product.name ASC') ->all(); if(count($productsArray) > 0) { $messageAutoHtml .= '

Produits disponibles :
' ; } } } if($producer) { $fromEmail = $this->producerSolver->getProducerEmailPlatform($producer) ; $fromName = $producer->name ; $linkProducer = 'https://'.$producer->slug.'.souke.fr'; $linkUnsubscribe = \Yii::$app->urlManagerProducer->createAbsoluteUrl(['newsletter/unsubscribe', 'slug_producer' => $producer->slug]); // Message inscription newsletter $messageAutoText .= " -- Boutique : ".$linkProducer." Me désinscrire : ".$linkUnsubscribe; $messageAutoHtml .= "

--
"; $messageAutoHtml .= "Boutique : ".$linkProducer."
"; $messageAutoHtml .= "Me désinscrire : ".$linkUnsubscribe.""; } else { $fromEmail = 'contact@souke.fr' ; $fromName = 'Souke' ; } $htmlContent = $message.$messageAutoHtml; $textContent = strip_tags($message).$messageAutoText; return $this->emailBuilder->instanciateEmail( $fromName, $fromEmail, $subject, $htmlContent, $textContent ); } }