protected function loadFromDatabase() { if (!isset($this->fields)) { $pricesList = \CPrice::getListEx(array(), array("=PRODUCT_ID" => $this->id, "+<=QUANTITY_FROM" => 1, "+>=QUANTITY_TO" => 1), false, false, array("PRICE", "CURRENCY", "CATALOG_GROUP_ID", "CATALOG_GROUP_CODE")); $this->fields = array(); while ($priceInfo = $pricesList->fetch()) { $price_id = $priceInfo["CATALOG_GROUP_ID"]; $price = \FormatCurrency($priceInfo["PRICE"], $priceInfo["CURRENCY"]); $this->addField($price_id, $price_id, $price); $this->addField($priceInfo["CATALOG_GROUP_CODE"], $price_id, $price); } } return is_array($this->fields); }
/** * Fills member elementPrices member with prices. * * @param integer[] $productList Identifiers of the elements. * * @return void */ protected function loadElementPrices(array $productList) { $priceList = \CPrice::getListEx(array(), array('PRODUCT_ID' => $productList), false, false, array('ID', 'PRODUCT_ID', 'CATALOG_GROUP_ID', 'PRICE', 'CURRENCY', 'QUANTITY_FROM', 'QUANTITY_TO')); while ($price = $priceList->fetch()) { if (!isset($this->elementPrices[$price["CATALOG_GROUP_ID"]][$price["CURRENCY"]])) { $this->elementPrices[$price["CATALOG_GROUP_ID"]][$price["CURRENCY"]] = array(); } $priceValue = doubleval($price["PRICE"]); $this->elementPrices[$price["CATALOG_GROUP_ID"]][$price["CURRENCY"]][$priceValue] = $priceValue; } foreach ($this->elementPrices as $catalogGroupId => $currencyPrices) { foreach ($currencyPrices as $currency => $prices) { if (count($prices) > 2) { $this->elementPrices[$catalogGroupId][$currency] = array(min($prices), max($prices)); } } } }
protected function getSkuPrices() { $result = array(); if ($this->offers) { $ids = array(); foreach ($this->offers as $id => $offers) { foreach ($offers as $offer) { $ids[] = $offer['ID']; } } if ($ids) { $priceIds = $this->getVisiblePrices(); foreach ($priceIds as $id) { $dbPrice = \CPrice::getListEx(array(), array('PRODUCT_ID' => $ids, 'CATALOG_GROUP_ID' => $id), false, false, array('PRODUCT_ID', 'PRICE', 'CURRENCY', 'QUANTITY_FROM', 'QUANTITY_TO')); while ($arPrice = $dbPrice->fetch()) { $arPrice['QUANTITY_FROM'] = (int) $arPrice['QUANTITY_FROM']; $arPrice['QUANTITY_TO'] = (int) $arPrice['QUANTITY_TO']; if (!isset($result[$id][$arPrice["PRODUCT_ID"]]) || $result[$id][$arPrice["PRODUCT_ID"]]['QUANTITY_FROM'] > $arPrice['QUANTITY_FROM']) { $result[$id][$arPrice["PRODUCT_ID"]] = array('PRICE' => $arPrice['PRICE'], 'CURRENCY' => $arPrice['CURRENCY'], 'QUANTITY_FROM' => $arPrice['QUANTITY_FROM'], 'QUANTITY_TO' => $arPrice['QUANTITY_TO']); } } unset($arPrice, $dbPrice); } } } return $result; }
/** * Fills member elementPrices member with prices. * * @param integer[] $productList Identifiers of the elements. * * @return void */ protected function loadElementPrices(array $productList) { $priceList = \CPrice::getListEx(array(), array('PRODUCT_ID' => $productList), false, false, array('ID', 'PRODUCT_ID', 'CATALOG_GROUP_ID', 'PRICE', 'CURRENCY', 'QUANTITY_FROM', 'QUANTITY_TO')); while ($price = $priceList->fetch()) { if (!$price["QUANTITY_FROM"] && !$price["QUANTITY_TO"]) { if (!isset($this->elementPrices[$price["CATALOG_GROUP_ID"]][$price["CURRENCY"]])) { $this->elementPrices[$price["CATALOG_GROUP_ID"]][$price["CURRENCY"]] = array(); } $this->elementPrices[$price["CATALOG_GROUP_ID"]][$price["CURRENCY"]][] = $price["PRICE"]; } } }