Created
June 17, 2020 07:02
-
-
Save qwertik17/114f05fe38a6c1a49f061b0879bce5a8 to your computer and use it in GitHub Desktop.
Отправка заказов в телеграм
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
if($modx->event->name != 'msOnCreateOrder') return; | |
$token = $modx->getOption('mstelegram_token', null, false); | |
$recipients = explode(',', $modx->getOption('mstelegram_recipients', null, '')); | |
$contacts = $modx->getObject('msOrderAddress', array('id'=> $msOrder->address)); | |
$_products = $msOrder->getMany('Products'); | |
$delivery = $msOrder->getOne('Delivery'); | |
$payment = $msOrder->getOne('Payment'); | |
// Список товаров в заказе | |
$i = 0; | |
$products = ''; | |
foreach ($_products as $product) { | |
$i++; | |
$products .= "{$i}. {$product->name} ({$product->count} шт.)\n"; | |
} | |
// Текст сообщения | |
$message = " | |
Новый заказ #{$msOrder->num} | |
на сумму {$msOrder->cost} р. | |
----- | |
{$products} | |
----- | |
Имя: {$contacts->receiver} | |
Телефон: {$contacts->phone} | |
Город: {$contacts->city} | |
{$contacts->street} | |
Комментрарий: {$contacts->comment} | |
Сдача с: {$contacts->index} | |
Способ доставки: {$delivery->name} | |
Тип оплаты: {$payment->name} | |
"; | |
$message = urlencode($message); | |
foreach($recipients as $id){ | |
$id = trim($id); | |
if(!$id) continue; | |
$url = "https://api.telegram.org/bot{$token}/sendMessage?chat_id={$id}&text={$message}"; | |
$ch = curl_init(); | |
curl_setopt_array($ch, array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true)); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment