Доброго дня, помогите кто может (с PHP не знаком, но нужно решить проблему). Есть функция из модуля оплаты, необходимо чтобы в запрос на сервер летела сумма округленная до 2-х знаков после запятой. Погуглив нашел нужный инструмент, и объявил переменную и приравнял к исходному значению округленному формулой $totalR = round($total, 2); и в 'sum' указал $totalR, ошибка на сайте ParseError: syntax error, unexpected '$data' (T_VARIABLE) Я в целом неправильно делаю что то, или с синтаксисом вопросы? было: PHP: public static function create(WC_Order $order): WebPaymentRequest { $total = (float) $order->get_total('edit'); $data = [ 'shift' => wp_date('dmY'), 'sum' => $total, 'order_number' => $order->get_id(), 'details' => [ 'items' => [], 'amountTotal' => $total, ], ]; стало: PHP: public static function create(WC_Order $order): WebPaymentRequest { $total = (float) $order->get_total('edit'); [B]$totalR = round($total, 2);[/B] $data = [ 'shift' => wp_date('dmY'), 'sum' => [B]$totalR,[/B] 'order_number' => $order->get_id(), 'details' => [ 'items' => [], 'amountTotal' => $total, ], ];
ббкоды [ B ] [ /B ] ты только на форуме поставил или они реально присутствуют где-то в коде? не должно быть такого!
где было выделено жирным? проверь свой код, если там есть этот мусор - удали его. без этих лишних штук вроде всё норм. не должно быть ошибки. unexpected трам-пара-рам обычно случается когда забыли точку с запятой в предыдущей строке,или скобку не закрыли, что-то в этом роде.
Вот вся страница с кодом, но как я понимаю дальнейший код не влияет на то что я правил, просто иногда летели суммы с многими знаками после запятой в запросе, я хотел в модуль вот воткнуть round, внизу выделил красным то что я добавил и заменил <?phpdeclare(strict_types=1); namespace Tolkam\Woocommerce\Gateway\Oplati\Client; use Swagger\Client\Model\WebPaymentRequest; use WC_Order; use WC_Order_Item_Fee; use WC_Order_Item_Product; use WC_Order_Item_Shipping; class WebPaymentRequestFactory { /** * @param WC_Order $order * * @return WebPaymentRequest */ public static function create(WC_Order $order): WebPaymentRequest { $total = (float) $order->get_total('edit'); $totalR = round($total, 2) $data = [ 'shift' => wp_date('dmY'), 'sum' => $totalR, 'order_number' => $order->get_id(), 'details' => [ 'items' => [], 'amountTotal' => $totalR, ], ]; foreach ($order->get_items(['line_item', 'fee', 'shipping']) as $item) { // regular product, not shipping or fee if ($item instanceof WC_Order_Item_Product) { $product = $item->get_product(); $data['details']['items'][] = [ 'type' => $product->is_virtual() ? 2 : 1, 'name' => $item->get_name(), 'quantity' => $item->get_quantity(), 'price' => (float) $product->get_price('edit'), 'cost' => (float) $item->get_total('edit'), ]; } if ( $item instanceof WC_Order_Item_Shipping || $item instanceof WC_Order_Item_Fee ) { $data['details']['items'][] = [ 'type' => 2, 'name' => $item->get_name(), 'quantity' => $item->get_quantity(), 'cost' => (float) $item->get_total('edit'), ]; } } foreach ($order->get_taxes() as $tax) { $data['details']['taxes'][] = [ 'rate' => (float) $tax->get_rate_percent('edit'), 'sum' => (float) $tax->get_tax_total('edit') + (float) $tax->get_shipping_tax_total('edit'), ]; } return new WebPaymentRequest($data); } }
@Метро2033, именно тот случай: --- Добавлено --- Ещё в первой строке пробела, или перехода на новую строку не хватает... Впрочем, это может быть только тут "криво" скопировано? PHP: <?phpdeclare(strict_types=1);