Builds SQL for selecting articles by price

@param double $dPriceFrom Starting price
@param double $dPriceTo   Max price

@return string
1930
protected function _getPriceSelect($dPriceFrom, $dPriceTo)
    {
        $oBaseObject = $this->getBaseObject();
        $sArticleTable = $oBaseObject->getViewName();
        $sSelectFields = $oBaseObject->getSelectFields();

        $sSelect = "select {$sSelectFields} from {$sArticleTable} where oxvarminprice >= 0 ";
        $sSelect .= $dPriceTo ? "and oxvarminprice <= " . (double) $dPriceTo . " " : " ";
        $sSelect .= $dPriceFrom ? "and oxvarminprice  >= " . (double) $dPriceFrom . " " : " ";

        $sSelect .= " and " . $oBaseObject->getSqlActiveSnippet() . " and {$sArticleTable}.oxissearch = 1";

        if (!$this->_sCustomSorting) {
            $sSelect .= " order by {$sArticleTable}.oxvarminprice asc , {$sArticleTable}.oxid";
        } else {
            $sSelect .= " order by {$this->_sCustomSorting}, {$sArticleTable}.oxid ";
        }

        return $sSelect;
    }
288540
public function getTPrice()
    {
        if (!\OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('bl_perfLoadPrice') || !$this->_blLoadPrice) {
            return;
        }

        // return cached result, since oPrice is created ONLY in this function [or function of EQUAL level]
        if ($this->_oTPrice !== null) {
            return $this->_oTPrice;
        }

        $oPrice = $this->_getPriceObject();

        $dBasePrice = $this->oxarticles__oxtprice->value;
        $dBasePrice = $this->_preparePrice($dBasePrice, $this->getArticleVat());

        $oPrice->setPrice($dBasePrice);

        $this->_applyVat($oPrice, $this->getArticleVat());
        $this->_applyCurrency($oPrice);

        if ($this->isParentNotBuyable()) {
            // if parent article is not buyable then compare agains min article variant price
            $oPrice2 = $this->getVarMinPrice();
        } else {
            // else compare against article price
            $oPrice2 = $this->getPrice();
        }

        if ($oPrice->getPrice() <= $oPrice2->getPrice()) {
            // if RRP price is less or equal to comparable price then return
            return;
        }

        $this->_oTPrice = $oPrice;

        return $this->_oTPrice;
    }
338076
public function getSelections($iLimit = null, $aFilter = null)
    {
        $sId = $this->getId() . ((int) $iLimit);
        if (!array_key_exists($sId, self::$_aSelections)) {
            $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
            $sSLViewName = getViewName('oxselectlist');

            $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
                   where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";

            if (($iLimit = (int) $iLimit)) {
                $sQ .= " limit $iLimit ";
            }

            // vat value for price
            $dVat = 0;
            if (($oPrice = $this->getPrice()) != null) {
                $dVat = $oPrice->getVat();
            }

            // all selectlists this article has
            $oList = oxNew(\OxidEsales\Eshop\Core\Model\ListModel::class);
            $oList->init('oxselectlist');
            $oList->getBaseObject()->setVat($dVat);
            $oList->selectString(sprintf($sQ, $oDb->quote($this->getId())));

            //#1104S if this is variant and it has no selectlists, trying with parent
            if ($oList->count() == 0 && $this->oxarticles__oxparentid->value) {
                $oList->selectString(sprintf($sQ, $oDb->quote($this->oxarticles__oxparentid->value)));
            }

            self::$_aSelections[$sId] = $oList->count() ? $oList : false;
        }

        if (self::$_aSelections[$sId]) {
            // marking active from filter
            $aFilter = ($aFilter === null) ? \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("sel") : $aFilter;
            if ($aFilter) {
                $iSelIdx = 0;
                foreach (self::$_aSelections[$sId] as $oSelection) {
                    if (isset($aFilter[$iSelIdx])) {
                        $oSelection->setActiveSelectionByIndex($aFilter[$iSelIdx]);
                    }
                    $iSelIdx++;
                }
            }
        }

        return self::$_aSelections[$sId];
    }
556909
public function getFPrice()
    {
        $dPrice = $this->getPrice();

        return \OxidEsales\Eshop\Core\Registry::getLang()->formatCurrency($dPrice, \OxidEsales\Eshop\Core\Registry::getConfig()->getActShopCurrencyObject());
    }
973659
public function getAbsValue($dPrice, $dAmount = 1)
    {
        if ($this->oxdiscount__oxaddsumtype->value == '%') {
            return $dPrice * ($this->oxdiscount__oxaddsum->value / 100);
        } else {
            $oCur = \OxidEsales\Eshop\Core\Registry::getConfig()->getActShopCurrencyObject();

            return $this->oxdiscount__oxaddsum->value * $dAmount * $oCur->rate;
        }
    }
