5
5
use App \DTO \Account \ChangePasswordDTO ;
6
6
use App \Http \HtmlResponse ;
7
7
use App \Model \Authentication \Account ;
8
+ use App \Service \Authentication \AccountAddressService ;
8
9
use App \Service \Authentication \AccountService ;
9
10
use App \Validation \Authentication \ChangePasswordValidation ;
10
11
use League \Plates \Engine ;
17
18
public function __construct (
18
19
private Engine $ template ,
19
20
private AccountService $ accountService ,
20
- private ChangePasswordValidation $ changePasswordValidation
21
+ private ChangePasswordValidation $ changePasswordValidation ,
22
+ private AccountAddressService $ accountAddressService
21
23
)
22
24
{
23
25
}
@@ -36,10 +38,13 @@ public function load(ServerRequestInterface $request): ResponseInterface
36
38
}
37
39
}
38
40
41
+ $ accountAddresses = $ this ->accountAddressService ->findAllAddressesByAccountId ($ account ->getId ());
42
+
39
43
return new HtmlResponse ($ this ->template ->render (
40
44
'account/account ' ,
41
45
[
42
- 'accountData ' => $ accountData
46
+ 'accountData ' => $ accountData ,
47
+ 'addressList ' => $ accountAddresses
43
48
]
44
49
));
45
50
}
@@ -81,6 +86,30 @@ public function update(Account $account): ?array
81
86
$ updateAccount ->setSurname ($ _POST ['accountUserLastname ' ]);
82
87
$ updateAccount ->setEmail ($ _POST ['accountUserEmail ' ]);
83
88
89
+ $ updateAccount ->setDefaultShippingAddress (null );
90
+ if (!empty ($ _POST ['accountUserDefaultShippingAddress ' ]))
91
+ {
92
+ if ($ this ->accountAddressService ->findAddressByIdAndAccount (
93
+ (int )$ _POST ['accountUserDefaultShippingAddress ' ],
94
+ $ updateAccount ->getId ()
95
+ ) !== NULL )
96
+ {
97
+ $ updateAccount ->setDefaultShippingAddress ((int )$ _POST ['accountUserDefaultShippingAddress ' ]);
98
+ }
99
+ }
100
+
101
+ $ updateAccount ->setDefaultInvoiceAddress (null );
102
+ if (!empty ($ _POST ['accountUserDefaultInvoiceAddress ' ]))
103
+ {
104
+ if ($ this ->accountAddressService ->findAddressByIdAndAccount (
105
+ (int )$ _POST ['accountUserDefaultInvoiceAddress ' ],
106
+ $ updateAccount ->getId ()
107
+ ) !== NULL )
108
+ {
109
+ $ updateAccount ->setDefaultInvoiceAddress ((int )$ _POST ['accountUserDefaultInvoiceAddress ' ]);
110
+ }
111
+ }
112
+
84
113
if ($ this ->accountService ->updateAccount ($ updateAccount )) {
85
114
return $ this ->accountService ->findAccountById ($ account ->getId ());
86
115
}
0 commit comments