Skip to content

Commit

Permalink
feature: enable real-time index for custom repos
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarlovi committed Feb 26, 2021
1 parent 49fbd70 commit d14a734
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
20 changes: 20 additions & 0 deletions src/CoreShop2VueStorefrontBundle/Bridge/RepositoryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -57,10 +57,4 @@ public function postSave(DataObjectEvent $event)
));
}
}

private function shouldSynchronizeWithVue($object): bool
{
return $object instanceof CategoryInterface
|| $object instanceof ProductInterface;
}
}

0 comments on commit d14a734

Please sign in to comment.