j7-dev / woomp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

同時使用折價券+88折扣時,開立發票出現錯誤

andykao1026 opened this issue · comments

綠界開發票也會有一樣的狀況

問題描述

3件商品總金額917
無法被整除,引發發票開立錯誤

image

image

解法

參考綠界文件

image
image

將有小數點限制的參數改用 number_format 包起來就好
image

同場加映: 發票明明錯誤,卻顯示開立成功

這個順便改了 之前小賴的作法
只要發票有成功送出 是不管綠界回啥,一律回成功@@

現在改成 會回綠界回的訊息 ex 格是錯誤

[更新] 11/14 經過線上測試後,還是有錯誤

單價計算錯誤,變成1 * 0.33 = 1元了 單價完全錯誤
image

原因是 number_format 會 return 一個 string 還會帶千分位
如果轉成 (float) 數字,會變成1
應該使用 round 就好

判斷是商品資訊那邊寫錯
image

$itemsTmp = $order->get_items();
$itemsTmp 會變成一個 WC_Order_Item_Product 物件組成的 array
然後遍歷出來

[14-Nov-2023 04:41:11 UTC] ⭐ 一些數據 Array
(
    [get_quantity] => 3
    [get_subtotal] => 1197
    [get_subtotal_tax] => 0
    [get_total] => 917
    [get_total_tax] => 0
)

原本寫法完全是在瞎寫
用陣列的拿法去拿物件的屬性,居然不會出錯也是奇蹟了

ref: https://woocommerce.github.io/code-reference/classes/WC-Order-Item-Product.html

image

錯誤已排除