diff --git a/src/Sylius/Bundle/ApiBundle/Doctrine/ORM/QueryExtension/Common/EnabledExtension.php b/src/Sylius/Bundle/ApiBundle/Doctrine/ORM/QueryExtension/Shop/Common/EnabledExtension.php similarity index 83% rename from src/Sylius/Bundle/ApiBundle/Doctrine/ORM/QueryExtension/Common/EnabledExtension.php rename to src/Sylius/Bundle/ApiBundle/Doctrine/ORM/QueryExtension/Shop/Common/EnabledExtension.php index 162e1655e1..f63bf90545 100644 --- a/src/Sylius/Bundle/ApiBundle/Doctrine/ORM/QueryExtension/Common/EnabledExtension.php +++ b/src/Sylius/Bundle/ApiBundle/Doctrine/ORM/QueryExtension/Shop/Common/EnabledExtension.php @@ -11,22 +11,20 @@ declare(strict_types=1); -namespace Sylius\Bundle\ApiBundle\Doctrine\ORM\QueryExtension\Common; +namespace Sylius\Bundle\ApiBundle\Doctrine\ORM\QueryExtension\Shop\Common; use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface; use ApiPlatform\Doctrine\Orm\Extension\QueryItemExtensionInterface; use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface; use ApiPlatform\Metadata\Operation; use Doctrine\ORM\QueryBuilder; +use Sylius\Bundle\ApiBundle\SectionResolver\ShopApiSection; use Sylius\Bundle\CoreBundle\SectionResolver\SectionProviderInterface; +use Sylius\Resource\Model\ToggleableInterface; final readonly class EnabledExtension implements QueryCollectionExtensionInterface, QueryItemExtensionInterface { - public function __construct( - private SectionProviderInterface $sectionProvider, - private string $resourceClass, - private string $section, - ) { + public function __construct(private SectionProviderInterface $sectionProvider) { } /** @@ -62,11 +60,11 @@ final readonly class EnabledExtension implements QueryCollectionExtensionInterfa QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ): void { - if (!is_a($resourceClass, $this->resourceClass, true)) { + if (!is_a($resourceClass, ToggleableInterface::class, true)) { return; } - if (!$this->sectionProvider->getSection() instanceof $this->section) { + if (!$this->sectionProvider->getSection() instanceof ShopApiSection) { return; } diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/extensions.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/extensions.xml index 879f367c6a..dc45cd542e 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/extensions.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/extensions.xml @@ -95,16 +95,6 @@ - - - %sylius.model.product.class% - Sylius\Bundle\ApiBundle\SectionResolver\ShopApiSection - - - - %sylius.model.product_variant.class% - Sylius\Bundle\ApiBundle\SectionResolver\ShopApiSection @@ -230,16 +218,6 @@ - - - %sylius.model.taxon.class% - Sylius\Bundle\ApiBundle\SectionResolver\ShopApiSection - - - beConstructedWith( - $sectionProvider, - ProductVariantInterface::class, - ShopApiSection::class, - ); + $this->beConstructedWith($sectionProvider); } public function it_does_not_apply_conditions_to_item_for_unsupported_resource( @@ -53,7 +50,7 @@ final class EnabledExtensionSpec extends ObjectBehavior ): void { $sectionProvider->getSection()->willReturn($adminApiSection); - $this->applyToItem($queryBuilder, $queryNameGenerator, ProductVariantInterface::class, []); + $this->applyToItem($queryBuilder, $queryNameGenerator, ToggleableInterface::class, []); $queryBuilder->getRootAliases()->shouldNotHaveBeenCalled(); $queryBuilder->andWhere()->shouldNotHaveBeenCalled(); @@ -77,7 +74,7 @@ final class EnabledExtensionSpec extends ObjectBehavior $this->applyToItem( $queryBuilder, $queryNameGenerator, - ProductVariantInterface::class, + ToggleableInterface::class, [], new Get(), [ContextKeys::CHANNEL => $channel, ContextKeys::LOCALE_CODE => 'en_US'], @@ -102,7 +99,7 @@ final class EnabledExtensionSpec extends ObjectBehavior ): void { $sectionProvider->getSection()->willReturn($adminApiSection); - $this->applyToCollection($queryBuilder, $queryNameGenerator, ProductVariantInterface::class); + $this->applyToCollection($queryBuilder, $queryNameGenerator, ToggleableInterface::class); $queryBuilder->getRootAliases()->shouldNotHaveBeenCalled(); $queryBuilder->andWhere()->shouldNotHaveBeenCalled(); @@ -126,7 +123,7 @@ final class EnabledExtensionSpec extends ObjectBehavior $this->applyToCollection( $queryBuilder, $queryNameGenerator, - ProductVariantInterface::class, + ToggleableInterface::class, new Get(), [ContextKeys::CHANNEL => $channel, ContextKeys::LOCALE_CODE => 'en_US'], ); diff --git a/tests/Api/DataFixtures/ORM/product/product_variant_with_original_price.yaml b/tests/Api/DataFixtures/ORM/product/product_variant_with_original_price.yaml index ea08c5a65a..9d19d38ce8 100644 --- a/tests/Api/DataFixtures/ORM/product/product_variant_with_original_price.yaml +++ b/tests/Api/DataFixtures/ORM/product/product_variant_with_original_price.yaml @@ -29,6 +29,11 @@ Sylius\Component\Core\Model\Product: channels: ['@channel_web'] currentLocale: 'en_US' options: ['@product_option_color'] + product_mug_disabled: + code: 'MUG_DISABLED' + channels: ['@channel_web'] + currentLocale: 'en_US' + enabled: false Sylius\Component\Core\Model\ProductTranslation: product_translation_mug: @@ -37,6 +42,12 @@ Sylius\Component\Core\Model\ProductTranslation: name: 'Mug' description: '' translatable: '@product_mug' + product_translation_mug_disabled: + slug: 'mug-disabled' + locale: 'en_US' + name: 'Mug Disabled' + description: '' + translatable: '@product_mug_disabled' Sylius\Component\Core\Model\ProductVariant: product_variant_mug_blue: