|
|
@@ -52,6 +52,7 @@ class MailForm extends Model |
|
|
|
public $id_distribution ; |
|
|
|
public $subject; |
|
|
|
public $message; |
|
|
|
public $integrate_product_list = false; |
|
|
|
|
|
|
|
/** |
|
|
|
* @inheritdoc |
|
|
@@ -60,6 +61,7 @@ class MailForm extends Model |
|
|
|
{ |
|
|
|
return [ |
|
|
|
[['subject', 'message'], 'required', 'message' => 'Champs obligatoire'], |
|
|
|
[['integrate_product_list'], 'boolean'], |
|
|
|
[['id_distribution'],'integer'] |
|
|
|
]; |
|
|
|
} |
|
|
@@ -72,7 +74,8 @@ class MailForm extends Model |
|
|
|
return [ |
|
|
|
'subject' => 'Sujet', |
|
|
|
'message' => 'Message', |
|
|
|
'id_distribution' => 'Distribution' |
|
|
|
'id_distribution' => 'Distribution', |
|
|
|
'integrate_product_list' => 'Intégrer la liste des produits au message' |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
@@ -111,42 +114,44 @@ class MailForm extends Model |
|
|
|
$messageAutoHtml .= '<a href="'.$linkOrder.'">Passer ma commande du '.$dateOrder.'</a>' ; |
|
|
|
$messageAutoText .= 'Suivez ce lien pour passer votre commande du '.$dateOrder.' : |
|
|
|
'.$linkOrder ; |
|
|
|
|
|
|
|
$productsArray = Product::find() |
|
|
|
->where([ |
|
|
|
'id_producer' => GlobalParam::getCurrentProducerId(), |
|
|
|
]) |
|
|
|
->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) > 1) { |
|
|
|
$messageAutoHtml .= '<br /><br />Produits disponibles : <br /><ul>' ; |
|
|
|
$messageAutoText .= ' |
|
|
|
|
|
|
|
if($this->integrate_product_list) { |
|
|
|
$productsArray = Product::find() |
|
|
|
->where([ |
|
|
|
'id_producer' => GlobalParam::getCurrentProducerId(), |
|
|
|
]) |
|
|
|
->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) > 1) { |
|
|
|
$messageAutoHtml .= '<br /><br />Produits disponibles : <br /><ul>' ; |
|
|
|
$messageAutoText .= ' |
|
|
|
|
|
|
|
Produits disponibles : |
|
|
|
' ; |
|
|
|
foreach($productsArray as $product) { |
|
|
|
|
|
|
|
$productDescription = $product->name ; |
|
|
|
if(strlen($product->description)) { |
|
|
|
$productDescription .= ' / '.$product->description ; |
|
|
|
} |
|
|
|
if($product->price) { |
|
|
|
$productDescription .= ' / '.Price::format($product->getPriceWithTax()) ; |
|
|
|
$productDescription .= ' ('.Product::strUnit($product->unit, 'wording_unit').')' ; |
|
|
|
} |
|
|
|
|
|
|
|
$messageAutoText .= '- '.$productDescription.' |
|
|
|
foreach($productsArray as $product) { |
|
|
|
|
|
|
|
$productDescription = $product->name ; |
|
|
|
if(strlen($product->description)) { |
|
|
|
$productDescription .= ' / '.$product->description ; |
|
|
|
} |
|
|
|
if($product->price) { |
|
|
|
$productDescription .= ' / '.Price::format($product->getPriceWithTax()) ; |
|
|
|
$productDescription .= ' ('.Product::strUnit($product->unit, 'wording_unit').')' ; |
|
|
|
} |
|
|
|
|
|
|
|
$messageAutoText .= '- '.$productDescription.' |
|
|
|
' ; |
|
|
|
$messageAutoHtml .= '<li>'.Html::encode($productDescription).'</li>' ; |
|
|
|
$messageAutoHtml .= '<li>'.Html::encode($productDescription).'</li>' ; |
|
|
|
} |
|
|
|
$messageAutoHtml .= '</ul>' ; |
|
|
|
} |
|
|
|
$messageAutoHtml .= '</ul>' ; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@@ -160,7 +165,12 @@ Produits disponibles : |
|
|
|
$fromEmail = 'contact@opendistrib.net' ; |
|
|
|
$fromName = 'Opendistrib' ; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tests |
|
|
|
/*$usersArray = [ |
|
|
|
['email' => '', 'name' => '', 'lastname' => ''] |
|
|
|
];*/ |
|
|
|
|
|
|
|
foreach($usersArray as $user) { |
|
|
|
$body['Messages'][] = [ |
|
|
|
'From' => [ |