Beispiel #1
0
 /**
  * @param Group $customerGroup used for the price definition
  * @param string $number
  * @param array $data Contains nested configurator group > option array.
  * @return array
  */
 public function getConfigurator(Group $customerGroup, $number, array $data = array())
 {
     if (empty($data)) {
         $data = array('Farbe' => array('rot', 'gelb', 'blau'));
     }
     $groups = $this->insertConfiguratorData($data);
     $configurator = $this->createConfiguratorSet($groups);
     $variants = array_merge(array('prices' => $this->getGraduatedPrices($customerGroup->getKey())), $this->getUnitData());
     $variants = $this->generateVariants($configurator['groups'], $number, $variants);
     return array('configuratorSet' => $configurator, 'variants' => $variants);
 }
 /**
  * Pre selection of the cheapest prices ids.
  *
  * @param Struct\BaseProduct[] $products
  * @param Struct\Customer\Group $customerGroup
  * @return array
  */
 private function getCheapestPriceIds($products, Struct\Customer\Group $customerGroup)
 {
     $ids = [];
     foreach ($products as $product) {
         $ids[] = $product->getId();
     }
     $ids = array_unique($ids);
     $subQuery = $this->connection->createQueryBuilder();
     $subQuery->select('prices.id')->from('s_articles_prices', 'prices');
     /**
      * joins the product variants for the min purchase calculation.
      * The cheapest price is defined by prices.price * variant.minpurchase (the real basket price)
      */
     $subQuery->innerJoin('prices', 's_articles_details', 'variant', 'variant.id = prices.articledetailsID');
     /**
      * Joins the products for the closeout validation.
      * Required to select only product prices which product variant can be added to the basket and purchased
      */
     $subQuery->innerJoin('variant', 's_articles', 'product', 'product.id = variant.articleID');
     $graduation = 'prices.from = 1';
     if ($this->config->get('useLastGraduationForCheapestPrice')) {
         $graduation = "prices.to = 'beliebig'";
     }
     $subQuery->where('prices.pricegroup = :customerGroup')->andWhere($graduation)->andWhere('variant.active = 1')->andWhere('prices.articleID = outerPrices.articleID');
     /**
      * This part of the query handles the closeout products.
      *
      * The `laststock` column contains "1" if the product is a closeout product.
      * In the case that the product contains the closeout flag,
      * the stock and minpurchase are used as they defined in the database
      *
      * In the case that the product isn't a closeout product,
      * the stock and minpurchase are set to 0
      */
     $subQuery->andWhere('(product.laststock * variant.instock) >= (product.laststock * variant.minpurchase)');
     $subQuery->setMaxResults(1);
     if ($this->config->get('calculateCheapestPriceWithMinPurchase')) {
         /**
          * Sorting by the cheapest available price
          */
         $subQuery->orderBy('(prices.price * variant.minpurchase)');
     } else {
         /**
          * Sorting by the cheapest unit price
          */
         $subQuery->orderBy('prices.price');
     }
     /**
      * Creates an outer query which allows to
      * select multiple cheapest product prices.
      */
     $query = $this->connection->createQueryBuilder();
     $query->setParameter(':customerGroup', $customerGroup->getKey());
     $query->select('(' . $subQuery->getSQL() . ') as priceId')->from('s_articles_prices', 'outerPrices')->where('outerPrices.articleID IN (:products)')->setParameter(':products', $ids, Connection::PARAM_INT_ARRAY)->groupBy('outerPrices.articleID')->having('priceId IS NOT NULL');
     $statement = $query->execute();
     return $statement->fetchAll(\PDO::FETCH_COLUMN);
 }
 /**
  * @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;
 }