36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Jinove\Vinoteca\Catalog;
|
|
|
|
use Bitrix\Main\Engine\CurrentUser;
|
|
use Bitrix\Main\Loader;
|
|
|
|
final class Prices
|
|
{
|
|
public static function optimal(array $productIds, string $siteId = SITE_ID): array
|
|
{
|
|
$productIds = array_values(array_unique(array_filter(array_map("intval", $productIds))));
|
|
if (!$productIds || !Loader::includeModule("catalog") || !Loader::includeModule("currency")) {
|
|
return [];
|
|
}
|
|
$groups = CurrentUser::get()->getUserGroups();
|
|
$prices = [];
|
|
foreach ($productIds as $productId) {
|
|
$optimal = \CCatalogProduct::GetOptimalPrice($productId, 1, $groups, "N", [], $siteId);
|
|
$price = $optimal["RESULT_PRICE"] ?? null;
|
|
if (!$price || (float)$price["DISCOUNT_PRICE"] <= 0) {
|
|
continue;
|
|
}
|
|
$prices[$productId] = [
|
|
"price" => (float)$price["DISCOUNT_PRICE"],
|
|
"base" => max((float)$price["DISCOUNT_PRICE"], (float)$price["BASE_PRICE"]),
|
|
"currency" => (string)$price["CURRENCY"],
|
|
];
|
|
}
|
|
|
|
return $prices;
|
|
}
|
|
}
|