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,
v.Quantity.Value,
getLocalizedTemplateMessage(
"cost_currency",
map[string]interface{}{
"Amount": v.Price.Value,
"Currency": currency[strings.ToLower(v.Price.Currency)],
},
),
) )
if v.Quantity != nil {
if v.Quantity.Value != 0 {
mb += fmt.Sprintf(
" %v",
v.Quantity.Value,
)
}
}
if v.Price != nil {
if val, ok := currency[strings.ToLower(v.Price.Currency)]; ok {
mb += fmt.Sprintf(
" 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 != nil {
mb += fmt.Sprintf( if dataOrder.Delivery.Name != "" {
"\n%s:\n%s; %s", mb += fmt.Sprintf(
getLocalizedMessage("delivery"), "\n%s:\n%s",
dataOrder.Delivery.Name, getLocalizedMessage("delivery"),
getLocalizedTemplateMessage( dataOrder.Delivery.Name,
"cost_currency", )
map[string]interface{}{ }
"Amount": dataOrder.Delivery.Amount.Value,
"Currency": currency[strings.ToLower(dataOrder.Delivery.Amount.Currency)], 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(
"cost_currency",
map[string]interface{}{
"Amount": dataOrder.Delivery.Amount.Value,
"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 += fmt.Sprintf( mb += v.Name
"%s; %s",
v.Name, if v.Amount != nil {
getLocalizedTemplateMessage( if val, ok := currency[strings.ToLower(v.Amount.Currency)]; ok && v.Amount.Value != 0 {
"cost_currency", mb += fmt.Sprintf(
map[string]interface{}{ "; %s",
"Amount": v.Amount.Value, getLocalizedTemplateMessage(
"Currency": currency[strings.ToLower(v.Amount.Currency)], "cost_currency",
}, map[string]interface{}{
), "Amount": v.Amount.Value,
) "Currency": val,
},
),
)
}
}
if v.Status != nil && v.Status.Name != "" { if v.Status != nil && v.Status.Name != "" {
mb += fmt.Sprintf( mb += fmt.Sprintf(
@ -748,18 +781,20 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
} }
} }
if dataOrder.Cost != nil && dataOrder.Cost.Value != 0 { if dataOrder.Cost != nil {
mb += fmt.Sprintf( if val, ok := currency[strings.ToLower(dataOrder.Cost.Currency)]; ok && dataOrder.Cost.Value != 0 {
"\n%s: %s", mb += fmt.Sprintf(
getLocalizedMessage("cost"), "\n%s: %s",
getLocalizedTemplateMessage( getLocalizedMessage("order_total"),
"cost_currency", getLocalizedTemplateMessage(
map[string]interface{}{ "cost_currency",
"Amount": dataOrder.Cost.Value, map[string]interface{}{
"Currency": currency[strings.ToLower(dataOrder.Cost.Currency)], "Amount": dataOrder.Cost.Value,
}, "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}}"