From 54a909ab1c86b9964e812d2f1c15b23a73aaf0be Mon Sep 17 00:00:00 2001 From: michalmarcinkowski Date: Thu, 21 May 2015 11:48:46 +0200 Subject: [PATCH] Initial fixes --- .../ChannelBundle/Behat/ChannelContext.php | 2 +- .../DependencyInjection/Configuration.php | 11 +++- .../Doctrine/ORM/ChannelRepository.php | 20 ++++++- .../Form/Type/ChannelChoiceType.php | 60 ------------------- .../Form/Type/ChannelEntityChoiceType.php | 28 --------- .../Resources/config/driver/doctrine/orm.xml | 1 - .../Resources/config/services.xml | 11 ---- .../CoreBundle/Context/ChannelContext.php | 13 +++- .../Controller/ProductController.php | 1 + .../Doctrine/ORM/PaymentRepository.php | 14 ++--- .../Doctrine/ORM/ProductRepository.php | 7 +-- .../Doctrine/ORM/PromotionRepository.php | 14 ++--- .../EventListener/OrderChannelListener.php | 9 +++ .../Form/Type/Checkout/PaymentStepType.php | 6 +- .../Form/Type/Checkout/ShippingStepType.php | 6 +- .../Resources/config/app/sylius.yml | 5 +- .../CoreBundle/Resources/config/form.xml | 6 +- .../DataFixtures/ORM/LoadChannelData.php | 8 +-- .../Doctrine/ORM/PromotionRepository.php | 14 ++--- .../Repository/ChannelRepositoryInterface.php | 15 ++++- .../Core/Channel/ChannelResolver.php | 8 ++- .../Core/Channel/ChannelResolverInterface.php | 8 +-- 22 files changed, 116 insertions(+), 151 deletions(-) delete mode 100644 src/Sylius/Bundle/ChannelBundle/Form/Type/ChannelChoiceType.php delete mode 100644 src/Sylius/Bundle/ChannelBundle/Form/Type/ChannelEntityChoiceType.php diff --git a/src/Sylius/Bundle/ChannelBundle/Behat/ChannelContext.php b/src/Sylius/Bundle/ChannelBundle/Behat/ChannelContext.php index 5ceb28dd1d..8fd87f9b1d 100644 --- a/src/Sylius/Bundle/ChannelBundle/Behat/ChannelContext.php +++ b/src/Sylius/Bundle/ChannelBundle/Behat/ChannelContext.php @@ -74,7 +74,7 @@ class ChannelContext extends DefaultContext isset($data['shipping']) ? $data['shipping'] : null, isset($data['payments']) ? $data['payments'] : null, false - ); + ); } $this->getEntityManager()->flush(); diff --git a/src/Sylius/Bundle/ChannelBundle/DependencyInjection/Configuration.php b/src/Sylius/Bundle/ChannelBundle/DependencyInjection/Configuration.php index ca7f67594c..eb29a3bd62 100644 --- a/src/Sylius/Bundle/ChannelBundle/DependencyInjection/Configuration.php +++ b/src/Sylius/Bundle/ChannelBundle/DependencyInjection/Configuration.php @@ -11,6 +11,7 @@ namespace Sylius\Bundle\ChannelBundle\DependencyInjection; +use Sylius\Bundle\ResourceBundle\SyliusResourceBundle; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; @@ -35,7 +36,7 @@ class Configuration implements ConfigurationInterface $rootNode ->children() - ->scalarNode('driver')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end() ->end() ; @@ -85,7 +86,13 @@ class Configuration implements ConfigurationInterface ->scalarNode('model')->defaultValue('Sylius\Component\Channel\Model\Channel')->end() ->scalarNode('controller')->defaultValue('Sylius\Bundle\ResourceBundle\Controller\ResourceController')->end() ->scalarNode('repository')->end() - ->scalarNode('form')->defaultValue('Sylius\Bundle\ChannelBundle\Form\Type\ChannelType')->end() + ->arrayNode('form') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('default')->defaultValue('Sylius\Bundle\ChannelBundle\Form\Type\ChannelType')->end() + ->scalarNode('choice')->end() + ->end() + ->end() ->end() ->end() ->end() diff --git a/src/Sylius/Bundle/ChannelBundle/Doctrine/ORM/ChannelRepository.php b/src/Sylius/Bundle/ChannelBundle/Doctrine/ORM/ChannelRepository.php index 53628632ee..63a45e4aea 100644 --- a/src/Sylius/Bundle/ChannelBundle/Doctrine/ORM/ChannelRepository.php +++ b/src/Sylius/Bundle/ChannelBundle/Doctrine/ORM/ChannelRepository.php @@ -21,15 +21,31 @@ use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; */ class ChannelRepository extends EntityRepository implements ChannelRepositoryInterface { + /** + * {@inheritDoc} + */ public function findMatchingHostname($hostname) { $queryBuilder = $this->createQueryBuilder('channel'); $queryBuilder - ->andWhere('channel.url LIKE :hostname') + ->andWhere($queryBuilder->expr()->like('channel.url', ':hostname')) ->setParameter('hostname', '%'.$hostname.'%') ; return $queryBuilder->getQuery()->getOneOrNullResult(); } -} + + /** + * {@inheritDoc} + */ + public function findDefault() + { + return $this + ->getCollectionQueryBuilder() + ->getQuery() + ->setMaxResults(1) + ->getSingleResult() + ; + } +} \ No newline at end of file diff --git a/src/Sylius/Bundle/ChannelBundle/Form/Type/ChannelChoiceType.php b/src/Sylius/Bundle/ChannelBundle/Form/Type/ChannelChoiceType.php deleted file mode 100644 index da85715f76..0000000000 --- a/src/Sylius/Bundle/ChannelBundle/Form/Type/ChannelChoiceType.php +++ /dev/null @@ -1,60 +0,0 @@ - - */ -abstract class ChannelChoiceType extends AbstractType -{ - /** - * Channel class name. - * - * @var string - */ - protected $className; - - /** - * Constructor. - * - * @param string $className - */ - public function __construct($className) - { - $this->className = $className; - } - - /** - * {@inheritdoc} - */ - public function setDefaultOptions(OptionsResolverInterface $resolver) - { - $resolver - ->setDefaults(array( - 'class' => $this->className - )) - ; - } - - /** - * {@inheritdoc} - */ - public function getName() - { - return 'sylius_channel_choice'; - } -} diff --git a/src/Sylius/Bundle/ChannelBundle/Form/Type/ChannelEntityChoiceType.php b/src/Sylius/Bundle/ChannelBundle/Form/Type/ChannelEntityChoiceType.php deleted file mode 100644 index 2396815d10..0000000000 --- a/src/Sylius/Bundle/ChannelBundle/Form/Type/ChannelEntityChoiceType.php +++ /dev/null @@ -1,28 +0,0 @@ - - */ -class ChannelEntityChoiceType extends ChannelChoiceType -{ - /** - * {@inheritdoc} - */ - public function getParent() - { - return 'entity'; - } -} diff --git a/src/Sylius/Bundle/ChannelBundle/Resources/config/driver/doctrine/orm.xml b/src/Sylius/Bundle/ChannelBundle/Resources/config/driver/doctrine/orm.xml index 39a94f5580..07b0b55aca 100644 --- a/src/Sylius/Bundle/ChannelBundle/Resources/config/driver/doctrine/orm.xml +++ b/src/Sylius/Bundle/ChannelBundle/Resources/config/driver/doctrine/orm.xml @@ -18,7 +18,6 @@ Sylius\Bundle\ChannelBundle\Doctrine\ORM\ChannelRepository - Sylius\Bundle\ChannelBundle\Form\Type\ChannelEntityChoiceType diff --git a/src/Sylius/Bundle/ChannelBundle/Resources/config/services.xml b/src/Sylius/Bundle/ChannelBundle/Resources/config/services.xml index fb443327ba..b13f5e8c9c 100644 --- a/src/Sylius/Bundle/ChannelBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/ChannelBundle/Resources/config/services.xml @@ -17,21 +17,10 @@ http://symfony.com/schema/dic/services/services-1.0.xsd"> - Sylius\Bundle\ChannelBundle\Form\Type\ChannelType Sylius\Component\Channel\Context\ChannelContext - - %sylius.model.channel.class% - %sylius.validation_group.channel% - - - - %sylius.model.channel.class% - - - diff --git a/src/Sylius/Bundle/CoreBundle/Context/ChannelContext.php b/src/Sylius/Bundle/CoreBundle/Context/ChannelContext.php index 6119965c0a..73042ba696 100644 --- a/src/Sylius/Bundle/CoreBundle/Context/ChannelContext.php +++ b/src/Sylius/Bundle/CoreBundle/Context/ChannelContext.php @@ -38,13 +38,24 @@ class ChannelContext extends BaseChannelContext implements ChannelContextInterfa $this->channelResolver = $channelResolver; } + /** + * {@inheritdoc} + */ + public function getChannel() + { + if (null === $this->channel) { + $this->channel = $this->channelResolver->resolve(); + } + return $this->channel; + } + /** * @inheritdoc */ public function onKernelRequest(KernelEvent $event) { if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) { - $this->channel = $this->channelResolver->resolve($event->getRequest()); + $this->channel = $this->channelResolver->resolve($event->getRequest()->getHost()); } } } diff --git a/src/Sylius/Bundle/CoreBundle/Controller/ProductController.php b/src/Sylius/Bundle/CoreBundle/Controller/ProductController.php index 44ad833cd5..3473338711 100644 --- a/src/Sylius/Bundle/CoreBundle/Controller/ProductController.php +++ b/src/Sylius/Bundle/CoreBundle/Controller/ProductController.php @@ -238,6 +238,7 @@ class ProductController extends BaseProductController /** * @param Request $request * @param array $criteria + * * @return null|ProductInterface */ public function findOr404(Request $request, array $criteria = array()) diff --git a/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/PaymentRepository.php b/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/PaymentRepository.php index a4caef4716..2f56ab94e2 100644 --- a/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/PaymentRepository.php +++ b/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/PaymentRepository.php @@ -11,6 +11,7 @@ namespace Sylius\Bundle\CoreBundle\Doctrine\ORM; +use Pagerfanta\PagerfantaInterface; use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; class PaymentRepository extends EntityRepository @@ -28,9 +29,8 @@ class PaymentRepository extends EntityRepository $this->_em->getFilters()->disable('softdeleteable'); $queryBuilder = $this->getCollectionQueryBuilder(); - $queryBuilder - ->leftJoin($this->getAlias().'.order', 'paymentOrder') + ->leftJoin($this->getPropertyName('order'), 'paymentOrder') ->leftJoin('paymentOrder.billingAddress', 'address') ->addSelect('paymentOrder') ->addSelect('address') @@ -38,31 +38,31 @@ class PaymentRepository extends EntityRepository if (!empty($criteria['number'])) { $queryBuilder - ->andWhere('paymentOrder.number = :number') + ->andWhere($queryBuilder->expr()->eq('paymentOrder.number', ':number')) ->setParameter('number', $criteria['number']) ; } if (!empty($criteria['channel'])) { $queryBuilder - ->andWhere('paymentOrder.channel = :channel') + ->andWhere($queryBuilder->expr()->eq('paymentOrder.channel', ':channel')) ->setParameter('channel', $criteria['channel']) ; } if (!empty($criteria['billingAddress'])) { $queryBuilder - ->andWhere('address.lastName LIKE :billingAddress') + ->andWhere($queryBuilder->expr()->like('address.lastName', ':billingAddress')) ->setParameter('billingAddress', '%'.$criteria['billingAddress'].'%') ; } if (!empty($criteria['createdAtFrom'])) { $queryBuilder - ->andWhere($queryBuilder->expr()->gte($this->getAlias().'.createdAt', ':createdAtFrom')) + ->andWhere($queryBuilder->expr()->gte($this->getPropertyName('createdAt'), ':createdAtFrom')) ->setParameter('createdAtFrom', date('Y-m-d 00:00:00',strtotime($criteria['createdAtFrom']))) ; } if (!empty($criteria['createdAtTo'])) { $queryBuilder - ->andWhere($queryBuilder->expr()->lte($this->getAlias().'.createdAt', ':createdAtTo')) + ->andWhere($queryBuilder->expr()->lte($this->getPropertyName('createdAt'), ':createdAtTo')) ->setParameter('createdAtTo', date('Y-m-d 23:59:59', strtotime($criteria['createdAtTo']))) ; } diff --git a/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php b/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php index 800ffacb43..b617d8e9a2 100644 --- a/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php +++ b/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php @@ -12,6 +12,7 @@ namespace Sylius\Bundle\CoreBundle\Doctrine\ORM; use Doctrine\ORM\QueryBuilder; +use Pagerfanta\PagerfantaInterface; use Sylius\Bundle\ProductBundle\Doctrine\ORM\ProductRepository as BaseProductRepository; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\ProductInterface; @@ -26,8 +27,7 @@ use Sylius\Component\Core\Model\TaxonInterface; class ProductRepository extends BaseProductRepository { /** - * Create paginator for products categorized - * under given taxon. + * Create paginator for products categorized under given taxon. * * @param TaxonInterface $taxon * @param array $criteria @@ -49,8 +49,7 @@ class ProductRepository extends BaseProductRepository } /** - * Create paginator for products categorized - * under given taxon. + * Create paginator for products categorized under given taxon. * * @param TaxonInterface $taxon * diff --git a/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/PromotionRepository.php b/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/PromotionRepository.php index 86ab0db24c..f8f0b4b818 100644 --- a/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/PromotionRepository.php +++ b/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/PromotionRepository.php @@ -26,20 +26,20 @@ class PromotionRepository extends BasePromotionRepository */ public function findActiveByChannel(ChannelInterface $channel) { - $qb = $this + $queryBuilder = $this ->getCollectionQueryBuilder() - ->orderBy($this->getAlias().'.priority', 'DESC') + ->orderBy($this->getPropertyName('priority'), 'DESC') ; - $this->filterByActive($qb); + $this->filterByActive($queryBuilder); - $qb - ->innerJoin($this->getAlias().'.channels', 'channel') - ->andWhere('channel = :channel') + $queryBuilder + ->innerJoin($this->getPropertyName('channels'), 'channel') + ->andWhere($queryBuilder->expr()->eq('channel', ':channel')) ->setParameter('channel', $channel) ; - return $qb + return $queryBuilder ->getQuery() ->getResult() ; diff --git a/src/Sylius/Bundle/CoreBundle/EventListener/OrderChannelListener.php b/src/Sylius/Bundle/CoreBundle/EventListener/OrderChannelListener.php index b9f1c5524e..f250ae154d 100644 --- a/src/Sylius/Bundle/CoreBundle/EventListener/OrderChannelListener.php +++ b/src/Sylius/Bundle/CoreBundle/EventListener/OrderChannelListener.php @@ -23,13 +23,22 @@ use Symfony\Component\EventDispatcher\GenericEvent; */ class OrderChannelListener { + /** + * @var ChannelContextInterface + */ protected $channelContext; + /** + * @param ChannelContextInterface $channelContext + */ public function __construct(ChannelContextInterface $channelContext) { $this->channelContext = $channelContext; } + /** + * @param GenericEvent $event + */ public function processOrderChannel(GenericEvent $event) { $order = $event->getSubject(); diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/PaymentStepType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/PaymentStepType.php index d9d19a7144..2d012c6b1c 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/PaymentStepType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/PaymentStepType.php @@ -29,11 +29,13 @@ class PaymentStepType extends AbstractResourceType protected $channelContext; /** + * @param string $dataClass + * @param array $validationGroups * @param ChannelContextInterface $channelContext */ - public function __construct($dataClass, ChannelContextInterface $channelContext) + public function __construct($dataClass, array $validationGroups = array(), ChannelContextInterface $channelContext) { - parent::__construct($dataClass); + parent::__construct($dataClass, $validationGroups); $this->channelContext = $channelContext; } diff --git a/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/ShippingStepType.php b/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/ShippingStepType.php index 238b798a22..d855360793 100644 --- a/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/ShippingStepType.php +++ b/src/Sylius/Bundle/CoreBundle/Form/Type/Checkout/ShippingStepType.php @@ -29,11 +29,13 @@ class ShippingStepType extends AbstractResourceType protected $channelContext; /** + * @param string $dataClass + * @param array $validationGroups * @param ChannelContextInterface $channelContext */ - public function __construct($dataClass, ChannelContextInterface $channelContext) + public function __construct($dataClass, array $validationGroups = array(), ChannelContextInterface $channelContext) { - parent::__construct($dataClass); + parent::__construct($dataClass, $validationGroups); $this->channelContext = $channelContext; } diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius.yml b/src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius.yml index 9f18857dea..e82984f952 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius.yml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/app/sylius.yml @@ -39,7 +39,8 @@ sylius_channel: classes: channel: model: Sylius\Component\Core\Model\Channel - form: Sylius\Bundle\CoreBundle\Form\Type\ChannelType + form: + default: Sylius\Bundle\CoreBundle\Form\Type\ChannelType sylius_cart: resolver: sylius.cart_item_resolver.default @@ -284,7 +285,7 @@ sylius_rbac: sylius.group.update: Edit group sylius.group.delete: Delete group - sylius.manage.group: Manage channels + sylius.manage.channel: Manage channels sylius.channel.show: Show channel sylius.channel.index: List channels sylius.channel.create: Create channel diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/form.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/form.xml index 67fe08d271..e69e0795d4 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/config/form.xml +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/form.xml @@ -57,7 +57,8 @@ - %sylius.model.cart.class% + %sylius.model.order.class% + %sylius.validation_group.order% @@ -67,7 +68,8 @@ - %sylius.model.cart.class% + %sylius.model.order.class% + %sylius.validation_group.order% diff --git a/src/Sylius/Bundle/FixturesBundle/DataFixtures/ORM/LoadChannelData.php b/src/Sylius/Bundle/FixturesBundle/DataFixtures/ORM/LoadChannelData.php index 8d691d23b0..cd20669a22 100644 --- a/src/Sylius/Bundle/FixturesBundle/DataFixtures/ORM/LoadChannelData.php +++ b/src/Sylius/Bundle/FixturesBundle/DataFixtures/ORM/LoadChannelData.php @@ -28,10 +28,10 @@ class LoadChannelsData extends DataFixture public function load(ObjectManager $manager) { $url = $this->container->getParameter('router.request_context.host'); - $manager->persist($this->createChannel('WEB-UK', 'UK Webstore', $url, array('en_GB'), array('GBP'), array('DHL', 'UPS Ground'), array('Dummy', 'Stripe'))); - $manager->persist($this->createChannel('WEB-DE', 'Germany Webstore', null, array('de_DE'), array('EUR'), array('DHL', 'UPS Ground'), array('Dummy', 'Stripe'))); - $manager->persist($this->createChannel('WEB-US', 'United States Webstore', null, array('en_US'), array('USD'), array('FedEx', 'FedEx World Shipping'), array('Dummy', 'Stripe'))); - $manager->persist($this->createChannel('MOBILE', 'Mobile Store', null, array('en_GB', 'de_DE'), array('GBP', 'USD', 'EUR'), array('DHL', 'UPS Ground', 'FedEx'), array('Dummy', 'Stripe'))); + $manager->persist($this->createChannel('WEB-UK', 'UK Webstore', $url, array('en_GB'), array('GBP'), array('DHL', 'UPS Ground'), array('Dummy', 'StripeCheckout'))); + $manager->persist($this->createChannel('WEB-DE', 'Germany Webstore', null, array('de_DE'), array('EUR'), array('DHL', 'UPS Ground'), array('Dummy', 'StripeCheckout'))); + $manager->persist($this->createChannel('WEB-US', 'United States Webstore', null, array('en_US'), array('USD'), array('FedEx', 'FedEx World Shipping'), array('Dummy', 'StripeCheckout'))); + $manager->persist($this->createChannel('MOBILE', 'Mobile Store', null, array('en_GB', 'de_DE'), array('GBP', 'USD', 'EUR'), array('DHL', 'UPS Ground', 'FedEx'), array('Dummy', 'StripeCheckout'))); $manager->flush(); } diff --git a/src/Sylius/Bundle/PromotionBundle/Doctrine/ORM/PromotionRepository.php b/src/Sylius/Bundle/PromotionBundle/Doctrine/ORM/PromotionRepository.php index 8136f3b9ef..d94a09b66b 100644 --- a/src/Sylius/Bundle/PromotionBundle/Doctrine/ORM/PromotionRepository.php +++ b/src/Sylius/Bundle/PromotionBundle/Doctrine/ORM/PromotionRepository.php @@ -29,7 +29,7 @@ class PromotionRepository extends EntityRepository implements PromotionRepositor { $qb = $this ->getCollectionQueryBuilder() - ->orderBy($this->getAlias().'.priority', 'DESC') + ->orderBy($this->getPropertyName('priority'), 'DESC') ; $this->filterByActive($qb); @@ -43,9 +43,9 @@ class PromotionRepository extends EntityRepository implements PromotionRepositor protected function getCollectionQueryBuilder() { return parent::getCollectionQueryBuilder() - ->leftJoin($this->getAlias().'.rules', 'r') + ->leftJoin($this->getPropertyName('rules'), 'r') ->addSelect('r') - ->leftJoin($this->getAlias().'.actions', 'a') + ->leftJoin($this->getPropertyName('actions'), 'a') ->addSelect('a'); } @@ -58,14 +58,14 @@ class PromotionRepository extends EntityRepository implements PromotionRepositor return $qb ->where( $qb->expr()->orX( - $qb->expr()->isNull($this->getAlias().'.startsAt'), - $qb->expr()->lt($this->getAlias().'.startsAt', ':date') + $qb->expr()->isNull($this->getPropertyName('startsAt')), + $qb->expr()->lt($this->getPropertyName('startsAt'), ':date') ) ) ->andWhere( $qb->expr()->orX( - $qb->expr()->isNull($this->getAlias().'.endsAt'), - $qb->expr()->gt($this->getAlias().'.endsAt', ':date') + $qb->expr()->isNull($this->getPropertyName('endsAt')), + $qb->expr()->gt($this->getPropertyName('endsAt'), ':date') ) ) ->setParameter('date', $date) diff --git a/src/Sylius/Component/Channel/Repository/ChannelRepositoryInterface.php b/src/Sylius/Component/Channel/Repository/ChannelRepositoryInterface.php index a6a3735ddf..c37150efd1 100644 --- a/src/Sylius/Component/Channel/Repository/ChannelRepositoryInterface.php +++ b/src/Sylius/Component/Channel/Repository/ChannelRepositoryInterface.php @@ -11,6 +11,10 @@ namespace Sylius\Component\Channel\Repository; +use Doctrine\ORM\NonUniqueResultException; +use Doctrine\ORM\NoResultException; +use Sylius\Component\Channel\Model\ChannelInterface; + /** * Repository interface for channels. * @@ -22,8 +26,15 @@ interface ChannelRepositoryInterface * Find channel best matching given hostname. * * @param string $hostname - * - * @return null|ChannelInterface + * @return mixed + * @throws NonUniqueResultException */ public function findMatchingHostname($hostname); + + /** + * @return ChannelInterface + * @throws NonUniqueResultException + * @throws NoResultException + */ + public function findDefault(); } diff --git a/src/Sylius/Component/Core/Channel/ChannelResolver.php b/src/Sylius/Component/Core/Channel/ChannelResolver.php index 86f2c185ea..3c4e90f527 100644 --- a/src/Sylius/Component/Core/Channel/ChannelResolver.php +++ b/src/Sylius/Component/Core/Channel/ChannelResolver.php @@ -37,8 +37,12 @@ class ChannelResolver implements ChannelResolverInterface /** * {@inheritdoc} */ - public function resolve(Request $request) + public function resolve($hostname = null) { - return $this->channelRepository->findMatchingHostname($request->getHost()); + if (null === $hostname || null === $channel = $this->channelRepository->findMatchingHostname($hostname)) { + return $this->channelRepository->findDefault(); + } + + return $channel; } } diff --git a/src/Sylius/Component/Core/Channel/ChannelResolverInterface.php b/src/Sylius/Component/Core/Channel/ChannelResolverInterface.php index e793df8529..0ac8949c65 100644 --- a/src/Sylius/Component/Core/Channel/ChannelResolverInterface.php +++ b/src/Sylius/Component/Core/Channel/ChannelResolverInterface.php @@ -11,7 +11,7 @@ namespace Sylius\Component\Core\Channel; -use Symfony\Component\HttpFoundation\Request; +use Sylius\Component\Channel\Model\ChannelInterface; /** * Interface for service defining the currently used channel. @@ -23,9 +23,9 @@ interface ChannelResolverInterface /** * Get currently used channel. * - * @param Request $request + * @param string $hostname * - * @return null|ChannelInterface + * @return ChannelInterface */ - public function resolve(Request $request); + public function resolve($hostname = null); }