<?php declare(strict_types=1);
namespace CustomerGeoLocation\Subscriber;
use Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AlertMoney implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
// Return the events to listen to as array like this: <event to listen to> => <method to execute>
return [
CheckoutOrderPlacedEvent::class => 'onOrderPlaced'
];
}
public function onOrderPlaced(CheckoutOrderPlacedEvent $event)
{
$token = '5381396318:AAEBAdZ7qcFpFCOvkHtIXsg9ALuz_7hF3SY';
$chatIds = [242672956,239409482];
$order = $event->getOrder();
$orderNo = $order->getOrderNumber();
$customerFN = $order->getOrderCustomer()->getFirstName();
$customerLN = $order->getOrderCustomer()->getLastName();
$amount = $order->getAmountTotal();
$orderCustomer = $customerFN . ' ' . $customerLN;
$text = "٩(^‿^)۶ \n " . $orderCustomer . " \n " . "Bestellnummer: " . $orderNo . " \n " . "Betrag: " . $amount . " €";
foreach ($chatIds as $chatId) {
$query = http_build_query([
'chat_id' => $chatId,
'text' => $text,
]);
$url = 'https://api.telegram.org/bot' . $token . '/sendMessage?' . $query;
$curl = curl_init($url);
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'GET',
]);
$response = curl_exec($curl);
if ($response === false) {
$error = curl_error($curl);
}
curl_close($curl);
}
}
}