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, bool $addLinkOrderWhenNoDistribution = false ): Email { $linkProducer = ''; if($producer) { $linkProducer = 'https://'.$producer->slug.'.souke.fr'; } $messageAutoText = '' ; $messageAutoHtml = '' ; $messageAutoHtml .= ' '; if($distribution) { $messageAutoText = ' ' ; $messageAutoHtml .= '

' ; $linkOrder = $linkProducer.'/order/order?date='.$distribution->date; $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 :
' ; } } } else { if($addLinkOrderWhenNoDistribution) { $linkOrder = $linkProducer.'/order/order'; $messageAutoHtml .= 'Passer ma commande' ; $messageAutoText .= 'Suivez ce lien pour passer votre commande : '.$linkOrder ; } } if($producer) { $fromEmail = $this->producerSolver->getProducerEmailPlatform($producer) ; $fromName = $producer->name ; $linkUnsubscribe = $linkProducer.'/newsletter/index'; // Message inscription newsletter $messageAutoText .= " -- Aller sur la boutique : ".$linkProducer." Se désinscrire de l'infolettre : ".$linkUnsubscribe; $messageAutoHtml .= "

--
"; $messageAutoHtml .= "Aller sur la boutique : ".$linkProducer."
"; $messageAutoHtml .= "Se désinscrire de l'infolettre : ".$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 ); } }