Пример #1
0
 /**
  * @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;
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 public function getList($products, Struct\ShopContextInterface $context, Struct\Customer\Group $customerGroup)
 {
     /**
      * Contains the cheapest price logic which product price should be selected.
      */
     $ids = $this->getCheapestPriceIds($products, $customerGroup);
     $query = $this->connection->createQueryBuilder();
     $query->select($this->fieldHelper->getPriceFields())->addSelect($this->fieldHelper->getUnitFields());
     $query->from('s_articles_prices', 'price')->innerJoin('price', 's_articles_details', 'variant', 'variant.id = price.articledetailsID')->innerJoin('variant', 's_articles', 'product', 'product.id = variant.articleID')->leftJoin('variant', 's_core_units', 'unit', 'unit.id = variant.unitID')->leftJoin('price', 's_articles_prices_attributes', 'priceAttribute', 'priceAttribute.priceID = price.id');
     $this->fieldHelper->addUnitTranslation($query, $context);
     $this->fieldHelper->addVariantTranslation($query, $context);
     $query->andWhere('price.id IN (:ids)')->setParameter(':ids', $ids, Connection::PARAM_INT_ARRAY);
     /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */
     $statement = $query->execute();
     $data = $statement->fetchAll(\PDO::FETCH_ASSOC);
     $prices = [];
     foreach ($data as $row) {
         $product = $row['__price_articleID'];
         $prices[$product] = $this->priceHydrator->hydrateCheapestPrice($row);
     }
     return $prices;
 }