From 8102395cf2bae36d2cb0080f85099f1c4d87efd5 Mon Sep 17 00:00:00 2001 From: Bartosz Pietrzak Date: Thu, 2 Aug 2018 10:43:59 +0200 Subject: [PATCH] BC break fix --- app/config/config.yml | 4 ++++ .../Doctrine/ORM/ProductRepository.php | 21 ++++++++++++------- .../DependencyInjection/Configuration.php | 8 +++++++ .../SyliusShopExtension.php | 4 ++++ .../Resources/config/grids/product.yml | 2 +- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/config/config.yml b/app/config/config.yml index a148ca3409a..39e301a73cf 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -68,3 +68,7 @@ liip_imagine: web_path: web_root: "%kernel.project_dir%/web" cache_prefix: "media/cache" + +sylius_shop: + product_grid: + include_all_descendants: true diff --git a/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php b/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php index 718bda34abd..38d25683e7d 100644 --- a/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php +++ b/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php @@ -75,22 +75,29 @@ public function createShopListQueryBuilder( $queryBuilder = $this->createQueryBuilder('o') ->addSelect('translation') ->innerJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale') - ->innerJoin('o.productTaxons', 'productTaxon') - ->innerJoin('productTaxon.taxon', 'taxon'); + ->innerJoin('o.productTaxons', 'productTaxon'); if ($includeAllDescendants) { - $queryBuilder->andWhere('taxon.left >= :taxonLeft'); - $queryBuilder->andWhere('taxon.right <= :taxonRight'); + $queryBuilder + ->innerJoin('productTaxon.taxon', 'taxon') + ->andWhere('taxon.left >= :taxonLeft') + ->andWhere('taxon.right <= :taxonRight') + ->andWhere('taxon.root = :taxonRoot') + ->setParameter('taxonLeft', $taxon->getLeft()) + ->setParameter('taxonRight', $taxon->getRight()) + ->setParameter('taxonRoot', $taxon->getRoot()) + ; } else { - $queryBuilder->andWhere('productTaxon.taxon = :taxon'); + $queryBuilder + ->andWhere('productTaxon.taxon = :taxon') + ->setParameter('taxon', $taxon) + ; } $queryBuilder ->andWhere(':channel MEMBER OF o.channels') ->andWhere('o.enabled = true') ->setParameter('locale', $locale) - ->setParameter('taxonLeft', $taxon->getLeft()) - ->setParameter('taxonRight', $taxon->getRight()) ->setParameter('channel', $channel) ; diff --git a/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php b/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php index 8b1dcabaf3e..ff13f867c67 100644 --- a/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php +++ b/src/Sylius/Bundle/ShopBundle/DependencyInjection/Configuration.php @@ -58,6 +58,14 @@ public function getConfigTreeBuilder(): TreeBuilder ->end() ->end() ->end() + ->arrayNode('product_grid') + ->addDefaultsIfNotSet() + ->children() + ->booleanNode('include_all_descendants') + ->defaultFalse() + ->end() + ->end() + ->end() ->end() ; diff --git a/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php b/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php index b9dcd20d2d4..41413331a28 100644 --- a/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php +++ b/src/Sylius/Bundle/ShopBundle/DependencyInjection/SyliusShopExtension.php @@ -38,6 +38,10 @@ public function load(array $config, ContainerBuilder $container): void $loader->load(sprintf('services/integrations/locale/%s.xml', $config['locale_switcher'])); $container->setParameter('sylius_shop.firewall_context_name', $config['firewall_context_name']); + $container->setParameter( + 'sylius_shop.product_grid.include_all_descendants', + $config['product_grid']['include_all_descendants'] + ); $this->configureCheckoutResolverIfNeeded($config['checkout_resolver'], $container); } diff --git a/src/Sylius/Bundle/ShopBundle/Resources/config/grids/product.yml b/src/Sylius/Bundle/ShopBundle/Resources/config/grids/product.yml index da7122b1c59..6de55cfd7fb 100644 --- a/src/Sylius/Bundle/ShopBundle/Resources/config/grids/product.yml +++ b/src/Sylius/Bundle/ShopBundle/Resources/config/grids/product.yml @@ -15,7 +15,7 @@ sylius_grid: taxon: "expr:notFoundOnNull(service('sylius.repository.taxon').findOneBySlug($slug, service('sylius.context.locale').getLocaleCode()))" locale: "expr:service('sylius.context.locale').getLocaleCode()" sorting: "expr:service('request_stack').getCurrentRequest().get('sorting', [])" - includeAllDescendants: true + includeAllDescendants: "expr:parameter('sylius_shop.product_grid.include_all_descendants')" sorting: position: asc limits: [9, 18, 27]