Skip to content

Commit

Permalink
Merge pull request #60 from DivanteLtd/fix/product-listener
Browse files Browse the repository at this point in the history
feat: ProductListener processes custom repos
  • Loading branch information
dkarlovi committed Feb 26, 2021
2 parents 46a8972 + d14a734 commit a8d524b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 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 @@ -49,6 +49,7 @@ public function getConfigTreeBuilder()
->arrayPrototype()
->children()
->variableNode('mappings')->end()
->variableNode('settings')->end()
->end()
->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ 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;
}

foreach ($this->persisterFactory->create(null, null, $this->repositoryProvider->getAliasFor($object)) as $config) {
foreach ($this->persisterFactory->create(null, $this->repositoryProvider->getAliasFor($object)) as $config) {
$config['persister']->persist($object);
}
}
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 a8d524b

Please sign in to comment.