custom/plugins/MadSplitAddress/src/Subscriber/OrderSubscriber.php line 65

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace MadSplitAddress\Subscriber;
  4. use Shopware\Storefront\Page\Account\Order\AccountOrderPageLoadedEvent;
  5. use Shopware\Storefront\Page\Account\Overview\AccountOverviewPageLoadedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class OrderSubscriber  implements EventSubscriberInterface
  8. {
  9.     public static function getSubscribedEvents(): array
  10.     {
  11.         return [
  12.             AccountOverviewPageLoadedEvent::class => 'AccountOverviewPageLoaded',
  13.             AccountOrderPageLoadedEvent::class => 'onAccountOrderPageLoaded',
  14.         ];
  15.     }
  16.     public function AccountOverviewPageLoaded(AccountOverviewPageLoadedEvent $event): void
  17.     {
  18.         $order $event->getPage()->getNewestOrder();
  19.         if ($order){
  20.             $streethelpers $order->getDeliveries()->getElements();
  21.             $myStreet '';
  22.             $myNumber '';
  23.             $check 0;
  24.             $count 0;
  25.             foreach($streethelpers as &$streethelper){
  26.                 $splitStreets explode(" "$streethelper->getShippingOrderAddress()->getStreet());
  27.                 foreach ($splitStreets as &$splitStreet){
  28.                     if (is_numeric($splitStreet) || $check == || preg_match('~[0-9]+~'$splitStreet)) {
  29.                         if($check == 1){
  30.                             $myNumber $myNumber.' ';
  31.                         }
  32.                         $myNumber $myNumber.$splitStreet;
  33.                         $check 1;
  34.                     }else{
  35.                         if($count == 1){
  36.                             $myStreet $myStreet.' ';
  37.                         }
  38.                         $myStreet $myStreet.$splitStreet;
  39.                         $count 1;
  40.                     }
  41.                 }
  42.             }
  43.             $order->madStreet $myStreet;
  44.             $order->madStreetNumber $myNumber;
  45.         }
  46.     }
  47.     public function onAccountOrderPageLoaded(AccountOrderPageLoadedEvent $event): void
  48.     {
  49.         $orders $event->getPage()->getOrders()->getElements();
  50.         if($orders){
  51.             foreach($orders as &$order){
  52.                 $streethelpers $order->getDeliveries()->getElements();
  53.                 $myStreet '';
  54.                 $myNumber '';
  55.                 $check 0;
  56.                 $count 0;
  57.                 foreach($streethelpers as &$streethelper){
  58.                     $splitStreets explode(" "$streethelper->getShippingOrderAddress()->getStreet());
  59.                     foreach ($splitStreets as &$splitStreet){
  60.                         if (is_numeric($splitStreet) || $check == || preg_match('~[0-9]+~'$splitStreet)) {
  61.                             if($check == 1){
  62.                                 $myNumber $myNumber.' ';
  63.                             }
  64.                             $myNumber $myNumber.$splitStreet;
  65.                             $check 1;
  66.                         }else{
  67.                             if($count == 1){
  68.                                 $myStreet $myStreet.' ';
  69.                             }
  70.                             $myStreet $myStreet.$splitStreet;
  71.                             $count 1;
  72.                         }
  73.                     }
  74.                 }
  75.                 $order->madStreet $myStreet;
  76.                 $order->madStreetNumber $myNumber;
  77.             }
  78.         }
  79.     }
  80. }