1 | <?php |
||
25 | class Standard |
||
26 | extends \Aimeos\Client\Html\Common\Client\Factory\Base |
||
27 | implements \Aimeos\Client\Html\Common\Client\Factory\Iface |
||
28 | { |
||
29 | /** client/html/checkout/standard/delivery/subparts |
||
30 | * List of HTML sub-clients rendered within the checkout standard delivery section |
||
31 | * |
||
32 | * The output of the frontend is composed of the code generated by the HTML |
||
33 | * clients. Each HTML client can consist of serveral (or none) sub-clients |
||
34 | * that are responsible for rendering certain sub-parts of the output. The |
||
35 | * sub-clients can contain HTML clients themselves and therefore a |
||
36 | * hierarchical tree of HTML clients is composed. Each HTML client creates |
||
37 | * the output that is placed inside the container of its parent. |
||
38 | * |
||
39 | * At first, always the HTML code generated by the parent is printed, then |
||
40 | * the HTML code of its sub-clients. The order of the HTML sub-clients |
||
41 | * determines the order of the output of these sub-clients inside the parent |
||
42 | * container. If the configured list of clients is |
||
43 | * |
||
44 | * array( "subclient1", "subclient2" ) |
||
45 | * |
||
46 | * you can easily change the order of the output by reordering the subparts: |
||
47 | * |
||
48 | * client/html/<clients>/subparts = array( "subclient1", "subclient2" ) |
||
49 | * |
||
50 | * You can also remove one or more parts if they shouldn't be rendered: |
||
51 | * |
||
52 | * client/html/<clients>/subparts = array( "subclient1" ) |
||
53 | * |
||
54 | * As the clients only generates structural HTML, the layout defined via CSS |
||
55 | * should support adding, removing or reordering content by a fluid like |
||
56 | * design. |
||
57 | * |
||
58 | * @param array List of sub-client names |
||
59 | * @since 2014.03 |
||
60 | * @category Developer |
||
61 | */ |
||
62 | private $subPartPath = 'client/html/checkout/standard/delivery/subparts'; |
||
63 | private $subPartNames = []; |
||
64 | |||
65 | |||
66 | /** |
||
67 | * Returns the HTML code for insertion into the body. |
||
68 | * |
||
69 | * @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
||
70 | * @return string HTML code |
||
71 | */ |
||
72 | public function getBody( string $uid = '' ) : string |
||
113 | |||
114 | |||
115 | /** |
||
116 | * Returns the HTML string for insertion into the header. |
||
117 | * |
||
118 | * @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
||
119 | * @return string|null String including HTML tags for the header on error |
||
120 | */ |
||
121 | public function getHeader( string $uid = '' ) : ?string |
||
133 | |||
134 | |||
135 | /** |
||
136 | * Returns the sub-client given by its name. |
||
137 | * |
||
138 | * @param string $type Name of the client type |
||
139 | * @param string|null $name Name of the sub-client (Default if null) |
||
140 | * @return \Aimeos\Client\Html\Iface Sub-client object |
||
141 | */ |
||
142 | public function getSubClient( string $type, string $name = null ) : \Aimeos\Client\Html\Iface |
||
220 | |||
221 | |||
222 | /** |
||
223 | * Processes the input, e.g. store given values. |
||
224 | * |
||
225 | * A view must be available and this method doesn't generate any output |
||
226 | * besides setting view variables. |
||
227 | */ |
||
228 | public function process() |
||
229 | { |
||
230 | $view = $this->getView(); |
||
231 | |||
232 | try |
||
233 | { |
||
234 | $context = $this->getContext(); |
||
235 | $basketCtrl = \Aimeos\Controller\Frontend::create( $context, 'basket' ); |
||
236 | $servCtrl = \Aimeos\Controller\Frontend::create( $context, 'service' )->uses( ['media', 'price', 'text'] ); |
||
237 | |||
238 | // only start if there's something to do |
||
239 | if( ( $serviceIds = $view->param( 'c_deliveryoption', null ) ) !== null ) |
||
240 | { |
||
241 | $basketCtrl->deleteService( 'delivery' ); |
||
242 | |||
243 | foreach( (array) $serviceIds as $idx => $id ) |
||
244 | { |
||
245 | try |
||
246 | { |
||
247 | $basketCtrl->addService( $servCtrl->get( $id ), $view->param( 'c_delivery/' . $id, [] ), $idx ); |
||
248 | } |
||
249 | catch( \Aimeos\Controller\Frontend\Basket\Exception $e ) |
||
250 | { |
||
251 | $view->deliveryError = $e->getErrors(); |
||
252 | $view->standardErrorList = array_merge( $view->get( 'standardErrorList', [] ), $e->getErrors() ); |
||
253 | |||
254 | throw $e; |
||
255 | } |
||
256 | } |
||
257 | } |
||
258 | |||
259 | |||
260 | parent::process(); |
||
261 | |||
262 | |||
263 | // Test if delivery service is available |
||
264 | $services = $basketCtrl->get()->getServices( 'delivery' ); |
||
265 | |||
266 | if( !isset( $view->standardStepActive ) && $services->isEmpty() |
||
267 | && count( $servCtrl->getProviders( 'delivery' ) ) > 0 |
||
268 | ) { |
||
269 | $view->standardStepActive = 'delivery'; |
||
270 | return; |
||
271 | } |
||
272 | } |
||
273 | catch( \Exception $e ) |
||
274 | { |
||
275 | $view->standardStepActive = 'delivery'; |
||
276 | throw $e; |
||
277 | } |
||
278 | } |
||
279 | |||
280 | |||
281 | /** |
||
282 | * Returns the list of sub-client names configured for the client. |
||
283 | * |
||
284 | * @return array List of HTML client names |
||
285 | */ |
||
286 | protected function getSubClientNames() : array |
||
290 | |||
291 | |||
292 | /** |
||
293 | * Sets the necessary parameter values in the view. |
||
294 | * |
||
295 | * @param \Aimeos\MW\View\Iface $view The view object which generates the HTML output |
||
296 | * @param array &$tags Result array for the list of tags that are associated to the output |
||
297 | * @param string|null &$expire Result variable for the expiration date of the output (null for no expiry) |
||
298 | * @return \Aimeos\MW\View\Iface Modified view object |
||
299 | */ |
||
300 | public function addData( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\MW\View\Iface |
||
355 | } |
||
356 |