1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016-2022 |
6
|
|
|
* @package Client |
7
|
|
|
* @subpackage Html |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Client\Html\Account\Profile; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Default implementation of account profile HTML client. |
16
|
|
|
* |
17
|
|
|
* @package Client |
18
|
|
|
* @subpackage Html |
19
|
|
|
*/ |
20
|
|
|
class Standard |
21
|
|
|
extends \Aimeos\Client\Html\Common\Client\Factory\Base |
22
|
|
|
implements \Aimeos\Client\Html\Iface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Sets the necessary parameter values in the view. |
26
|
|
|
* |
27
|
|
|
* @param \Aimeos\MW\View\Iface $view The view object which generates the HTML output |
28
|
|
|
* @param array &$tags Result array for the list of tags that are associated to the output |
29
|
|
|
* @param string|null &$expire Result variable for the expiration date of the output (null for no expiry) |
30
|
|
|
* @return \Aimeos\MW\View\Iface Modified view object |
31
|
|
|
*/ |
32
|
|
|
public function data( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\MW\View\Iface |
33
|
|
|
{ |
34
|
|
|
$context = $this->context(); |
35
|
|
|
$config = $context->config(); |
36
|
|
|
|
37
|
|
|
/** client/html/common/address/salutations |
38
|
|
|
* List of salutions the customers can select from in the HTML frontend |
39
|
|
|
* |
40
|
|
|
* The following salutations are available: |
41
|
|
|
* |
42
|
|
|
* * empty string for "unknown" |
43
|
|
|
* * company |
44
|
|
|
* * mr |
45
|
|
|
* * ms |
46
|
|
|
* |
47
|
|
|
* You can modify the list of salutation codes and remove the ones |
48
|
|
|
* which shouldn't be used or add new ones. |
49
|
|
|
* |
50
|
|
|
* @param array List of available salutation codes |
51
|
|
|
* @since 2021.04 |
52
|
|
|
* @see client/html/account/profile/address/salutations |
53
|
|
|
*/ |
54
|
|
|
$salutations = $config->get( 'client/html/common/address/salutations', ['', 'company', 'mr', 'ms'] ); |
55
|
|
|
|
56
|
|
|
/** client/html/account/profile/domains |
57
|
|
|
* A list of domain names whose items should be available in the account profile view template |
58
|
|
|
* |
59
|
|
|
* The templates rendering customer details can contain additional |
60
|
|
|
* items. If you want to display additional content, you can configure |
61
|
|
|
* your own list of domains (attribute, media, price, product, text, |
62
|
|
|
* etc. are domains) whose items are fetched from the storage. |
63
|
|
|
* |
64
|
|
|
* @param array List of domain names |
65
|
|
|
* @since 2016.10 |
66
|
|
|
* @category Developer |
67
|
|
|
*/ |
68
|
|
|
$domains = $config->get( 'client/html/account/profile/domains', ['customer/address'] ); |
69
|
|
|
|
70
|
|
|
$item = \Aimeos\Controller\Frontend::create( $context, 'customer' )->uses( $domains )->get(); |
71
|
|
|
|
72
|
|
|
$localeManager = \Aimeos\MShop::create( $context, 'locale' ); |
73
|
|
|
$languages = $localeManager->search( $localeManager->filter( true ) ) |
74
|
|
|
->col( 'locale.languageid', 'locale.languageid' ); |
75
|
|
|
|
76
|
|
|
$deliveries = []; |
77
|
|
|
$addr = $item->getPaymentAddress(); |
78
|
|
|
|
79
|
|
|
if( !$addr->getLanguageId() ) { |
80
|
|
|
$addr->setLanguageId( $context->locale()->getLanguageId() ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$billing = $addr->toArray(); |
84
|
|
|
$billing['string'] = $this->call( 'getAddressString', $view, $addr ); |
85
|
|
|
|
86
|
|
|
foreach( $item->getAddressItems() as $pos => $address ) |
87
|
|
|
{ |
88
|
|
|
$delivery = $address->toArray(); |
89
|
|
|
$delivery['string'] = $this->call( 'getAddressString', $view, $address ); |
90
|
|
|
$deliveries[$pos] = $delivery; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$view->profileItem = $item; |
94
|
|
|
$view->addressBilling = $billing; |
95
|
|
|
$view->addressDelivery = $deliveries; |
96
|
|
|
$view->addressCountries = $view->config( 'client/html/checkout/standard/address/countries', [] ); |
97
|
|
|
$view->addressStates = $view->config( 'client/html/checkout/standard/address/states', [] ); |
98
|
|
|
$view->addressSalutations = $salutations; |
99
|
|
|
$view->addressLanguages = $languages; |
100
|
|
|
|
101
|
|
|
return parent::data( $view, $tags, $expire ); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Processes the input, e.g. store given values. |
107
|
|
|
* |
108
|
|
|
* A view must be available and this method doesn't generate any output |
109
|
|
|
* besides setting view variables if necessary. |
110
|
|
|
*/ |
111
|
|
|
public function init() |
112
|
|
|
{ |
113
|
|
|
$view = $this->view(); |
114
|
|
|
|
115
|
|
|
if( !$view->param( 'address/save' ) && !$view->param( 'address/delete' ) ) { |
116
|
|
|
return; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$cntl = \Aimeos\Controller\Frontend::create( $this->context(), 'customer' ); |
120
|
|
|
$addrItems = $cntl->uses( ['customer/address'] )->get()->getAddressItems(); |
121
|
|
|
$cntl->add( $view->param( 'address/payment', [] ) ); |
122
|
|
|
$map = []; |
123
|
|
|
|
124
|
|
|
foreach( $view->param( 'address/delivery/customer.address.id', [] ) as $pos => $id ) |
125
|
|
|
{ |
126
|
|
|
foreach( $view->param( 'address/delivery', [] ) as $key => $list ) |
127
|
|
|
{ |
128
|
|
|
if( array_key_exists( $pos, $list ) ) { |
129
|
|
|
$map[$pos][$key] = $list[$pos]; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
if( $pos = $view->param( 'address/delete' ) ) { |
135
|
|
|
unset( $map[$pos] ); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
foreach( $map as $pos => $data ) |
139
|
|
|
{ |
140
|
|
|
$addrItem = $addrItems->get( $pos ) ?: $cntl->createAddressItem(); |
141
|
|
|
$cntl->addAddressItem( $addrItem->fromArray( $data ), $pos ); |
142
|
|
|
$addrItems->remove( $pos ); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
foreach( $addrItems as $addrItem ) { |
146
|
|
|
$cntl->deleteAddressItem( $addrItem ); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
$cntl->store(); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Returns the address as string |
155
|
|
|
* |
156
|
|
|
* @param \Aimeos\MW\View\Iface $view The view object which generates the HTML output |
157
|
|
|
* @param \Aimeos\MShop\Common\Item\Address\Iface $addr Order address item |
158
|
|
|
* @return string Address as string |
159
|
|
|
*/ |
160
|
|
|
protected function getAddressString( \Aimeos\MW\View\Iface $view, \Aimeos\MShop\Common\Item\Address\Iface $addr ) |
161
|
|
|
{ |
162
|
|
|
return preg_replace( "/\n+/m", "\n", trim( sprintf( |
163
|
|
|
/// Address format with company (%1$s), salutation (%2$s), title (%3$s), first name (%4$s), last name (%5$s), |
164
|
|
|
/// address part one (%6$s, e.g street), address part two (%7$s, e.g house number), address part three (%8$s, e.g additional information), |
165
|
|
|
/// postal/zip code (%9$s), city (%10$s), state (%11$s), country (%12$s), language (%13$s), |
166
|
|
|
/// e-mail (%14$s), phone (%15$s), facsimile/telefax (%16$s), web site (%17$s), vatid (%18$s) |
167
|
|
|
$view->translate( 'client', '%1$s |
168
|
|
|
%2$s %3$s %4$s %5$s |
169
|
|
|
%6$s %7$s |
170
|
|
|
%8$s |
171
|
|
|
%9$s %10$s |
172
|
|
|
%11$s |
173
|
|
|
%12$s |
174
|
|
|
%13$s |
175
|
|
|
%14$s |
176
|
|
|
%15$s |
177
|
|
|
%16$s |
178
|
|
|
%17$s |
179
|
|
|
%18$s |
180
|
|
|
' |
181
|
|
|
), |
182
|
|
|
$addr->getCompany(), |
183
|
|
|
$view->translate( 'mshop/code', (string) $addr->getSalutation() ), |
184
|
|
|
$addr->getTitle(), |
185
|
|
|
$addr->getFirstName(), |
186
|
|
|
$addr->getLastName(), |
187
|
|
|
$addr->getAddress1(), |
188
|
|
|
$addr->getAddress2(), |
189
|
|
|
$addr->getAddress3(), |
190
|
|
|
$addr->getPostal(), |
191
|
|
|
$addr->getCity(), |
192
|
|
|
$addr->getState(), |
193
|
|
|
$view->translate( 'country', (string) $addr->getCountryId() ), |
194
|
|
|
$view->translate( 'language', (string) $addr->getLanguageId() ), |
195
|
|
|
$addr->getEmail(), |
196
|
|
|
$addr->getTelephone(), |
197
|
|
|
$addr->getTelefax(), |
198
|
|
|
$addr->getWebsite(), |
199
|
|
|
$addr->getVatID() |
200
|
|
|
) ) ); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
/** client/html/account/profile/template-body |
205
|
|
|
* Relative path to the HTML body template of the account profile client. |
206
|
|
|
* |
207
|
|
|
* The template file contains the HTML code and processing instructions |
208
|
|
|
* to generate the result shown in the body of the frontend. The |
209
|
|
|
* configuration string is the path to the template file relative |
210
|
|
|
* to the templates directory (usually in client/html/templates). |
211
|
|
|
* |
212
|
|
|
* You can overwrite the template file configuration in extensions and |
213
|
|
|
* provide alternative templates. These alternative templates should be |
214
|
|
|
* named like the default one but suffixed by |
215
|
|
|
* an unique name. You may use the name of your project for this. If |
216
|
|
|
* you've implemented an alternative client class as well, it |
217
|
|
|
* should be suffixed by the name of the new class. |
218
|
|
|
* |
219
|
|
|
* @param string Relative path to the template creating code for the HTML page body |
220
|
|
|
* @since 2016.10 |
221
|
|
|
* @category Developer |
222
|
|
|
* @see client/html/account/profile/template-header |
223
|
|
|
*/ |
224
|
|
|
|
225
|
|
|
/** client/html/account/profile/template-header |
226
|
|
|
* Relative path to the HTML header template of the account profile client. |
227
|
|
|
* |
228
|
|
|
* The template file contains the HTML code and processing instructions |
229
|
|
|
* to generate the HTML code that is inserted into the HTML page header |
230
|
|
|
* of the rendered page in the frontend. The configuration string is the |
231
|
|
|
* path to the template file relative to the templates directory (usually |
232
|
|
|
* in client/html/templates). |
233
|
|
|
* |
234
|
|
|
* You can overwrite the template file configuration in extensions and |
235
|
|
|
* provide alternative templates. These alternative templates should be |
236
|
|
|
* named like the default one but suffixed by |
237
|
|
|
* an unique name. You may use the name of your project for this. If |
238
|
|
|
* you've implemented an alternative client class as well, it |
239
|
|
|
* should be suffixed by the name of the new class. |
240
|
|
|
* |
241
|
|
|
* @param string Relative path to the template creating code for the HTML page head |
242
|
|
|
* @since 2016.10 |
243
|
|
|
* @category Developer |
244
|
|
|
* @see client/html/account/profile/template-body |
245
|
|
|
*/ |
246
|
|
|
} |
247
|
|
|
|