1204151
public function postSelect(StatementInterface $statement, ResultInterface $result, ResultSetInterface $resultSet)
    {
        if ($this->getDmsColumns())
            // We have used the query with presented Predefined DMS Columns
            // Nothing to do
            return;

        $storedValues = $this->getStoredValues();
        $pkColumn     = $storedValues['pk'];

        $totalResultSet = array();
        foreach($resultSet as $rc)
        {
            if (!$rc instanceof iDataSetConveyor)
                throw new \Exception(sprintf(
                    'ResultSet must instance of iDataSetConveyor to DmsFeature interact to. "%s" given.'
                    , get_class($rc)
                ));

            $rc = $rc->toArray();

            $pk = $rc[$pkColumn]; // get pk column value
            foreach ($rc as $c => $v) {
                // iterate trough result containing duplicated rows because of join over dms values
                if ($c == 'dms__content' || $c == 'dms__field')
                    // dms virtual columns avoided and set as field->content
                    continue;

                if ($c == $pkColumn
                    && (!in_array($pkColumn, $storedValues['columns'])
                        && !in_array('*', $storedValues['columns'])
                    )
                )
                    continue;


                $totalResultSet[$pk][$c] = $v;
            }

            if (isset($rc['dms__content']) && isset($rc['dms__field'])) {
                if (in_array($rc['dms__field'], $storedValues['columns'])
                    || in_array('*', $storedValues['columns'])
                )
                {
                    $column = $rc['dms__field'];
                    $value  = $rc['dms__content'];
                    $totalResultSet[$pk][$column] = $value;
                }

                unset($rc['dms__field']);
                unset($rc['dms__content']);
            }
        }

        $resultSet->initialize($totalResultSet);
    }
450495
protected function _setVarMinMaxPrice($sParentId)
    {
        if ($sParentId) {
            $database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
            $sQ = '
                SELECT
                    MIN( IF( `oxarticles`.`oxprice` > 0, `oxarticles`.`oxprice`, `p`.`oxprice` ) ) AS `varminprice`,
                    MAX( IF( `oxarticles`.`oxprice` > 0, `oxarticles`.`oxprice`, `p`.`oxprice` ) ) AS `varmaxprice`
                FROM ' . $this->getViewName(true) . ' AS `oxarticles`
                    LEFT JOIN ' . $this->getViewName(true) . ' AS `p` ON ( `p`.`oxid` = `oxarticles`.`oxparentid` AND `p`.`oxprice` > 0 )
                WHERE ' . $this->getSqlActiveSnippet(true) . '
                    AND ( `oxarticles`.`oxparentid` = ' . $database->quote($sParentId) . ' )';
            $aPrices = $database->getRow($sQ);
            if (isset($aPrices['varminprice'], $aPrices['varmaxprice'])) {
                $sQ = '
                    UPDATE `oxarticles`
                    SET
                        `oxvarminprice` = ' . $database->quote($aPrices['varminprice']) . ',
                        `oxvarmaxprice` = ' . $database->quote($aPrices['varmaxprice']) . '
                    WHERE
                        `oxid` = ' . $database->quote($sParentId);
            } else {
                $sQ = '
                    UPDATE `oxarticles`
                    SET
                        `oxvarminprice` = `oxprice`,
                        `oxvarmaxprice` = `oxprice`
                    WHERE
                        `oxid` = ' . $database->quote($sParentId);
            }
            $database->execute($sQ);
        }
    }
1371496
public static function priceEditor($tid = 0) {
    $build = [];
    $query = \Drupal::database()->select('site_commerce', 'n');
    $query->fields('n', array('pid'));
    $query->condition('status', 1);
    $query->innerJoin('site_commerce_field_data', 'f', 'f.pid=n.pid');
    if ($tid) {
      $query->innerJoin('site_commerce__field_category', 'c', 'c.entity_id=n.pid');
      $query->condition('field_category_target_id', $tid);
    }
    $query->orderBy('f.weight');
    $pids = $query->execute()->fetchCol();
    $site_commerces = \Drupal::entityTypeManager()->getStorage('site_commerce')->loadMultiple($pids);
    if (count($site_commerces)) {
      $build['products'] = array(
        '#theme' => 'site_commerce_price_editor',
        '#site_commerces' => $site_commerces,
        '#tid' => $tid,
        '#attached' => array(
          'library' => array(
            'site_commerce/administer',
          ),
        ),
        '#cache' => [
          'max-age' => 0,
        ],
      );
    }

    return $build;
  }
