По условиям акции предоставить покупателю цену назначенную для другой группы пользователей

В общем, помогли мне и победил :slight_smile:

В файле /app/schemas/promotions/schema.php

Добавил ‘usergroup_price’

Было:
‘product_discount’ => array (
‘function’ => array(‘fn_promotion_apply_catalog_rule’, ‘#this’, ‘@product’, ‘@auth’),
‘discount_bonuses’ => array(‘to_percentage’, ‘by_percentage’, ‘to_fixed’, ‘by_fixed’),
‘zones’ => array(‘catalog’),
),

Стало:
‘product_discount’ => array (
‘function’ => array(‘fn_promotion_apply_catalog_rule’, ‘#this’, ‘@product’, ‘@auth’),
‘discount_bonuses’ => array(‘to_percentage’, ‘by_percentage’, ‘to_fixed’, ‘by_fixed’, ‘usergroup_price’),
‘zones’ => array(‘catalog’),
),

В файле:
/app/functions/fn.promotions.php

Примерно 1838 строчка, изменена функция function fn_promotions_calculate_discount на вот такую:

function fn_promotions_calculate_discount($type, $price, $value, $product_id, $current_price = 0)
{
$discount = 0;

if ($value === '') {
    return 0;
}

if ($type == 'to_percentage') {
    $discount = $price * (100 - $value) / 100;

} elseif ($type == 'by_percentage') {
    $discount = $price * $value / 100;

} elseif ($type == 'to_fixed') {
    $discount = (!empty($current_price) ? $current_price : $price) - $value;

} elseif ($type == 'by_fixed') {
    $discount = $value;
} elseif ($type == 'usergroup_price') {
    $discount = $price - db_get_field('SELECT price from ?:product_prices WHERE product_id=?i and usergroup_id=?i',$product_id, $value);
}

if ($discount < 0) {
    $discount = 0;
}

return $discount;

}

И в этом же файле примерно 414 строка добавлено:

В результате в акциях для каталога появился новый вариант, в качестве его значения вбивается id группы пользователей, цены которых хочу использовать

И всё, теперь на странице товара и в каталоге отображается нужная мне цена, от другой группы пользователей, а в качестве базовой, от которой рассчитывается скидка отображается цена группы пользователей под которым авторизованы :slight_smile:
image

6 лайков