Created
June 17, 2020 06:58
-
-
Save qwertik17/d247cacf23a1fb4e3f503ee512e92a85 to your computer and use it in GitHub Desktop.
Напоминание за 1 час о доставке заказа
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('MODX_API_MODE', true); | |
/** @noinspection PhpIncludeInspection */ | |
require dirname(dirname(dirname(dirname(__FILE__)))) . '/index.php'; | |
$emailTo = $modx->getOption('notice_emailTo'); | |
$notice_period = $modx->getOption('notice_def'); | |
if (!$emailTo || !$notice_period) return; | |
$notice_period = $notice_period * 60; | |
$pdo = $modx->getService('pdoFetch'); | |
$results = $pdo->getCollection('msOrder', array(), array( | |
'leftJoin' => array( | |
'msOrderAddress' => array( | |
'class' => 'msOrderAddress', | |
'on' => 'msOrder.id = msOrderAddress.id', | |
), | |
'modUserProfile' => array( | |
'class' => 'modUserProfile', | |
'on' => 'msOrder.user_id = modUserProfile.internalKey', | |
), | |
), | |
'select' => array( | |
'msOrder' => '*', | |
'msOrderAddress' => '*', | |
'modUserProfile' => 'email', | |
), | |
'where' => array ( | |
'(msOrderAddress.region IS NOT NULL AND msOrderAddress.region != "") AND (msOrderAddress.metro IS NULL OR msOrderAddress.metro != "Да")' | |
) | |
)); | |
if (count($results)) | |
{ | |
date_default_timezone_set("Europe/Samara"); | |
$cur_time = time(); | |
$need_time = $cur_time - $notice_period; | |
foreach ($results as $order) | |
{ | |
print_r($order); | |
$msOrder = $modx->getObject('msOrder', $order['id']); | |
$_products = $msOrder->getMany('Products'); | |
$i = 0; | |
$products = '<ul>'; | |
foreach ($_products as $product) { | |
$i++; | |
$products .= "<li>{$i}. {$product->name} ({$product->count} шт.)</li>"; | |
} | |
$products .= '</ul>'; | |
$delivery = $msOrder->getOne('Delivery'); | |
$payment = $msOrder->getOne('Payment'); | |
//return; | |
$time_delivery = strtotime($order['region']); | |
$time_notice = time() + $notice_period; | |
if ($time_delivery <= $time_notice) | |
{ | |
//Отправляем письмо | |
$modx->getService('mail', 'mail.modPHPMailer'); | |
$modx->mail->set(modMail::MAIL_FROM, $modx->getOption('emailsender')); | |
$modx->mail->set(modMail::MAIL_FROM_NAME, $modx->getOption('site_name')); | |
$modx->mail->address('to', $emailTo); | |
$modx->mail->set(modMail::MAIL_SUBJECT, 'Заказ '.$order['num'].'. Напоминание о доставке'); | |
$modx->mail->set(modMail::MAIL_BODY, $modx->getChunk('tpl.notice_email', array( | |
'order' => $order, | |
'products' => $products, | |
'delivery' => $delivery->name, | |
'payment' => $payment->name, | |
))); | |
$modx->mail->setHTML(true); | |
if ($modx->mail->send()) { | |
$contacts = $modx->getObject('msOrderAddress', array('id'=> $msOrder->address)); | |
$contacts->set('metro', 'Да'); | |
$contacts->save(); | |
} | |
$modx->mail->reset(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment