Skip to content

msOrderTotal: добавить параметр formatPrices для форматирования цен #92

@biz87

Description

@biz87

Проблема

Сниппет msOrderTotal передаёт в чанк сырые числовые значения без форматирования. Например, total_cost = 446692 вместо 446 692.

При этом в msProducts есть параметр formatPrices, который вызывает $ms3->format->price() и корректно форматирует цены с разделителями тысяч, валютой и т.д. — согласно системным настройкам ms3_price_format.

Текущее поведение

// ms3_order_total.php — строки 43-45
if ($response['success']) {
    $total = array_merge($total, $response['data']);
}
// Значения передаются в чанк как есть (raw numbers)

В чанке {$total_cost} выводит 446692 — без разделителей тысяч.

Ожидаемое поведение

Добавить параметр formatPrices (по аналогии с msProducts), который форматирует денежные поля через $ms3->format->price():

if (!empty($scriptProperties['formatPrices'])) {
    $withCurrency = !empty($scriptProperties['withCurrency']);
    $total['cost'] = $ms3->format->price($total['cost'], $withCurrency);
    $total['cart_cost'] = $ms3->format->price($total['cart_cost'], $withCurrency);
    $total['delivery_cost'] = $ms3->format->price($total['delivery_cost'], $withCurrency);
    $total['payment_cost'] = $ms3->format->price($total['payment_cost'], $withCurrency);
    $total['total_cost'] = $ms3->format->price($total['total_cost'], $withCurrency);
    $total['total_discount'] = $ms3->format->price($total['total_discount'], $withCurrency);
    $total['total_weight'] = $ms3->format->weight($total['total_weight']);
}

Текущий workaround

Форматирование через Fenom-фильтр number_format в кастомном чанке:

{$total_cost | number_format : 0 : '.' : ' '} {'ms3_frontend_currency' | lexicon}

Но это не использует системные настройки ms3_price_format и ms3_currency_position, поэтому менее гибко.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions