diff --git a/src/CoreShop2VueStorefrontBundle/Bridge/RepositoryProvider.php b/src/CoreShop2VueStorefrontBundle/Bridge/RepositoryProvider.php index 5577f02..5b35091 100644 --- a/src/CoreShop2VueStorefrontBundle/Bridge/RepositoryProvider.php +++ b/src/CoreShop2VueStorefrontBundle/Bridge/RepositoryProvider.php @@ -18,6 +18,26 @@ public function __construct(iterable $repositories) $this->repositories = $repositories; } + public function hasRepositoryFor(object $object): bool + { + $className = get_class($object); + + if (isset($cache[$className])) { + return $cache[$className]; + } + + /** @var RepositoryInterface $repository */ + foreach ($this->repositories as $repository) { + if ($repository->getClassName() === $className) { + $cache[$className] = true; + + return true; + } + } + + return false; + } + public function getAliasFor(object $object): string { $className = get_class($object); diff --git a/src/CoreShop2VueStorefrontBundle/EventListener/ProductListener.php b/src/CoreShop2VueStorefrontBundle/EventListener/ProductListener.php index 827f476..0fcade8 100644 --- a/src/CoreShop2VueStorefrontBundle/EventListener/ProductListener.php +++ b/src/CoreShop2VueStorefrontBundle/EventListener/ProductListener.php @@ -41,7 +41,7 @@ public function postSave(DataObjectEvent $event) /** @var ProductInterface|CategoryInterface|Concrete $object */ $object = $event->getObject(); - if ($this->shouldSynchronizeWithVue($object)) { + if ($this->repositoryProvider->hasRepositoryFor($object)) { if ($object->getType() == AbstractObject::OBJECT_TYPE_VARIANT) { return false; } @@ -57,10 +57,4 @@ public function postSave(DataObjectEvent $event) )); } } - - private function shouldSynchronizeWithVue($object): bool - { - return $object instanceof CategoryInterface - || $object instanceof ProductInterface; - } }