Completed
Push — master ( 25c6af...9f51fe )
by Aimeos
02:20
created

Base::getItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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, \Aimeos\Controller\Frontend\Order\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 and adds a new order for the given order base ID
64
	 *
65
	 * @param string $baseId Unique ID of the saved basket
66
	 * @param string $type Arbitrary order type (max. eight chars)
67
	 * @return \Aimeos\MShop\Order\Item\Iface Created order object
68
	 */
69
	public function addItem( $baseId, $type )
70
	{
71
		return $this->controller->addItem( $baseId, $type );
72
	}
73
74
75
	/**
76
	 * Returns the filter for searching items
77
	 *
78
	 * @return \Aimeos\MW\Criteria\Iface Filter object
79
	 */
80
	public function createFilter()
81
	{
82
		return $this->controller->createFilter();
83
	}
84
85
86
	/**
87
	 * Returns the order item for the given ID
88
	 *
89
	 * @param string $id Unique order ID
90
	 * @return \Aimeos\MShop\Order\Item\Iface Order object
91
	 */
92
	public function getItem( $id )
93
	{
94
		return $this->controller->getItem( $id );
95
	}
96
97
98
	/**
99
	 * Returns the order items based on the given filter that belong to the current user
100
	 *
101
	 * @param \Aimeos\MW\Criteria\Iface Filter object
102
	 * @param integer &$total|null Variable that will contain the total number of available items
103
	 * @return \Aimeos\MShop\Order\Item\Iface[] Associative list of IDs as keys and order objects as values
104
	 */
105
	public function searchItems( \Aimeos\MW\Criteria\Iface $filter, &$total = null )
106
	{
107
		return $this->controller->searchItems( $filter, $total );
108
	}
109
110
111
	/**
112
	 * Blocks the resources listed in the order.
113
	 *
114
	 * Every order contains resources like products or redeemed coupon codes
115
	 * that must be blocked so they can't be used by another customer in a
116
	 * later order. This method reduces the the stock level of products, the
117
	 * counts of coupon codes and others.
118
	 *
119
	 * It's save to call this method multiple times for one order. In this case,
120
	 * the actions will be executed only once. All subsequent calls will do
121
	 * nothing as long as the resources haven't been unblocked in the meantime.
122
	 *
123
	 * You can also block and unblock resources several times. Please keep in
124
	 * mind that unblocked resources may be reused by other orders in the
125
	 * meantime. This can lead to an oversell of products!
126
	 *
127
	 * @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object
128
	 * @return void
129
	 */
130
	public function block( \Aimeos\MShop\Order\Item\Iface $orderItem )
131
	{
132
		$this->getController()->block( $orderItem );
133
	}
134
135
136
	/**
137
	 * Frees the resources listed in the order.
138
	 *
139
	 * If customers created orders but didn't pay for them, the blocked resources
140
	 * like products and redeemed coupon codes must be unblocked so they can be
141
	 * ordered again or used by other customers. This method increased the stock
142
	 * level of products, the counts of coupon codes and others.
143
	 *
144
	 * It's save to call this method multiple times for one order. In this case,
145
	 * the actions will be executed only once. All subsequent calls will do
146
	 * nothing as long as the resources haven't been blocked in the meantime.
147
	 *
148
	 * You can also unblock and block resources several times. Please keep in
149
	 * mind that unblocked resources may be reused by other orders in the
150
	 * meantime. This can lead to an oversell of products!
151
	 *
152
	 * @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object
153
	 * @return void
154
	 */
155
	public function unblock( \Aimeos\MShop\Order\Item\Iface $orderItem )
156
	{
157
		$this->getController()->unblock( $orderItem );
158
	}
159
160
161
	/**
162
	 * Blocks or frees the resources listed in the order if necessary.
163
	 *
164
	 * After payment status updates, the resources like products or coupon
165
	 * codes listed in the order must be blocked or unblocked. This method
166
	 * cares about executing the appropriate action depending on the payment
167
	 * status.
168
	 *
169
	 * It's save to call this method multiple times for one order. In this case,
170
	 * the actions will be executed only once. All subsequent calls will do
171
	 * nothing as long as the payment status hasn't changed in the meantime.
172
	 *
173
	 * @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object
174
	 * @return void
175
	 */
176
	public function update( \Aimeos\MShop\Order\Item\Iface $orderItem )
177
	{
178
		$this->getController()->update( $orderItem );
179
	}
180
181
182
	/**
183
	 * Creates a new order from the given basket.
184
	 *
185
	 * Saves the given basket to the storage including the addresses, coupons,
186
	 * products, services, etc. and creates/stores a new order item for that
187
	 * order.
188
	 *
189
	 * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object to be stored
190
	 * @return \Aimeos\MShop\Order\Item\Iface Order item that belongs to the stored basket
191
	 * @deprecated 2017.04 Use store() from basket controller instead
192
	 */
193
	public function store( \Aimeos\MShop\Order\Item\Base\Iface $basket )
194
	{
195
		return $this->getController()->store( $basket );
196
	}
197
198
199
	/**
200
	 * Returns the frontend controller
201
	 *
202
	 * @return \Aimeos\Controller\Frontend\Order\Iface Frontend controller object
203
	 */
204
	protected function getController()
205
	{
206
		return $this->controller;
207
	}
208
}
209