Skip to content

Commit

Permalink
[AddressBundle] add AddressIdentifierRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Apr 1, 2019
1 parent 1c342bf commit daac0ac
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Bundle\AddressBundle\Doctrine\ORM;

use CoreShop\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use CoreShop\Component\Address\Repository\AddressIdentifierRepositoryInterface;

class AddressIdentifierRepository extends EntityRepository implements AddressIdentifierRepositoryInterface
{
/**
* {@inheritdoc}
*/
public function findByName($name)
{
return $this->createQueryBuilder('o')
->andWhere('o.name = :name')
->setParameter('name', $name)
->getQuery()
->useQueryCache(true)
->useResultCache(true)
->getResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Component\Address\Repository;

use CoreShop\Component\Address\Model\AddressIdentifierInterface;
use CoreShop\Component\Resource\Repository\RepositoryInterface;

interface AddressIdentifierRepositoryInterface extends RepositoryInterface
{
/**
* @param string $name
*
* @return AddressIdentifierInterface
*/
public function findByName($name);
}

0 comments on commit daac0ac

Please sign in to comment.