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
|
|
|
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\Order\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
|
|
|
* Creates a new order from the given basket. |
64
|
|
|
* |
65
|
|
|
* Saves the given basket to the storage including the addresses, coupons, |
66
|
|
|
* products, services, etc. and creates/stores a new order item for that |
67
|
|
|
* order. |
68
|
|
|
* |
69
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object to be stored |
70
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface Order item that belongs to the stored basket |
71
|
|
|
*/ |
72
|
|
|
public function store( \Aimeos\MShop\Order\Item\Base\Iface $basket ) |
73
|
|
|
{ |
74
|
|
|
return $this->getController()->store( $basket ); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Blocks the resources listed in the order. |
80
|
|
|
* |
81
|
|
|
* Every order contains resources like products or redeemed coupon codes |
82
|
|
|
* that must be blocked so they can't be used by another customer in a |
83
|
|
|
* later order. This method reduces the the stock level of products, the |
84
|
|
|
* counts of coupon codes and others. |
85
|
|
|
* |
86
|
|
|
* It's save to call this method multiple times for one order. In this case, |
87
|
|
|
* the actions will be executed only once. All subsequent calls will do |
88
|
|
|
* nothing as long as the resources haven't been unblocked in the meantime. |
89
|
|
|
* |
90
|
|
|
* You can also block and unblock resources several times. Please keep in |
91
|
|
|
* mind that unblocked resources may be reused by other orders in the |
92
|
|
|
* meantime. This can lead to an oversell of products! |
93
|
|
|
* |
94
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object |
95
|
|
|
* @return void |
96
|
|
|
*/ |
97
|
|
|
public function block( \Aimeos\MShop\Order\Item\Iface $orderItem ) |
98
|
|
|
{ |
99
|
|
|
$this->getController()->block( $orderItem ); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Frees the resources listed in the order. |
105
|
|
|
* |
106
|
|
|
* If customers created orders but didn't pay for them, the blocked resources |
107
|
|
|
* like products and redeemed coupon codes must be unblocked so they can be |
108
|
|
|
* ordered again or used by other customers. This method increased the stock |
109
|
|
|
* level of products, the counts of coupon codes and others. |
110
|
|
|
* |
111
|
|
|
* It's save to call this method multiple times for one order. In this case, |
112
|
|
|
* the actions will be executed only once. All subsequent calls will do |
113
|
|
|
* nothing as long as the resources haven't been blocked in the meantime. |
114
|
|
|
* |
115
|
|
|
* You can also unblock and block resources several times. Please keep in |
116
|
|
|
* mind that unblocked resources may be reused by other orders in the |
117
|
|
|
* meantime. This can lead to an oversell of products! |
118
|
|
|
* |
119
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object |
120
|
|
|
* @return void |
121
|
|
|
*/ |
122
|
|
|
public function unblock( \Aimeos\MShop\Order\Item\Iface $orderItem ) |
123
|
|
|
{ |
124
|
|
|
$this->getController()->unblock( $orderItem ); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Blocks or frees the resources listed in the order if necessary. |
130
|
|
|
* |
131
|
|
|
* After payment status updates, the resources like products or coupon |
132
|
|
|
* codes listed in the order must be blocked or unblocked. This method |
133
|
|
|
* cares about executing the appropriate action depending on the payment |
134
|
|
|
* status. |
135
|
|
|
* |
136
|
|
|
* It's save to call this method multiple times for one order. In this case, |
137
|
|
|
* the actions will be executed only once. All subsequent calls will do |
138
|
|
|
* nothing as long as the payment status hasn't changed in the meantime. |
139
|
|
|
* |
140
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object |
141
|
|
|
* @return void |
142
|
|
|
*/ |
143
|
|
|
public function update( \Aimeos\MShop\Order\Item\Iface $orderItem ) |
144
|
|
|
{ |
145
|
|
|
$this->getController()->update( $orderItem ); |
|
|
|
|
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Returns the frontend controller |
151
|
|
|
* |
152
|
|
|
* @return \Aimeos\Controller\Frontend\Order\Iface Frontend controller object |
153
|
|
|
*/ |
154
|
|
|
protected function getController() |
155
|
|
|
{ |
156
|
|
|
return $this->controller; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|