1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016 |
6
|
|
|
* @package Controller |
7
|
|
|
* @subpackage Frontend |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Frontend\Service\Decorator; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Base for service frontend controller decorators |
16
|
|
|
* |
17
|
|
|
* @package Controller |
18
|
|
|
* @subpackage Frontend |
19
|
|
|
*/ |
20
|
|
|
abstract class Base |
21
|
|
|
extends \Aimeos\Controller\Frontend\Base |
|
|
|
|
22
|
|
|
implements \Aimeos\Controller\Frontend\Common\Decorator\Iface |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
private $controller; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Initializes the controller decorator. |
29
|
|
|
* |
30
|
|
|
* @param \Aimeos\Controller\Frontend\Iface $controller Controller object |
31
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object with required objects |
32
|
|
|
*/ |
33
|
|
|
public function __construct( \Aimeos\Controller\Frontend\Iface $controller, \Aimeos\MShop\Context\Item\Iface $context ) |
34
|
|
|
{ |
35
|
|
|
$iface = '\Aimeos\Controller\Frontend\Service\Iface'; |
36
|
|
|
if( !( $controller instanceof $iface ) ) |
37
|
|
|
{ |
38
|
|
|
$msg = sprintf( 'Class "%1$s" does not implement interface "%2$s"', get_class( $controller ), $iface ); |
39
|
|
|
throw new \Aimeos\Controller\Frontend\Exception( $msg ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$this->controller = $controller; |
43
|
|
|
|
44
|
|
|
parent::__construct( $context ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Passes unknown methods to wrapped objects. |
50
|
|
|
* |
51
|
|
|
* @param string $name Name of the method |
52
|
|
|
* @param array $param List of method parameter |
53
|
|
|
* @return mixed Returns the value of the called method |
54
|
|
|
* @throws \Aimeos\Controller\Frontend\Exception If method call failed |
55
|
|
|
*/ |
56
|
|
|
public function __call( $name, array $param ) |
57
|
|
|
{ |
58
|
|
|
return @call_user_func_array( array( $this->controller, $name ), $param ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Returns the service items that are available for the service type and the content of the basket. |
64
|
|
|
* |
65
|
|
|
* @param string $type Service type, e.g. "delivery" (shipping related) or "payment" (payment related) |
66
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket of the user |
67
|
|
|
* @param array $ref List of domains for which the items referenced by the services should be fetched too |
68
|
|
|
* @return array List of service items implementing \Aimeos\MShop\Service\Item\Iface with referenced items |
69
|
|
|
*/ |
70
|
|
|
public function getServices( $type, \Aimeos\MShop\Order\Item\Base\Iface $basket, |
71
|
|
|
$ref = array( 'media', 'price', 'text' ) ) |
72
|
|
|
{ |
73
|
|
|
return $this->controller->getServices( $type, $basket, $ref ); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Returns the list of attribute definitions which must be used to render the input form where the customer can |
79
|
|
|
* enter or chose the required data necessary by the service provider. |
80
|
|
|
* |
81
|
|
|
* @param string $type Service type, e.g. "delivery" (shipping related) or "payment" (payment related) |
82
|
|
|
* @param string $serviceId Identifier of one of the service option returned by getService() |
83
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object |
84
|
|
|
* @return array List of attribute definitions implementing \Aimeos\MW\Criteria\Attribute\Iface |
85
|
|
|
*/ |
86
|
|
|
public function getServiceAttributes( $type, $serviceId, \Aimeos\MShop\Order\Item\Base\Iface $basket ) |
87
|
|
|
{ |
88
|
|
|
return $this->controller->getServiceAttributes( $type, $serviceId, $basket ); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Returns the price of the service. |
94
|
|
|
* |
95
|
|
|
* @param string $type Service type, e.g. "delivery" (shipping related) or "payment" (payment related) |
96
|
|
|
* @param string $serviceId Identifier of one of the service option returned by getService() |
97
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket with products |
98
|
|
|
* @return \Aimeos\MShop\Price\Item\Iface Price item |
99
|
|
|
* @throws \Aimeos\Controller\Frontend\Service\Exception If no active service provider for this ID is available |
100
|
|
|
* @throws \Aimeos\MShop\Exception If service provider isn't available |
101
|
|
|
* @throws \Exception If an error occurs |
102
|
|
|
*/ |
103
|
|
|
public function getServicePrice( $type, $serviceId, \Aimeos\MShop\Order\Item\Base\Iface $basket ) |
104
|
|
|
{ |
105
|
|
|
return $this->controller->getServicePrice( $type, $serviceId, $basket ); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Returns a list of attributes that are invalid. |
111
|
|
|
* |
112
|
|
|
* @param string $type Service type, e.g. "delivery" (shipping related) or "payment" (payment related) |
113
|
|
|
* @param string $serviceId Identifier of the service option chosen by the customer |
114
|
|
|
* @param array $attributes List of key/value pairs with name of the attribute from attribute definition object as |
115
|
|
|
* key and the string entered by the customer as value |
116
|
|
|
* @return array List of key/value pairs of attributes keys and an error message for values that are invalid or |
117
|
|
|
* missing |
118
|
|
|
*/ |
119
|
|
|
public function checkServiceAttributes( $type, $serviceId, array $attributes ) |
120
|
|
|
{ |
121
|
|
|
return $this->controller->checkServiceAttributes( $type, $serviceId, $attributes ); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Returns the frontend controller |
127
|
|
|
* |
128
|
|
|
* @return \Aimeos\Controller\Frontend\Service\Iface Frontend controller object |
129
|
|
|
*/ |
130
|
|
|
protected function getController() |
131
|
|
|
{ |
132
|
|
|
return $this->controller; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|