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"
for k, v := range dataOrder.Items {
mb += fmt.Sprintf(
"%d. %s %v x %s\n",
"%d. %s",
k+1,
v.Name,
)
if v.Quantity != nil {
if v.Quantity.Value != 0 {
mb += fmt.Sprintf(
" %v",
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(
"\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"),
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(
"cost_currency",
map[string]interface{}{
"Amount": dataOrder.Delivery.Amount.Value,
"Currency": currency[strings.ToLower(dataOrder.Delivery.Amount.Currency)],
"Currency": val,
},
),
)
}
}
if dataOrder.Delivery.Address != "" {
mb += ";\n" + dataOrder.Delivery.Address
@ -725,17 +753,22 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
getLocalizedMessage("payment"),
)
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(
"%s; %s",
v.Name,
"; %s",
getLocalizedTemplateMessage(
"cost_currency",
map[string]interface{}{
"Amount": v.Amount.Value,
"Currency": currency[strings.ToLower(v.Amount.Currency)],
"Currency": val,
},
),
)
}
}
if v.Status != nil && v.Status.Name != "" {
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(
"\n%s: %s",
getLocalizedMessage("cost"),
getLocalizedMessage("order_total"),
getLocalizedTemplateMessage(
"cost_currency",
map[string]interface{}{
"Amount": dataOrder.Cost.Value,
"Currency": currency[strings.ToLower(dataOrder.Cost.Currency)],
"Currency": val,
},
),
)
}
}
return mb
}

View File

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

View File

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

View File

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