<?php
namespace ZweiPunkt\ShopwareBundle\Subscriber;
use Pimcore\Config;
use Pimcore\Event\DataObjectEvents;
use Pimcore\Event\Model\DataObjectDeleteInfoEvent;
use Pimcore\Event\Model\DataObjectEvent;
use Pimcore\Model\DataObject\Product;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use ZweiPunkt\ShopwareBundle\Shopware\Service\ApiClient;
class ObjectEdited implements EventSubscriberInterface
{
private Config $config;
private ApiClient $apiClient;
public function __construct(
Config $config,
ApiClient $apiClient
) {
$this->config = $config;
$this->apiClient = $apiClient;
}
public static function getSubscribedEvents()
{
// return the subscribed events, their methods and priorities
return [
DataObjectEvents::DELETE_INFO => [
['onDelete', 10],
],
];
}
public function onDelete(DataObjectDeleteInfoEvent $event)
{
$object = $event->getObject();
if ($object instanceof Product) {
try {
$path = sprintf('/api/product/%s', $object->getShopwareId());
$this->apiClient->delete($path);
// TODO: Delete Product in Shopware when it's deleted in pimcore
} catch (\Exception $exception) {
//
}
}
}
}