529476
protected function getByPriceASC() : array
    {
        //Get product ID list (sort by offer price)
        //We can not use groupBy() in this place
        $arElementIDList = (array) DB::table('lovata_shopaholic_prices')
            ->select('lovata_shopaholic_offers.product_id')
            ->whereNull('lovata_shopaholic_prices.price_type_id')
            ->where('lovata_shopaholic_offers.active', true)
            ->where('lovata_shopaholic_prices.item_type', Offer::class)
            ->orderBy('lovata_shopaholic_prices.price', 'asc')
            ->join('lovata_shopaholic_offers', 'lovata_shopaholic_offers.id', '=', 'lovata_shopaholic_prices.item_id')
            ->lists('product_id');
        $arElementIDList = array_unique($arElementIDList);

        return $arElementIDList;
    }
1185341
public static function makePriceFromDB($price)
    {

        $price_element = explode('.', $price);

        $cent = $price_element[1];

        $cent = str_pad($cent, '0', STR_PAD_LEFT);

        return ',' . $price_element[0] . $cent;
    }
696165
public function getPrice()
    {
        if ($this->_isPriceViewModeNetto()) {
            $dPrice = $this->getWrappingPrice()->getNettoPrice();
        } else {
            $dPrice = $this->getWrappingPrice()->getBruttoPrice();
        }

        return $dPrice;
    }
173074
protected function getIdPriceProductStoreEntity(DataSetInterface $dataSet): string
    {
        $cacheIndex = $this->buildCacheIndex($dataSet);
        if (isset($this->idPriceProductStoreCache[$cacheIndex])) {
            return $this->idPriceProductStoreCache[$cacheIndex];
        }

        $priceProductStoreEntity = SpyPriceProductStoreQuery::create()
            ->filterByFkStore($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_STORE])
            ->filterByFkCurrency($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_CURRENCY])
            ->filterByFkPriceProduct($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRICE_PRODUCT])
            ->filterByNetPrice((int)$dataSet[PriceProductMerchantRelationshipDataSetInterface::PRICE_NET])
            ->filterByGrossPrice((int)$dataSet[PriceProductMerchantRelationshipDataSetInterface::PRICE_GROSS])
            ->findOneOrCreate();

        $priceProductStoreEntity->save();

        $this->idPriceProductStoreCache[$cacheIndex] = $priceProductStoreEntity->getIdPriceProductStore();

        return $this->idPriceProductStoreCache[$cacheIndex];
    }
852625
private function getLoadPriceDataSelect($indexTable, $websiteId, $productIds)
    {
        $select = $this->getConnection()->select()
            ->from(['p' => $indexTable])
            ->where('p.website_id = ?', $websiteId)
            ->where('p.entity_id IN(?)', $productIds);

        return $select;
    }
473025
public function getPriceForPayment()
    {
        $dPrice = $this->getDiscountedProductsBruttoPrice();
        //#1905 not discounted products should be included in payment amount calculation
        if ($oPriceList = $this->getNotDiscountProductsPrice()) {
            $dPrice += $oPriceList->getBruttoSum();
        }

        // adding delivery price to final price
        if ($oDeliveryPrice = $this->_aCosts['oxdelivery']) {
            $dPrice += $oDeliveryPrice->getBruttoPrice();
        }

        return $dPrice;
    }
526506
protected function _getPrice()
    {
        $sPriceSuffix = $this->_getUserPriceSufix();
        if ($sPriceSuffix === '') {
            $dPrice = $this->oxarticles__oxprice->value;
        } else {
            if (\OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('blOverrideZeroABCPrices')) {
                $dPrice = ($this->{'oxarticles__oxprice' . $sPriceSuffix}->value != 0) ? $this->{'oxarticles__oxprice' . $sPriceSuffix}->value : $this->oxarticles__oxprice->value;
            } else {
                $dPrice = $this->{'oxarticles__oxprice' . $sPriceSuffix}->value;
            }
        }

        return $dPrice;
    }
1281463
private String buildSelectSQL(boolean addOrderBy) {
        SQLParams sqlParams = SQLParams.builder()
                .modelClass(this.modelClass)
                .selectColumns(this.selectColumns)
                .tableName(this.tableName)
                .pkName(this.primaryKeyColumn)
                .conditionSQL(this.conditionSQL)
                .excludedColumns(this.excludedColumns)
                .isSQLLimit(isSQLLimit)
                .build();

        ifThen(addOrderBy, () -> sqlParams.setOrderBy(this.orderBySQL.toString()));

        return Anima.of().dialect().select(sqlParams);
    }
1363734
protected function ApplyPriceModifiers($dPrice)
    {
        if ($this->fieldValueMin > 0 && $dPrice < $this->fieldValueMin) {
            $dPrice = $this->fieldValueMin;
        }
        if ($this->fieldValueMax > 0 && $dPrice > $this->fieldValueMax) {
            $dPrice = $this->fieldValueMax;
        }
        if ($this->fieldValueAdditional > 0) {
            $dPrice = $dPrice + $this->fieldValueAdditional;
        }

        return $dPrice;
    }