Skip to content

Commit

Permalink
Category entity in the constructor of CategoryRepository is resolved …
Browse files Browse the repository at this point in the history
…via EntityNameResolver

- Category entity is now extendable and extraction of class metadata are loaded from an extended entity if exists
  • Loading branch information
Miroslav-Stopka authored and TomasLudvik committed Jul 27, 2018
1 parent e0638e4 commit 48910cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -59,6 +59,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- [#313 - Streamed logging](https://github.com/shopsys/shopsys/pull/313)
- monolog logs into streams instead of files (use `docker-compose logs` to access it)
- see details in the [Logging](/docs/introduction/logging.md) article
- [#341 - Category entity in constructor of CategoryRepository is resolved via EntityNameResolver](https://github.com/shopsys/shopsys/pull/341)

#### Fixed
- [#291 - Unnecessary SQL queries on category detail in admin](https://github.com/shopsys/shopsys/pull/304):
Expand Down
15 changes: 11 additions & 4 deletions packages/framework/src/Model/Category/CategoryRepository.php
Expand Up @@ -7,6 +7,7 @@
use Doctrine\ORM\QueryBuilder;
use Gedmo\Tree\Entity\Repository\NestedTreeRepository;
use Shopsys\FrameworkBundle\Component\Domain\Config\DomainConfig;
use Shopsys\FrameworkBundle\Component\EntityExtension\EntityNameResolver;
use Shopsys\FrameworkBundle\Component\Paginator\QueryPaginator;
use Shopsys\FrameworkBundle\Component\String\DatabaseSearching;
use Shopsys\FrameworkBundle\Model\Pricing\Group\PricingGroup;
Expand All @@ -30,13 +31,19 @@ class CategoryRepository extends NestedTreeRepository

/**
* @param \Doctrine\ORM\EntityManagerInterface $em
* @param \Shopsys\FrameworkBundle\Model\Product\ProductRepository
* @param \Shopsys\FrameworkBundle\Model\Product\ProductRepository $productRepository
* @param \Shopsys\FrameworkBundle\Component\EntityExtension\EntityNameResolver $entityNameResolver
*/
public function __construct(EntityManagerInterface $em, ProductRepository $productRepository)
{
public function __construct(
EntityManagerInterface $em,
ProductRepository $productRepository,
EntityNameResolver $entityNameResolver
) {
$this->em = $em;
$classMetadata = $this->em->getClassMetadata(Category::class);
$this->productRepository = $productRepository;

$resolvedClassName = $entityNameResolver->resolve(Category::class);
$classMetadata = $this->em->getClassMetadata($resolvedClassName);
parent::__construct($this->em, $classMetadata);
}

Expand Down

0 comments on commit 48910cc

Please sign in to comment.