1
0
mirror of synced 2024-11-22 12:26:02 +03:00

improve send order message and translate

This commit is contained in:
DmitryZagorulko 2018-09-21 19:27:15 +03:00
parent 5d441a86da
commit ad70716e4f
4 changed files with 84 additions and 49 deletions

View File

@ -683,34 +683,62 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
mb += "\n" mb += "\n"
for k, v := range dataOrder.Items { for k, v := range dataOrder.Items {
mb += fmt.Sprintf( mb += fmt.Sprintf(
"%d. %s %v x %s\n", "%d. %s",
k+1, k+1,
v.Name, v.Name,
)
if v.Quantity != nil {
if v.Quantity.Value != 0 {
mb += fmt.Sprintf(
" %v",
v.Quantity.Value, v.Quantity.Value,
getLocalizedTemplateMessage(
"cost_currency",
map[string]interface{}{
"Amount": v.Price.Value,
"Currency": currency[strings.ToLower(v.Price.Currency)],
},
),
) )
} }
} }
if dataOrder.Delivery != nil { if v.Price != nil {
if val, ok := currency[strings.ToLower(v.Price.Currency)]; ok {
mb += fmt.Sprintf( mb += fmt.Sprintf(
"\n%s:\n%s; %s", " x %s\n",
getLocalizedTemplateMessage(
"cost_currency",
map[string]interface{}{
"Amount": v.Price.Value,
"Currency": val,
},
),
)
}
} else {
mb += "\n"
}
}
}
if dataOrder.Delivery != nil {
if dataOrder.Delivery.Name != "" {
mb += fmt.Sprintf(
"\n%s:\n%s",
getLocalizedMessage("delivery"), getLocalizedMessage("delivery"),
dataOrder.Delivery.Name, dataOrder.Delivery.Name,
)
}
if dataOrder.Delivery.Amount != nil {
if val, ok := currency[strings.ToLower(dataOrder.Delivery.Amount.Currency)]; ok && dataOrder.Delivery.Amount.Value != 0 {
mb += fmt.Sprintf(
"; %s",
getLocalizedTemplateMessage( getLocalizedTemplateMessage(
"cost_currency", "cost_currency",
map[string]interface{}{ map[string]interface{}{
"Amount": dataOrder.Delivery.Amount.Value, "Amount": dataOrder.Delivery.Amount.Value,
"Currency": currency[strings.ToLower(dataOrder.Delivery.Amount.Currency)], "Currency": val,
}, },
), ),
) )
}
}
if dataOrder.Delivery.Address != "" { if dataOrder.Delivery.Address != "" {
mb += ";\n" + dataOrder.Delivery.Address mb += ";\n" + dataOrder.Delivery.Address
@ -725,17 +753,22 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
getLocalizedMessage("payment"), getLocalizedMessage("payment"),
) )
for _, v := range dataOrder.Payments { for _, v := range dataOrder.Payments {
mb += v.Name
if v.Amount != nil {
if val, ok := currency[strings.ToLower(v.Amount.Currency)]; ok && v.Amount.Value != 0 {
mb += fmt.Sprintf( mb += fmt.Sprintf(
"%s; %s", "; %s",
v.Name,
getLocalizedTemplateMessage( getLocalizedTemplateMessage(
"cost_currency", "cost_currency",
map[string]interface{}{ map[string]interface{}{
"Amount": v.Amount.Value, "Amount": v.Amount.Value,
"Currency": currency[strings.ToLower(v.Amount.Currency)], "Currency": val,
}, },
), ),
) )
}
}
if v.Status != nil && v.Status.Name != "" { if v.Status != nil && v.Status.Name != "" {
mb += fmt.Sprintf( mb += fmt.Sprintf(
@ -748,19 +781,21 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
} }
} }
if dataOrder.Cost != nil && dataOrder.Cost.Value != 0 { if dataOrder.Cost != nil {
if val, ok := currency[strings.ToLower(dataOrder.Cost.Currency)]; ok && dataOrder.Cost.Value != 0 {
mb += fmt.Sprintf( mb += fmt.Sprintf(
"\n%s: %s", "\n%s: %s",
getLocalizedMessage("cost"), getLocalizedMessage("order_total"),
getLocalizedTemplateMessage( getLocalizedTemplateMessage(
"cost_currency", "cost_currency",
map[string]interface{}{ map[string]interface{}{
"Amount": dataOrder.Cost.Value, "Amount": dataOrder.Cost.Value,
"Currency": currency[strings.ToLower(dataOrder.Cost.Currency)], "Currency": val,
}, },
), ),
) )
} }
}
return mb return mb
} }

View File

@ -47,5 +47,5 @@ item_cost: "Cost"
order: "Order" order: "Order"
delivery: "Delivery" delivery: "Delivery"
payment: "Payment" payment: "Payment"
cost: "Amount" order_total: "Order total"
cost_currency: "{{.Amount}} {{.Currency}}" cost_currency: "{{.Amount}} {{.Currency}}"

View File

@ -43,9 +43,9 @@ voice: "[mensaje de voz]"
photo: "[foto]" photo: "[foto]"
other: "[formato indefinido de mensaje]" other: "[formato indefinido de mensaje]"
item_cost: "Costo" item_cost: "Precio"
order: "Orden" order: "Pedido"
delivery: "Entrega" delivery: "Entrega"
payment: "Pago" payment: "Pago"
cost: "Monto" order_total: "Total pedido"
cost_currency: "{{.Amount}} {{.Currency}}" cost_currency: "{{.Amount}} {{.Currency}}"

View File

@ -47,5 +47,5 @@ item_cost: "Цена"
order: "Заказ" order: "Заказ"
delivery: "Доставка" delivery: "Доставка"
payment: "Оплата" payment: "Оплата"
cost: "Сумма" order_total: "Сумма"
cost_currency: "{{.Amount}} {{.Currency}}" cost_currency: "{{.Amount}} {{.Currency}}"