|
|
|
|
|
|
|
|
|
|
|
|
|
|
use Yii; |
|
|
use Yii; |
|
|
use yii\base\Model; |
|
|
use yii\base\Model; |
|
|
|
|
|
use common\helpers\Price ; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* ContactForm is the model behind the contact form. |
|
|
* ContactForm is the model behind the contact form. |
|
|
|
|
|
|
|
|
class MailForm extends Model |
|
|
class MailForm extends Model |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
public $id_distribution ; |
|
|
public $subject; |
|
|
public $subject; |
|
|
public $message; |
|
|
public $message; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
return [ |
|
|
return [ |
|
|
[['subject', 'message'], 'required', 'message' => 'Champs obligatoire'], |
|
|
[['subject', 'message'], 'required', 'message' => 'Champs obligatoire'], |
|
|
|
|
|
[['id_distribution'],'integer'] |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return [ |
|
|
return [ |
|
|
'subject' => 'Sujet', |
|
|
'subject' => 'Sujet', |
|
|
'message' => 'Message', |
|
|
'message' => 'Message', |
|
|
|
|
|
'id_distribution' => 'Distribution' |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$body = ['Messages' => []] ; |
|
|
$body = ['Messages' => []] ; |
|
|
|
|
|
|
|
|
|
|
|
$messageAutoText = '' ; |
|
|
|
|
|
$messageAutoHtml = '' ; |
|
|
|
|
|
if($this->id_distribution) { |
|
|
|
|
|
|
|
|
|
|
|
$messageAutoText = ' |
|
|
|
|
|
|
|
|
|
|
|
' ; |
|
|
|
|
|
$messageAutoHtml = '<br /><br />' ; |
|
|
|
|
|
|
|
|
|
|
|
$distribution = Distribution::searchOne(['id' => $this->id_distribution]) ; |
|
|
|
|
|
|
|
|
|
|
|
if($distribution) { |
|
|
|
|
|
|
|
|
|
|
|
$linkOrder = Yii::$app->urlManagerProducer->createAbsoluteUrl(['order/order','slug_producer' => Producer::getCurrent()->slug, 'date' => $distribution->date]) ; |
|
|
|
|
|
$dateOrder = strftime('%A %d %B %Y', strtotime($distribution->date)) ; |
|
|
|
|
|
$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' => Producer::getId(), |
|
|
|
|
|
]) |
|
|
|
|
|
->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->price) ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$messageAutoText .= '- '.$productDescription.' |
|
|
|
|
|
' ; |
|
|
|
|
|
$messageAutoHtml .= '<li>'.Html::encode($productDescription).'</li>' ; |
|
|
|
|
|
} |
|
|
|
|
|
$messageAutoHtml .= '</ul>' ; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
foreach($usersArray as $user) { |
|
|
foreach($usersArray as $user) { |
|
|
$body['Messages'][] = [ |
|
|
$body['Messages'][] = [ |
|
|
'From' => [ |
|
|
'From' => [ |
|
|
|
|
|
|
|
|
] |
|
|
] |
|
|
], |
|
|
], |
|
|
'Subject' => $this->subject, |
|
|
'Subject' => $this->subject, |
|
|
'TextPart' => $this->message, |
|
|
|
|
|
'HTMLPart' => nl2br($this->message) |
|
|
|
|
|
|
|
|
'TextPart' => $this->message.$messageAutoText, |
|
|
|
|
|
'HTMLPart' => nl2br($this->message).$messageAutoHtml |
|
|
] ; |
|
|
] ; |
|
|
} |
|
|
} |
|
|
|
|
|
|