@@ -20,10 +20,10 @@ public function execute(string $chatId): void
20
20
if (empty ($ lastPurchase ['purchase ' ])) {
21
21
ResponseChat::interactWithUser ($ chatId , '😞 Poxa, não encontrei nenhuma compra 😞 ' );
22
22
}
23
- ResponseChat:: interactWithUser ( $ chatId , $ this ->formatToUser ($ lastPurchase) );
23
+ $ this ->showToUser ($ lastPurchase, $ chatId );
24
24
}
25
25
26
- protected function formatToUser (array $ lastPurchase ): string
26
+ protected function showToUser (array $ lastPurchase, string $ chatId ): void
27
27
{
28
28
$ message = "📄 Resumo da compra: \n\n" ;
29
29
$ message .= "📅 Data da compra: " . new DateTime ($ lastPurchase ['purchase ' ]->purchase_date )->format ('d/m/Y ' ) . "\n" ;
@@ -32,18 +32,29 @@ protected function formatToUser(array $lastPurchase): string
32
32
$ message .= "📊 Valor do desconto: R$ " . number_format ($ lastPurchase ['purchase ' ]->discount_value , 2 , ', ' , '. ' ) . "\n" ;
33
33
$ message .= "💰 Valor total: R$ " . number_format ($ lastPurchase ['purchase ' ]->total_value , 2 , ', ' , '. ' ) . "\n" ;
34
34
$ message .= "━━━━━━━━━━━━━━━━━ \n\n" ;
35
- $ message .= "📝 Produtos da Compras: \n\n " ;
35
+ $ message .= "📝 Produtos da Compras: \n" ;
36
36
37
- return $ message ;
38
- foreach ($ lastPurchase ['products ' ] as $ produto ) {
39
- $ name = substr ($ produto ->name , 0 , 30 );
37
+ ResponseChat::interactWithUser ($ chatId , $ message );
38
+
39
+ $ products = array_chunk ($ lastPurchase ['products ' ], 30 );
40
+
41
+ foreach ($ products as $ product ) {
42
+ ResponseChat::interactWithUser ($ chatId , $ this ->formatProducts ($ product ));
43
+ }
44
+ }
45
+
46
+ protected function formatProducts (array $ products ): string
47
+ {
48
+ $ message = '' ;
49
+ foreach ($ products as $ product ) {
50
+ $ name = substr ($ product ->name , 0 , 30 );
40
51
if (strlen ($ name ) === 30 ) {
41
52
$ name .= "... " ;
42
53
}
43
54
$ name = str_replace (' ' , "\u{00A0}" , $ name );
44
- $ value = number_format ($ produto ->total_value , 2 , ', ' , '. ' );
55
+ $ value = number_format ($ product ->total_value , 2 , ', ' , '. ' );
45
56
46
- $ message .= "🔹 $ name \n $ produto ->quantity $ produto ->unit - R$ $ value " ;
57
+ $ message .= "🔹 $ name \n $ product ->quantity $ product ->unit - R$ $ value " ;
47
58
$ message .= " ━━━━━━━━━━━━━━━━━ \n" ;
48
59
}
49
60
$ message .= "😅 Ufa, a lista acabou! \n" ;
0 commit comments