all the refactor
This commit is contained in:
@@ -43,21 +43,29 @@ func buildOrderLinesFromGrain(grain *checkout.CheckoutGrain) []OrderLine {
|
||||
if it == nil {
|
||||
continue
|
||||
}
|
||||
// Carry the per-item store as the inventory commit location; empty when
|
||||
// no store (commit then falls back to the order country / central stock).
|
||||
location := ""
|
||||
if it.StoreId != nil {
|
||||
location = *it.StoreId
|
||||
}
|
||||
lines = append(lines, OrderLine{
|
||||
Reference: it.Sku,
|
||||
Sku: it.Sku,
|
||||
Name: it.Meta.Name,
|
||||
Quantity: int32(it.Quantity),
|
||||
UnitPrice: it.Price.IncVat,
|
||||
// CartItem.Tax is percentage x 100 (e.g. 2500 = 25.00%). Convert to raw percent (25).
|
||||
TaxRate: int32(it.Tax / 100),
|
||||
UnitPrice: it.Price.IncVat.Int64(),
|
||||
// CartItem.Tax and OrderLine.TaxRate share the platform basis-point scale
|
||||
// (2500 = 25%), so the rate passes through unchanged.
|
||||
TaxRate: int32(it.Tax),
|
||||
Location: location,
|
||||
})
|
||||
}
|
||||
for _, d := range grain.Deliveries {
|
||||
if d == nil {
|
||||
continue
|
||||
}
|
||||
unitPrice := d.Price.IncVat
|
||||
unitPrice := d.Price.IncVat.Int64()
|
||||
if hasFreeShipping {
|
||||
unitPrice = 0
|
||||
}
|
||||
@@ -70,7 +78,7 @@ func buildOrderLinesFromGrain(grain *checkout.CheckoutGrain) []OrderLine {
|
||||
Name: "Delivery",
|
||||
Quantity: 1,
|
||||
UnitPrice: unitPrice,
|
||||
TaxRate: 25,
|
||||
TaxRate: 2500, // 25% in basis points
|
||||
})
|
||||
}
|
||||
|
||||
@@ -82,7 +90,7 @@ func buildOrderLinesFromGrain(grain *checkout.CheckoutGrain) []OrderLine {
|
||||
}
|
||||
discountVal := int64(0)
|
||||
if ap.Discount != nil {
|
||||
discountVal = ap.Discount.IncVat
|
||||
discountVal = ap.Discount.IncVat.Int64()
|
||||
}
|
||||
if discountVal <= 0 {
|
||||
continue
|
||||
@@ -93,7 +101,7 @@ func buildOrderLinesFromGrain(grain *checkout.CheckoutGrain) []OrderLine {
|
||||
Name: "Promotion: " + ap.Name,
|
||||
Quantity: 1,
|
||||
UnitPrice: -discountVal,
|
||||
TaxRate: 25, // default standard tax rate for promotion discount
|
||||
TaxRate: 2500, // default standard tax rate (25%) in basis points
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user