bundles/ZweiPunkt/ShopwareBundle/Subscriber/ObjectEdited.php line 36

Open in your IDE?
  1. <?php
  2. namespace ZweiPunkt\ShopwareBundle\Subscriber;
  3. use Pimcore\Config;
  4. use Pimcore\Event\DataObjectEvents;
  5. use Pimcore\Event\Model\DataObjectDeleteInfoEvent;
  6. use Pimcore\Event\Model\DataObjectEvent;
  7. use Pimcore\Model\DataObject\Product;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use ZweiPunkt\ShopwareBundle\Shopware\Service\ApiClient;
  10. class ObjectEdited implements EventSubscriberInterface
  11. {
  12.     private Config $config;
  13.     private ApiClient $apiClient;
  14.     public function __construct(
  15.         Config $config,
  16.         ApiClient $apiClient
  17.     ) {
  18.         $this->config $config;
  19.         $this->apiClient $apiClient;
  20.     }
  21.     public static function getSubscribedEvents()
  22.     {
  23.         // return the subscribed events, their methods and priorities
  24.         return [
  25.             DataObjectEvents::DELETE_INFO => [
  26.                 ['onDelete'10],
  27.             ],
  28.         ];
  29.     }
  30.     public function onDelete(DataObjectDeleteInfoEvent $event)
  31.     {
  32.         $object $event->getObject();
  33.         if ($object instanceof Product) {
  34.             try {
  35.                 $path sprintf('/api/product/%s'$object->getShopwareId());
  36.                 $this->apiClient->delete($path);
  37.                 // TODO: Delete Product in Shopware when it's deleted in pimcore
  38.             } catch (\Exception $exception) {
  39.                 //
  40.             }
  41.         }
  42.     }
  43. }