custom/plugins/MaxiaListingVariants6/src/Service/ListingVariantsLoaderFactory.php line 14

Open in your IDE?
  1. <?php
  2. namespace Maxia\MaxiaListingVariants6\Service;
  3. use Monolog\Logger;
  4. use Doctrine\DBAL\Connection;
  5. use Shopware\Core\PlatformRequest;
  6. use Symfony\Component\DependencyInjection\ContainerInterface;
  7. use Symfony\Component\HttpFoundation\RequestStack;
  8. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  9. class ListingVariantsLoaderFactory
  10. {
  11.     public static function create(
  12.         string $class,
  13.         ContainerInterface $container,
  14.         Logger $logger,
  15.         RequestStack $requestStack,
  16.         EventDispatcherInterface $eventDispatcher,
  17.         Connection $dbConnection,
  18.         ProductConfiguratorLoaderInterface $configuratorLoader,
  19.         VariantMappingLoaderInterface $variantMappingLoader,
  20.         ProductCombinationFinder $combinationFinder,
  21.         $productRepository,
  22.         $mediaRepository,
  23.         $productMediaRepository,
  24.         VariantDisplayConfigLoader $variantDisplayConfigLoader,
  25.         ConfigService $configService
  26.     ): ListingVariantsLoaderInterface
  27.     {
  28.         if (self::isCacheEnabled($requestStack$configService)) {
  29.             if ($container->has('Maxia\MaxiaListingVariants6\Service\CachedProductConfiguratorLoader')) {
  30.                 $configuratorLoader $container
  31.                     ->get('Maxia\MaxiaListingVariants6\Service\CachedProductConfiguratorLoader');
  32.             }
  33.             if ($container->has('Maxia\MaxiaListingVariants6\Service\CachedVariantMappingLoader')) {
  34.                 $variantMappingLoader $container
  35.                     ->get('Maxia\MaxiaListingVariants6\Service\CachedVariantMappingLoader');
  36.             }
  37.         }
  38.         return new $class(
  39.             $container,
  40.             $logger,
  41.             $requestStack,
  42.             $eventDispatcher,
  43.             $dbConnection,
  44.             $configuratorLoader,
  45.             $variantMappingLoader,
  46.             $combinationFinder,
  47.             $productRepository,
  48.             $mediaRepository,
  49.             $productMediaRepository,
  50.             $variantDisplayConfigLoader,
  51.             $configService
  52.         );
  53.     }
  54.     protected static function isCacheEnabled(RequestStack $requestStackConfigService $configService)
  55.     {
  56.         if (!$requestStack->getMainRequest()) {
  57.             return false;
  58.         }
  59.         $salesChannelId $requestStack->getMainRequest()
  60.             ->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID);
  61.         if (!$salesChannelId) {
  62.             return false;
  63.         }
  64.         return $configService->getBaseConfig($salesChannelId)->isCacheEnabled();
  65.     }
  66. }