/**
  * @param Struct\Customer\Group $customerGroup
  * @param Struct\ShopContextInterface $context
  * @return array|Struct\Product\PriceGroup[]
  */
 public function getPriceGroups(Struct\Customer\Group $customerGroup, Struct\ShopContextInterface $context)
 {
     $query = $this->connection->createQueryBuilder();
     $query->addSelect('priceGroupDiscount.groupID')->addSelect($this->fieldHelper->getPriceGroupDiscountFields())->addSelect($this->fieldHelper->getPriceGroupFields());
     $query->from('s_core_pricegroups_discounts', 'priceGroupDiscount')->innerJoin('priceGroupDiscount', 's_core_pricegroups', 'priceGroup', 'priceGroup.id = priceGroupDiscount.groupID');
     $query->andWhere('priceGroupDiscount.customergroupID = :customerGroup');
     $query->groupBy('priceGroupDiscount.id');
     $query->orderBy('priceGroupDiscount.groupID')->addOrderBy('priceGroupDiscount.discountstart');
     $query->setParameter(':customerGroup', $customerGroup->getId());
     /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */
     $statement = $query->execute();
     $data = $statement->fetchAll(\PDO::FETCH_GROUP);
     $priceGroups = [];
     foreach ($data as $row) {
         $priceGroup = $this->priceHydrator->hydratePriceGroup($row);
         foreach ($priceGroup->getDiscounts() as $discount) {
             $discount->setCustomerGroup($customerGroup);
         }
         $priceGroups[$priceGroup->getId()] = $priceGroup;
     }
     return $priceGroups;
 }
예제 #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;
 }
 /**
  * @inheritdoc
  */
 public function getList($products, Struct\Customer\Group $customerGroup)
 {
     $ids = [];
     foreach ($products as $product) {
         $ids[] = $product->getVariantId();
     }
     $ids = array_unique($ids);
     $query = $this->connection->createQueryBuilder();
     $query->select($this->fieldHelper->getPriceFields());
     $query->addSelect('variants.ordernumber as number');
     $query->from('s_articles_prices', 'price')->innerJoin('price', 's_articles_details', 'variants', 'variants.id = price.articledetailsID')->leftJoin('price', 's_articles_prices_attributes', 'priceAttribute', 'priceAttribute.priceID = price.id');
     $query->where('price.articledetailsID IN (:products)')->andWhere('price.pricegroup = :customerGroup')->setParameter(':products', $ids, Connection::PARAM_INT_ARRAY)->setParameter(':customerGroup', $customerGroup->getKey());
     $query->orderBy('price.articledetailsID', 'ASC')->addOrderBy('price.from', 'ASC');
     /**@var $statement \Doctrine\DBAL\Driver\ResultStatement */
     $statement = $query->execute();
     $data = $statement->fetchAll(\PDO::FETCH_ASSOC);
     $prices = [];
     foreach ($data as $row) {
         $product = $row['number'];
         $prices[$product][] = $this->priceHydrator->hydratePriceRule($row);
     }
     return $prices;
 }