custom/plugins/PickwareErpPro/vendor/pickware/shipping-bundle/src/Carrier/Model/Subscriber/CarrierEntitySubscriber.php line 39

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (c) Pickware GmbH. All rights reserved.
  4.  * This file is part of software that is released under a proprietary license.
  5.  * You must not copy, modify, distribute, make publicly available, or execute
  6.  * its contents or parts thereof without express permission by the copyright
  7.  * holder, unless otherwise permitted by law.
  8.  */
  9. declare(strict_types=1);
  10. namespace Pickware\ShippingBundle\Carrier\Model\Subscriber;
  11. use Pickware\ShippingBundle\Carrier\CarrierAdapterRegistryInterface;
  12. use Pickware\ShippingBundle\Carrier\Model\CarrierEntity;
  13. use Pickware\ShippingBundle\Carrier\Model\CarrierEvents;
  14. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class CarrierEntitySubscriber implements EventSubscriberInterface
  17. {
  18.     /**
  19.      * @var CarrierAdapterRegistryInterface
  20.      */
  21.     private $carrierAdapterRegistry;
  22.     public function __construct(CarrierAdapterRegistryInterface $carrierAdapterRegistry)
  23.     {
  24.         $this->carrierAdapterRegistry $carrierAdapterRegistry;
  25.     }
  26.     public static function getSubscribedEvents(): array
  27.     {
  28.         return [
  29.             CarrierEvents::ENTITY_LOADED => 'onEntityLoaded',
  30.         ];
  31.     }
  32.     public function onEntityLoaded(EntityLoadedEvent $event): void
  33.     {
  34.         /** @var CarrierEntity $carrier */
  35.         foreach ($event->getEntities() as $carrier) {
  36.             $technicalName $carrier->getTechnicalName();
  37.             if ($this->carrierAdapterRegistry->hasCarrierAdapter($technicalName)) {
  38.                 $adapter $this->carrierAdapterRegistry->getCarrierAdapterByTechnicalName($technicalName);
  39.                 $carrier->assign([
  40.                     'installed' => true,
  41.                     'capabilities' => $adapter->getCapabilities(),
  42.                 ]);
  43.             } else {
  44.                 $carrier->assign([
  45.                     'installed' => false,
  46.                     'capabilities' => null,
  47.                 ]);
  48.             }
  49.         }
  50.     }
  51. }