Skip to content

Instantly share code, notes, and snippets.

@artbelov
Last active September 14, 2021 10:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save artbelov/486a3f447ebdc1e395ae to your computer and use it in GitHub Desktop.
Save artbelov/486a3f447ebdc1e395ae to your computer and use it in GitHub Desktop.
miniShop2: Плагин E-mail уведомления при отправке заказа
<?php
switch ($modx->event->name) {
case 'msOnChangeOrderStatus':
if ($status == 3) {
$modx->getService('error', 'error.modError');
$modx->getService('mail', 'mail.modPHPMailer');
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
$modx->setLogTarget('FILE');
$modx->log(modX::LOG_LEVEL_INFO, 'Заказ №' . $order->get('id'));
foreach ($order->getMany('Products') as $item) {
$product = $item->getOne('Product');
// Расширенное свойство товара: 'sold'
// bezumkin.ru/modx/minishop2/msearch2/1805/
$product->set('sold', $product->get('sold') + $item->get('count'));
$product->save();
$modx->log(modX::LOG_LEVEL_INFO, 'Товар: "' . $product->get('pagetitle') . '" (#' . $product->get('id') . ')');
$modx->log(modX::LOG_LEVEL_INFO, 'Цена: ' . $product->get('price') . ' руб.');
$modx->log(modX::LOG_LEVEL_INFO, 'Количество: ' . $item->get('count') . ' шт.');
$modx->log(modX::LOG_LEVEL_INFO, 'Всего продано: ' . $product->get('sold') . ' шт.');
if ($order->get('email') !== '') {
$mail = $order->get('email');
$subj = 'Тема письма';
$body = 'Содержимое письма';
$modx->mail->set(modMail::MAIL_FROM, $modx->getOption('emailsender'));
$modx->mail->set(modMail::MAIL_FROM_NAME, $modx->getOption('site_name'));
$modx->mail->set(modMail::MAIL_SUBJECT, trim($subj));
$modx->mail->set(modMail::MAIL_BODY, $body);
$modx->mail->setHTML(true);
$modx->mail->address('to', trim($mail));
$modx->mail->send() ? $modx->mail->reset() : $modx->log(modX::LOG_LEVEL_ERROR, 'Ошибка: ' . $modx->mail->mailer->ErrorInfo);
}
}
}
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment