vendor/shopware/core/Content/Product/SalesChannel/Detail/AvailableCombinationLoader.php line 39

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Product\SalesChannel\Detail;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Framework\Context;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Doctrine\FetchModeHelper;
  6. use Shopware\Core\Framework\Feature;
  7. use Shopware\Core\Framework\Uuid\Uuid;
  8. class AvailableCombinationLoader
  9. {
  10.     private Connection $connection;
  11.     /**
  12.      * @internal
  13.      */
  14.     public function __construct(Connection $connection)
  15.     {
  16.         $this->connection $connection;
  17.     }
  18.     /**
  19.      * @deprecated tag:v6.5.0
  20.      * Parameter $salesChannelId will be mandatory in future implementation
  21.      */
  22.     public function load(string $productIdContext $context/*, string $salesChannelId*/): AvailableCombinationResult
  23.     {
  24.         $salesChannelId null;
  25.         if (\func_num_args() === 3) {
  26.             $salesChannelId func_get_arg(2);
  27.             if (\gettype($salesChannelId) !== 'string') {
  28.                 throw new \InvalidArgumentException('Argument 3 $salesChannelId must be of type string.');
  29.             }
  30.         }
  31.         if ($salesChannelId === null) {
  32.             Feature::triggerDeprecationOrThrow(
  33.                 'v6.5.0.0',
  34.                 \sprintf('"%s::%s()" will require the salesChannelId as third parameter in v6.5.0.0'__CLASS____METHOD__)
  35.             );
  36.         }
  37.         $query $this->connection->createQueryBuilder();
  38.         $query->from('product');
  39.         $query->leftJoin('product''product''parent''product.parent_id = parent.id');
  40.         $query->andWhere('product.parent_id = :id');
  41.         $query->andWhere('product.version_id = :versionId');
  42.         $query->andWhere('IFNULL(product.active, parent.active) = :active');
  43.         $query->andWhere('product.option_ids IS NOT NULL');
  44.         $query->setParameter('id'Uuid::fromHexToBytes($productId));
  45.         $query->setParameter('versionId'Uuid::fromHexToBytes($context->getVersionId()));
  46.         $query->setParameter('active'true);
  47.         if ($salesChannelId !== null) {
  48.             $query->innerJoin('product''product_visibility''visibilities''product.visibilities = visibilities.product_id');
  49.             $query->andWhere('visibilities.sales_channel_id = :salesChannelId');
  50.             $query->setParameter('salesChannelId'Uuid::fromHexToBytes($salesChannelId));
  51.         }
  52.         $query->select([
  53.             'LOWER(HEX(product.id))',
  54.             'product.option_ids as options',
  55.             'product.product_number as productNumber',
  56.             'product.available',
  57.         ]);
  58.         $combinations $query->execute()->fetchAll();
  59.         $combinations FetchModeHelper::groupUnique($combinations);
  60.         $result = new AvailableCombinationResult();
  61.         foreach ($combinations as $combination) {
  62.             $available = (bool) $combination['available'];
  63.             $options json_decode($combination['options'], true);
  64.             if ($options === false) {
  65.                 continue;
  66.             }
  67.             $result->addCombination($options$available);
  68.         }
  69.         return $result;
  70.     }
  71. }