/** * @param array $numbers * @param Struct\ShopContextInterface $context * @return \Doctrine\DBAL\Query\QueryBuilder */ protected function getQuery(array $numbers, Struct\ShopContextInterface $context) { $esdQuery = $this->getEsdQuery(); $customerGroupQuery = $this->getCustomerGroupQuery(); $availableVariantQuery = $this->getHasAvailableVariantQuery(); $fallbackPriceQuery = $this->getPriceCountQuery(':fallback'); $query = $this->connection->createQueryBuilder(); $query->select($this->fieldHelper->getArticleFields())->addSelect($this->fieldHelper->getTopSellerFields())->addSelect($this->fieldHelper->getVariantFields())->addSelect($this->fieldHelper->getUnitFields())->addSelect($this->fieldHelper->getTaxFields())->addSelect($this->fieldHelper->getPriceGroupFields())->addSelect($this->fieldHelper->getManufacturerFields())->addSelect($this->fieldHelper->getEsdFields())->addSelect('(' . $esdQuery->getSQL() . ') as __product_has_esd')->addSelect('(' . $customerGroupQuery->getSQL() . ') as __product_blocked_customer_groups')->addSelect('(' . $availableVariantQuery->getSQL() . ') as __product_has_available_variants')->addSelect('(' . $fallbackPriceQuery->getSQL() . ') as __product_fallback_price_count'); $query->setParameter(':fallback', $context->getFallbackCustomerGroup()->getKey()); if ($context->getCurrentCustomerGroup()->getId() !== $context->getFallbackCustomerGroup()->getId()) { $customerPriceQuery = $this->getPriceCountQuery(':current'); $query->addSelect('(' . $customerPriceQuery->getSQL() . ') as __product_custom_price_count'); $query->setParameter(':current', $context->getCurrentCustomerGroup()->getKey()); } $query->from('s_articles_details', 'variant')->innerJoin('variant', 's_articles', 'product', 'product.id = variant.articleID')->innerJoin('product', 's_core_tax', 'tax', 'tax.id = product.taxID')->leftJoin('variant', 's_core_units', 'unit', 'unit.id = variant.unitID')->leftJoin('product', 's_articles_supplier', 'manufacturer', 'manufacturer.id = product.supplierID')->leftJoin('product', 's_core_pricegroups', 'priceGroup', 'priceGroup.id = product.pricegroupID')->leftJoin('variant', 's_articles_attributes', 'productAttribute', 'productAttribute.articledetailsID = variant.id')->leftJoin('product', 's_articles_supplier_attributes', 'manufacturerAttribute', 'manufacturerAttribute.supplierID = product.supplierID')->leftJoin('product', 's_articles_top_seller_ro', 'topSeller', 'topSeller.article_id = product.id')->leftJoin('variant', 's_articles_esd', 'esd', 'esd.articledetailsID = variant.id')->leftJoin('esd', 's_articles_esd_attributes', 'esdAttribute', 'esdAttribute.esdID = esd.id')->where('variant.ordernumber IN (:numbers)')->andWhere('variant.active = 1')->andWhere('product.active = 1')->setParameter(':numbers', $numbers, Connection::PARAM_STR_ARRAY); $this->fieldHelper->addProductTranslation($query, $context); $this->fieldHelper->addVariantTranslation($query, $context); $this->fieldHelper->addManufacturerTranslation($query, $context); $this->fieldHelper->addUnitTranslation($query, $context); return $query; }