Skip to content

Instantly share code, notes, and snippets.

@bendasvadim
Last active December 23, 2021 13:39
Show Gist options
  • Save bendasvadim/27c71f6f9bf3d9f787ff08b1081087f4 to your computer and use it in GitHub Desktop.
Save bendasvadim/27c71f6f9bf3d9f787ff08b1081087f4 to your computer and use it in GitHub Desktop.
Изменение почты менеджера при заказе miniShop2 в зависсимости от выбранной доставки.
<?php
/** @var modX $modx */
switch ($modx->event->name) {
case 'msOnChangeOrderStatus':
// Update customer stat
if ($status = $modx->getObject('msOrderStatus', array('id' => $status, 'active' => 1))) {
if ($miniShop2 = $modx->getService('miniShop2')) {
$miniShop2->initialize($modx->context->key, array(
'json_response' => false,
));
if (!($miniShop2 instanceof miniShop2)) {
return;
}
$pls = $order->toArray();
$pls['cost'] = $miniShop2->formatPrice($pls['cost']);
$pls['cart_cost'] = $miniShop2->formatPrice($pls['cart_cost']);
$pls['delivery_cost'] = $miniShop2->formatPrice($pls['delivery_cost']);
$pls['weight'] = $miniShop2->formatWeight($pls['weight']);
if ($status->get('email_manager')) {
$subject = $miniShop2->pdoTools->getChunk('@INLINE ' . $status->get('subject_manager'), $pls);
$tpl = '';
if ($chunk = $modx->getObject('modChunk', $status->get('body_manager'))) {
$tpl = $chunk->get('name');
}
$body = $modx->runSnippet('msGetOrder', array_merge($pls, array('tpl' => $tpl)));
if ($order->get('delivery') == 1) {
$emails = array_map('trim', explode(',', $modx->getOption('ms2_email_manager_delivery_1', null, $modx->getOption('ms2_email_manager'))));
} else if ($order->get('delivery') == 2) {
$emails = array_map('trim', explode(',', $modx->getOption('ms2_email_manager_delivery_2', null, $modx->getOption('ms2_email_manager'))));
}
if (!empty($subject)) {
$modx->log(1, print_r($emails, true));
foreach ($emails as $email) {
if (preg_match('#.*?@.*#', $email)) {
$miniShop2->sendEmail($email, $subject, $body);
}
}
}
}
}
}
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment