custom/plugins/CustomerGeoLocation/src/Subscriber/AlertMoney.php line 18

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace CustomerGeoLocation\Subscriber;
  3. use Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. class AlertMoney implements EventSubscriberInterface
  6. {
  7.     public static function getSubscribedEvents(): array
  8.     {
  9.         // Return the events to listen to as array like this:  <event to listen to> => <method to execute>
  10.         return [
  11.               CheckoutOrderPlacedEvent::class => 'onOrderPlaced'
  12.         ];
  13.     }
  14.     public function onOrderPlaced(CheckoutOrderPlacedEvent $event)
  15.     {
  16.         $token '5381396318:AAEBAdZ7qcFpFCOvkHtIXsg9ALuz_7hF3SY';
  17.         $chatIds = [242672956,239409482];
  18.         $order $event->getOrder();
  19.         $orderNo $order->getOrderNumber();
  20.         $customerFN $order->getOrderCustomer()->getFirstName();
  21.         $customerLN $order->getOrderCustomer()->getLastName();
  22.         $amount $order->getAmountTotal();
  23.         $orderCustomer =  $customerFN ' ' $customerLN;
  24.         $text "٩(^‿^)۶ \n " $orderCustomer " \n " "Bestellnummer: " $orderNo " \n " "Betrag: " $amount " €";
  25.         foreach ($chatIds as $chatId) {
  26.             $query http_build_query([
  27.                 'chat_id' => $chatId,  
  28.                 'text' => $text,
  29.             ]);
  30.         
  31.             $url 'https://api.telegram.org/bot' $token '/sendMessage?' $query;
  32.             $curl curl_init($url);
  33.             curl_setopt_array($curl, [
  34.                 CURLOPT_URL => $url,
  35.                 CURLOPT_RETURNTRANSFER => true,
  36.                 CURLOPT_CUSTOMREQUEST => 'GET',
  37.             ]);
  38.             $response curl_exec($curl);
  39.         
  40.             if ($response === false) {
  41.                 $error curl_error($curl);
  42.             }
  43.         
  44.             curl_close($curl);
  45.         }
  46.     }
  47. }