'Champs obligatoire'],
[['integrate_product_list'], 'boolean'],
[['id_distribution'],'integer']
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'subject' => 'Sujet',
'message' => 'Message',
'id_distribution' => 'Distribution',
'integrate_product_list' => 'Intégrer la liste des produits au message'
];
}
/**
* Envoie un email aux utilisateurs définis en paramètre.
*
* @param array $usersArray
* @param boolean $fromProducer
*/
public function sendEmail($usersArray, $fromProducer = true)
{
$productManager = ProductManager::getInstance();
$producerManager = ProducerManager::getInstance();
$mj = new \Mailjet\Client(
Mailjet::getApiKey('public'),
Mailjet::getApiKey('private'),
true,
['version' => 'v3.1']
);
$body = ['Messages' => []] ;
$messageAutoText = '' ;
$messageAutoHtml = '' ;
if($this->id_distribution) {
$messageAutoText = '
' ;
$messageAutoHtml = '
' ;
$distribution = Distribution::searchOne(['id' => $this->id_distribution]) ;
if($distribution) {
$linkOrder = Yii::$app->urlManagerProducer->createAbsoluteUrl(['order/order','slug_producer' => GlobalParam::getCurrentProducer()->slug, '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($this->integrate_product_list) {
$productsArray = Product::find()
->where([
'id_producer' => GlobalParam::getCurrentProducerId(),
])
->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) > 1) {
$messageAutoHtml .= '
Produits disponibles :