Skip to content

Instantly share code, notes, and snippets.

@anoriar
Created September 5, 2018 21:04
Show Gist options
  • Save anoriar/86fc4af5623b7c14c44e3d81ad4af5c8 to your computer and use it in GitHub Desktop.
Save anoriar/86fc4af5623b7c14c44e3d81ad4af5c8 to your computer and use it in GitHub Desktop.
$productsInst = \Aero\Tools\Iblock\Catalog\Products::getInstanceByCode();
$products = $productsInst->getElements([
"select" => ["ID", "IBLOCK_ID", "CODE"],
"filter" => ["ACTIVE" => "Y"],
"nav" => ["nTopCount" => 200]
]
);
$salesInst = \Aero\Tools\Hlblock\Prototype::getInstance("FilterSale");
$filterSalesKeys = array_keys($salesInst->getElements([
"select" => ["ID", "UF_XML_ID"],
"indexArray" => "UF_XML_ID"
]));
$arProductMainDiscounts = [];
foreach ($products as $product) {
$arDiscounts = CCatalogDiscount::GetDiscountByProduct(
$product["ID"],
$USER->GetUserGroupArray(),
"N",
[],
"s1"
);
if (!empty($arDiscounts)) {
$filterDiscounts = [];
foreach ($arDiscounts as $discount) {
if (in_array($discount["ID"], $filterSalesKeys)) {
$filterDiscounts[] = $discount;
}
}
if (!empty($filterDiscounts)) {
$arProductMainDiscounts[$product["ID"]] = getMaxPriorityDiscount($filterDiscounts);
}
}
}
function getMaxPriorityDiscount($discounts)
{
$maxPriorityDiscount = reset($discounts);
$maxPriority = intval($maxPriorityDiscount["PRIORITY"]);
foreach ($discounts as $discount) {
$priority = intval($discount["PRIORITY"]);
if ($priority >= $maxPriority) {
$maxPriorityDiscount = $discount;
$maxPriority = $priority;
}
}
return $maxPriorityDiscount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment