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\Order\Decorator; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Base for order frontend controller decorators |
16
|
|
|
* |
17
|
|
|
* @package Controller |
18
|
|
|
* @subpackage Frontend |
19
|
|
|
*/ |
20
|
|
|
abstract class Base |
21
|
|
|
implements \Aimeos\Controller\Frontend\Common\Decorator\Iface |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
private $context; |
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
|
|
|
$this->context = $context; |
36
|
|
|
$this->controller = $controller; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Passes unknown methods to wrapped objects. |
42
|
|
|
* |
43
|
|
|
* @param string $name Name of the method |
44
|
|
|
* @param array $param List of method parameter |
45
|
|
|
* @return mixed Returns the value of the called method |
46
|
|
|
* @throws \Aimeos\Controller\Frontend\Exception If method call failed |
47
|
|
|
*/ |
48
|
|
|
public function __call( $name, array $param ) |
49
|
|
|
{ |
50
|
|
|
return call_user_func_array( array( $this->controller, $name ), $param ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Creates a new order from the given basket. |
56
|
|
|
* |
57
|
|
|
* Saves the given basket to the storage including the addresses, coupons, |
58
|
|
|
* products, services, etc. and creates/stores a new order item for that |
59
|
|
|
* order. |
60
|
|
|
* |
61
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object to be stored |
62
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface Order item that belongs to the stored basket |
63
|
|
|
*/ |
64
|
|
|
public function store( \Aimeos\MShop\Order\Item\Base\Iface $basket ) |
65
|
|
|
{ |
66
|
|
|
return $this->getController()->store( $basket ); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Blocks the resources listed in the order. |
72
|
|
|
* |
73
|
|
|
* Every order contains resources like products or redeemed coupon codes |
74
|
|
|
* that must be blocked so they can't be used by another customer in a |
75
|
|
|
* later order. This method reduces the the stock level of products, the |
76
|
|
|
* counts of coupon codes and others. |
77
|
|
|
* |
78
|
|
|
* It's save to call this method multiple times for one order. In this case, |
79
|
|
|
* the actions will be executed only once. All subsequent calls will do |
80
|
|
|
* nothing as long as the resources haven't been unblocked in the meantime. |
81
|
|
|
* |
82
|
|
|
* You can also block and unblock resources several times. Please keep in |
83
|
|
|
* mind that unblocked resources may be reused by other orders in the |
84
|
|
|
* meantime. This can lead to an oversell of products! |
85
|
|
|
* |
86
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object |
87
|
|
|
* @return void |
88
|
|
|
*/ |
89
|
|
|
public function block( \Aimeos\MShop\Order\Item\Iface $orderItem ) |
90
|
|
|
{ |
91
|
|
|
$this->getController()->block( $orderItem ); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Frees the resources listed in the order. |
97
|
|
|
* |
98
|
|
|
* If customers created orders but didn't pay for them, the blocked resources |
99
|
|
|
* like products and redeemed coupon codes must be unblocked so they can be |
100
|
|
|
* ordered again or used by other customers. This method increased the stock |
101
|
|
|
* level of products, the counts of coupon codes and others. |
102
|
|
|
* |
103
|
|
|
* It's save to call this method multiple times for one order. In this case, |
104
|
|
|
* the actions will be executed only once. All subsequent calls will do |
105
|
|
|
* nothing as long as the resources haven't been blocked in the meantime. |
106
|
|
|
* |
107
|
|
|
* You can also unblock and block resources several times. Please keep in |
108
|
|
|
* mind that unblocked resources may be reused by other orders in the |
109
|
|
|
* meantime. This can lead to an oversell of products! |
110
|
|
|
* |
111
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object |
112
|
|
|
* @return void |
113
|
|
|
*/ |
114
|
|
|
public function unblock( \Aimeos\MShop\Order\Item\Iface $orderItem ) |
115
|
|
|
{ |
116
|
|
|
$this->getController()->unblock( $orderItem ); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Blocks or frees the resources listed in the order if necessary. |
122
|
|
|
* |
123
|
|
|
* After payment status updates, the resources like products or coupon |
124
|
|
|
* codes listed in the order must be blocked or unblocked. This method |
125
|
|
|
* cares about executing the appropriate action depending on the payment |
126
|
|
|
* status. |
127
|
|
|
* |
128
|
|
|
* It's save to call this method multiple times for one order. In this case, |
129
|
|
|
* the actions will be executed only once. All subsequent calls will do |
130
|
|
|
* nothing as long as the payment status hasn't changed in the meantime. |
131
|
|
|
* |
132
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object |
133
|
|
|
* @return void |
134
|
|
|
*/ |
135
|
|
|
public function update( \Aimeos\MShop\Order\Item\Iface $orderItem ) |
136
|
|
|
{ |
137
|
|
|
$this->getController()->update( $orderItem ); |
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Returns the context item |
143
|
|
|
* |
144
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Context item object |
145
|
|
|
*/ |
146
|
|
|
protected function getContext() |
147
|
|
|
{ |
148
|
|
|
return $this->context; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Returns the frontend controller |
154
|
|
|
* |
155
|
|
|
* @return \Aimeos\Controller\Frontend\Common\Iface Frontend controller object |
156
|
|
|
*/ |
157
|
|
|
protected function getController() |
158
|
|
|
{ |
159
|
|
|
return $this->controller; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|