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 :