|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2020-2022 |
|
6
|
|
|
* @package Client |
|
7
|
|
|
* @subpackage Html |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Client\Html\Supplier\Detail; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Default implementation of supplier detail section HTML clients. |
|
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\Common\Client\Factory\Iface |
|
23
|
|
|
{ |
|
24
|
|
|
private $tags = []; |
|
25
|
|
|
private $expire; |
|
26
|
|
|
private $view; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Returns the HTML code for insertion into the body. |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
|
33
|
|
|
* @return string HTML code |
|
34
|
|
|
*/ |
|
35
|
|
|
public function body( string $uid = '' ) : string |
|
36
|
|
|
{ |
|
37
|
|
|
$prefixes = ['f_supid']; |
|
38
|
|
|
|
|
39
|
|
|
/** client/html/supplier/detail/cache |
|
40
|
|
|
* Enables or disables caching only for the supplier detail component |
|
41
|
|
|
* |
|
42
|
|
|
* Disable caching for components can be useful if you would have too much |
|
43
|
|
|
* entries to cache or if the component contains non-cacheable parts that |
|
44
|
|
|
* can't be replaced using the modify() method. |
|
45
|
|
|
* |
|
46
|
|
|
* @param boolean True to enable caching, false to disable |
|
47
|
|
|
* @see client/html/supplier/detail/cache |
|
48
|
|
|
* @see client/html/supplier/filter/cache |
|
49
|
|
|
* @see client/html/supplier/lists/cache |
|
50
|
|
|
*/ |
|
51
|
|
|
|
|
52
|
|
|
/** client/html/supplier/detail |
|
53
|
|
|
* All parameters defined for the supplier detail component and its subparts |
|
54
|
|
|
* |
|
55
|
|
|
* This returns all settings related to the detail component. |
|
56
|
|
|
* Please refer to the single settings for details. |
|
57
|
|
|
* |
|
58
|
|
|
* @param array Associative list of name/value settings |
|
59
|
|
|
* @see client/html/supplier#detail |
|
60
|
|
|
*/ |
|
61
|
|
|
$confkey = 'client/html/supplier/detail'; |
|
62
|
|
|
|
|
63
|
|
|
if( $html = $this->cached( 'body', $uid, $prefixes, $confkey ) ) { |
|
64
|
|
|
return $this->modify( $html, $uid ); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** client/html/supplier/detail/template-body |
|
68
|
|
|
* Relative path to the HTML body template of the supplier detail client. |
|
69
|
|
|
* |
|
70
|
|
|
* The template file contains the HTML code and processing instructions |
|
71
|
|
|
* to generate the result shown in the body of the frontend. The |
|
72
|
|
|
* configuration string is the path to the template file relative |
|
73
|
|
|
* to the templates directory (usually in client/html/templates). |
|
74
|
|
|
* |
|
75
|
|
|
* You can overwrite the template file configuration in extensions and |
|
76
|
|
|
* provide alternative templates. These alternative templates should be |
|
77
|
|
|
* named like the default one but suffixed by |
|
78
|
|
|
* an unique name. You may use the name of your project for this. If |
|
79
|
|
|
* you've implemented an alternative client class as well, it |
|
80
|
|
|
* should be suffixed by the name of the new class. |
|
81
|
|
|
* |
|
82
|
|
|
* @param string Relative path to the template creating code for the HTML page body |
|
83
|
|
|
* @since 2020.10 |
|
84
|
|
|
* @see client/html/supplier/detail/template-header |
|
85
|
|
|
*/ |
|
86
|
|
|
$template = $this->context()->config()->get( 'client/html/supplier/detail/template-body', 'supplier/detail/body' ); |
|
87
|
|
|
|
|
88
|
|
|
$view = $this->view = $this->view ?? $this->object()->data( $this->view(), $this->tags, $this->expire ); |
|
89
|
|
|
$html = $this->modify( $view->render( $template ), $uid ); |
|
90
|
|
|
|
|
91
|
|
|
return $this->cache( 'body', $uid, $prefixes, $confkey, $html, $this->tags, $this->expire ); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Returns the HTML string for insertion into the header. |
|
97
|
|
|
* |
|
98
|
|
|
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
|
99
|
|
|
* @return string|null String including HTML tags for the header on error |
|
100
|
|
|
*/ |
|
101
|
|
|
public function header( string $uid = '' ) : ?string |
|
102
|
|
|
{ |
|
103
|
|
|
$prefixes = ['f_supid']; |
|
104
|
|
|
$confkey = 'client/html/supplier/detail'; |
|
105
|
|
|
|
|
106
|
|
|
if( $html = $this->cached( 'header', $uid, $prefixes, $confkey ) ) { |
|
107
|
|
|
return $this->modify( $html, $uid ); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** client/html/supplier/detail/template-header |
|
111
|
|
|
* Relative path to the HTML header template of the supplier detail client. |
|
112
|
|
|
* |
|
113
|
|
|
* The template file contains the HTML code and processing instructions |
|
114
|
|
|
* to generate the HTML code that is inserted into the HTML page header |
|
115
|
|
|
* of the rendered page in the frontend. The configuration string is the |
|
116
|
|
|
* path to the template file relative to the templates directory (usually |
|
117
|
|
|
* in client/html/templates). |
|
118
|
|
|
* |
|
119
|
|
|
* You can overwrite the template file configuration in extensions and |
|
120
|
|
|
* provide alternative templates. These alternative templates should be |
|
121
|
|
|
* named like the default one but suffixed by |
|
122
|
|
|
* an unique name. You may use the name of your project for this. If |
|
123
|
|
|
* you've implemented an alternative client class as well, it |
|
124
|
|
|
* should be suffixed by the name of the new class. |
|
125
|
|
|
* |
|
126
|
|
|
* @param string Relative path to the template creating code for the HTML page head |
|
127
|
|
|
* @since 2020.10 |
|
128
|
|
|
* @see client/html/supplier/detail/template-body |
|
129
|
|
|
*/ |
|
130
|
|
|
$template = $this->context()->config()->get( 'client/html/supplier/detail/template-header', 'supplier/detail/header' ); |
|
131
|
|
|
|
|
132
|
|
|
$view = $this->view = $this->view ?? $this->object()->data( $this->view(), $this->tags, $this->expire ); |
|
133
|
|
|
$html = $view->render( $template ); |
|
134
|
|
|
|
|
135
|
|
|
return $this->cache( 'header', $uid, $prefixes, $confkey, $html, $this->tags, $this->expire ); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Sets the necessary parameter values in the view. |
|
141
|
|
|
* |
|
142
|
|
|
* @param \Aimeos\MW\View\Iface $view The view object which generates the HTML output |
|
143
|
|
|
* @param array &$tags Result array for the list of tags that are associated to the output |
|
144
|
|
|
* @param string|null &$expire Result variable for the expiration date of the output (null for no expiry) |
|
145
|
|
|
* @return \Aimeos\MW\View\Iface Modified view object |
|
146
|
|
|
*/ |
|
147
|
|
|
public function data( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\MW\View\Iface |
|
148
|
|
|
{ |
|
149
|
|
|
$context = $this->context(); |
|
150
|
|
|
$config = $context->config(); |
|
151
|
|
|
|
|
152
|
|
|
/** client/html/supplier/detail/supid-default |
|
153
|
|
|
* The default supplier ID used if none is given as parameter |
|
154
|
|
|
* |
|
155
|
|
|
* You can configure the default supplier ID if no ID is passed in the |
|
156
|
|
|
* URL using this configuration. |
|
157
|
|
|
* |
|
158
|
|
|
* @param string Supplier ID |
|
159
|
|
|
* @since 2021.01 |
|
160
|
|
|
* @see client/html/catalog/lists/catid-default |
|
161
|
|
|
*/ |
|
162
|
|
|
if( $supid = $view->param( 'f_supid', $config->get( 'client/html/supplier/detail/supid-default' ) ) ) |
|
163
|
|
|
{ |
|
164
|
|
|
$controller = \Aimeos\Controller\Frontend::create( $context, 'supplier' ); |
|
165
|
|
|
|
|
166
|
|
|
/** client/html/supplier/detail/domains |
|
167
|
|
|
* A list of domain names whose items should be available in the supplier detail view template |
|
168
|
|
|
* |
|
169
|
|
|
* The templates rendering the supplier detail section use the texts and |
|
170
|
|
|
* maybe images and attributes associated to the categories. You can |
|
171
|
|
|
* configure your own list of domains (attribute, media, price, product, |
|
172
|
|
|
* text, etc. are domains) whose items are fetched from the storage. |
|
173
|
|
|
* Please keep in mind that the more domains you add to the configuration, |
|
174
|
|
|
* the more time is required for fetching the content! |
|
175
|
|
|
* |
|
176
|
|
|
* @param array List of domain names |
|
177
|
|
|
* @since 2020.10 |
|
178
|
|
|
*/ |
|
179
|
|
|
$domains = $config->get( 'client/html/supplier/detail/domains', ['supplier/address', 'media', 'text'] ); |
|
180
|
|
|
|
|
181
|
|
|
$supplier = $controller->uses( $domains )->get( $supid ); |
|
182
|
|
|
|
|
183
|
|
|
$this->addMetaItems( $supplier, $expire, $tags ); |
|
184
|
|
|
|
|
185
|
|
|
$view->detailSupplierItem = $supplier; |
|
186
|
|
|
$view->detailSupplierAddresses = $this->getAddressStrings( $view, $supplier->getAddressItems() ); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
return parent::data( $view, $tags, $expire ); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* Returns the addresses as list of strings |
|
195
|
|
|
* |
|
196
|
|
|
* @param \Aimeos\MW\View\Iface $view View object |
|
197
|
|
|
* @param iterable $addresses List of address items implementing \Aimeos\MShop\Common\Item\Address\Iface |
|
198
|
|
|
* @return \Aimeos\Map List of address strings |
|
199
|
|
|
*/ |
|
200
|
|
|
protected function getAddressStrings( \Aimeos\MW\View\Iface $view, iterable $addresses ) : \Aimeos\Map |
|
201
|
|
|
{ |
|
202
|
|
|
$list = []; |
|
203
|
|
|
|
|
204
|
|
|
foreach( $addresses as $id => $addr ) |
|
205
|
|
|
{ |
|
206
|
|
|
$list[$id] = preg_replace( "/\n+/m", "\n", trim( sprintf( |
|
207
|
|
|
/// Address format with company (%1$s), salutation (%2$s), title (%3$s), first name (%4$s), last name (%5$s), |
|
208
|
|
|
/// 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), |
|
209
|
|
|
/// postal/zip code (%9$s), city (%10$s), state (%11$s), country (%12$s), language (%13$s), |
|
210
|
|
|
/// e-mail (%14$s), phone (%15$s), facsimile/telefax (%16$s), web site (%17$s), vatid (%18$s) |
|
211
|
|
|
$view->translate( 'client', '%1$s |
|
212
|
|
|
%2$s %3$s %4$s %5$s |
|
213
|
|
|
%6$s %7$s |
|
214
|
|
|
%8$s |
|
215
|
|
|
%9$s %10$s |
|
216
|
|
|
%11$s |
|
217
|
|
|
%12$s |
|
218
|
|
|
%13$s |
|
219
|
|
|
%14$s |
|
220
|
|
|
%15$s |
|
221
|
|
|
%16$s |
|
222
|
|
|
%17$s |
|
223
|
|
|
%18$s |
|
224
|
|
|
' |
|
225
|
|
|
), |
|
226
|
|
|
$addr->getCompany(), |
|
227
|
|
|
$view->translate( 'mshop/code', (string) $addr->getSalutation() ), |
|
228
|
|
|
$addr->getTitle(), |
|
229
|
|
|
$addr->getFirstName(), |
|
230
|
|
|
$addr->getLastName(), |
|
231
|
|
|
$addr->getAddress1(), |
|
232
|
|
|
$addr->getAddress2(), |
|
233
|
|
|
$addr->getAddress3(), |
|
234
|
|
|
$addr->getPostal(), |
|
235
|
|
|
$addr->getCity(), |
|
236
|
|
|
$addr->getState(), |
|
237
|
|
|
$view->translate( 'country', (string) $addr->getCountryId() ), |
|
238
|
|
|
$view->translate( 'language', (string) $addr->getLanguageId() ), |
|
239
|
|
|
$addr->getEmail(), |
|
240
|
|
|
$addr->getTelephone(), |
|
241
|
|
|
$addr->getTelefax(), |
|
242
|
|
|
$addr->getWebsite(), |
|
243
|
|
|
$addr->getVatID() |
|
244
|
|
|
) ) ); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
return map( $list ); |
|
248
|
|
|
} |
|
249
|
|
|
} |
|
250
|
|
|
|