From daac0accd58df6bd32ca8176e5bc600c6fc1b28c Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Mon, 1 Apr 2019 16:37:20 +0100 Subject: [PATCH] [AddressBundle] add AddressIdentifierRepository --- .../DependencyInjection/Configuration.php | 3 +- .../ORM/AddressIdentifierRepository.php | 33 +++++++++++++++++++ .../Controller/CustomerController.php | 2 +- .../AddressIdentifierRepositoryInterface.php | 26 +++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 src/CoreShop/Bundle/AddressBundle/Doctrine/ORM/AddressIdentifierRepository.php create mode 100644 src/CoreShop/Component/Address/Repository/AddressIdentifierRepositoryInterface.php diff --git a/src/CoreShop/Bundle/AddressBundle/DependencyInjection/Configuration.php b/src/CoreShop/Bundle/AddressBundle/DependencyInjection/Configuration.php index 5f12dc9ea8..e033dfe562 100644 --- a/src/CoreShop/Bundle/AddressBundle/DependencyInjection/Configuration.php +++ b/src/CoreShop/Bundle/AddressBundle/DependencyInjection/Configuration.php @@ -12,6 +12,7 @@ namespace CoreShop\Bundle\AddressBundle\DependencyInjection; +use CoreShop\Bundle\AddressBundle\Doctrine\ORM\AddressIdentifierRepository; use CoreShop\Bundle\AddressBundle\Doctrine\ORM\CountryRepository; use CoreShop\Bundle\AddressBundle\Form\Type\AddressIdentifierType; use CoreShop\Bundle\AddressBundle\Form\Type\CountryTranslationType; @@ -170,7 +171,7 @@ private function addModelsSection(ArrayNodeDefinition $node) ->scalarNode('interface')->defaultValue(AddressIdentifierInterface::class)->cannotBeEmpty()->end() ->scalarNode('admin_controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end() - ->scalarNode('repository')->cannotBeEmpty()->end() + ->scalarNode('repository')->defaultValue(AddressIdentifierRepository::class)->end() ->scalarNode('form')->defaultValue(AddressIdentifierType::class)->cannotBeEmpty()->end() ->end() ->end() diff --git a/src/CoreShop/Bundle/AddressBundle/Doctrine/ORM/AddressIdentifierRepository.php b/src/CoreShop/Bundle/AddressBundle/Doctrine/ORM/AddressIdentifierRepository.php new file mode 100644 index 0000000000..6228642b38 --- /dev/null +++ b/src/CoreShop/Bundle/AddressBundle/Doctrine/ORM/AddressIdentifierRepository.php @@ -0,0 +1,33 @@ +createQueryBuilder('o') + ->andWhere('o.name = :name') + ->setParameter('name', $name) + ->getQuery() + ->useQueryCache(true) + ->useResultCache(true) + ->getResult(); + } +} diff --git a/src/CoreShop/Bundle/FrontendBundle/Controller/CustomerController.php b/src/CoreShop/Bundle/FrontendBundle/Controller/CustomerController.php index 6ced9ecb8b..015bb12ad6 100644 --- a/src/CoreShop/Bundle/FrontendBundle/Controller/CustomerController.php +++ b/src/CoreShop/Bundle/FrontendBundle/Controller/CustomerController.php @@ -150,7 +150,7 @@ public function addressAction(Request $request) /** @var AddressInterface $address */ $address = $this->get('coreshop.factory.address')->createNew(); if ($request->query->has('address_identifier')) { - $addressIdentifier = $this->get('coreshop.repository.address_identifier')->findOneBy(['name' => $request->query->get('address_identifier')]); + $addressIdentifier = $this->get('coreshop.repository.address_identifier')->findByName($request->query->get('address_identifier')); if ($addressIdentifier instanceof AddressIdentifierInterface) { $address->setAddressIdentifier($addressIdentifier); } diff --git a/src/CoreShop/Component/Address/Repository/AddressIdentifierRepositoryInterface.php b/src/CoreShop/Component/Address/Repository/AddressIdentifierRepositoryInterface.php new file mode 100644 index 0000000000..f11e07257b --- /dev/null +++ b/src/CoreShop/Component/Address/Repository/AddressIdentifierRepositoryInterface.php @@ -0,0 +1,26 @@ +