1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
7
|
|
|
* @package Controller |
8
|
|
|
* @subpackage Frontend |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\Controller\Frontend\Order; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Default implementation of the order frontend controller. |
17
|
|
|
* |
18
|
|
|
* @package Controller |
19
|
|
|
* @subpackage Frontend |
20
|
|
|
*/ |
21
|
|
|
class Standard |
22
|
|
|
extends \Aimeos\Controller\Frontend\Base |
23
|
|
|
implements Iface, \Aimeos\Controller\Frontend\Common\Iface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Creates and adds a new order for the given order base ID |
27
|
|
|
* |
28
|
|
|
* @param string $baseId Unique ID of the saved basket |
29
|
|
|
* @param string $type Arbitrary order type (max. eight chars) |
30
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface Created order object |
31
|
|
|
*/ |
32
|
|
|
public function addItem( $baseId, $type ) |
33
|
|
|
{ |
34
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order' ); |
35
|
|
|
|
36
|
|
|
$item = $manager->createItem()->setBaseId( $baseId )->setType( $type ); |
37
|
|
|
$manager->saveItem( $item ); |
38
|
|
|
|
39
|
|
|
return $item; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Returns the filter for searching items |
45
|
|
|
* |
46
|
|
|
* @return \Aimeos\MW\Criteria\Iface Filter object |
47
|
|
|
*/ |
48
|
|
|
public function createFilter() |
49
|
|
|
{ |
50
|
|
|
return \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order' )->createSearch(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns the order item for the given ID |
56
|
|
|
* |
57
|
|
|
* @param string $id Unique order ID |
58
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface Order object |
59
|
|
|
*/ |
60
|
|
|
public function getItem( $id ) |
61
|
|
|
{ |
62
|
|
|
return \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order' )->getItem( $id ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Returns the order items based on the given filter that belong to the current user |
68
|
|
|
* |
69
|
|
|
* @param \Aimeos\MW\Criteria\Iface Filter object |
70
|
|
|
* @param integer|null &$total Variable that will contain the total number of available items |
71
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface[] Associative list of IDs as keys and order objects as values |
72
|
|
|
*/ |
73
|
|
|
public function searchItems( \Aimeos\MW\Criteria\Iface $filter, &$total = null ) |
74
|
|
|
{ |
75
|
|
|
return \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order' )->searchItems( $filter, [], $total ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Blocks the resources listed in the order. |
81
|
|
|
* |
82
|
|
|
* Every order contains resources like products or redeemed coupon codes |
83
|
|
|
* that must be blocked so they can't be used by another customer in a |
84
|
|
|
* later order. This method reduces the the stock level of products, the |
85
|
|
|
* counts of coupon codes and others. |
86
|
|
|
* |
87
|
|
|
* It's save to call this method multiple times for one order. In this case, |
88
|
|
|
* the actions will be executed only once. All subsequent calls will do |
89
|
|
|
* nothing as long as the resources haven't been unblocked in the meantime. |
90
|
|
|
* |
91
|
|
|
* You can also block and unblock resources several times. Please keep in |
92
|
|
|
* mind that unblocked resources may be reused by other orders in the |
93
|
|
|
* meantime. This can lead to an oversell of products! |
94
|
|
|
* |
95
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object |
96
|
|
|
*/ |
97
|
|
|
public function block( \Aimeos\MShop\Order\Item\Iface $orderItem ) |
98
|
|
|
{ |
99
|
|
|
\Aimeos\Controller\Common\Order\Factory::createController( $this->getContext() )->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
|
|
|
*/ |
121
|
|
|
public function unblock( \Aimeos\MShop\Order\Item\Iface $orderItem ) |
122
|
|
|
{ |
123
|
|
|
\Aimeos\Controller\Common\Order\Factory::createController( $this->getContext() )->unblock( $orderItem ); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Blocks or frees the resources listed in the order if necessary. |
129
|
|
|
* |
130
|
|
|
* After payment status updates, the resources like products or coupon |
131
|
|
|
* codes listed in the order must be blocked or unblocked. This method |
132
|
|
|
* cares about executing the appropriate action depending on the payment |
133
|
|
|
* status. |
134
|
|
|
* |
135
|
|
|
* It's save to call this method multiple times for one order. In this case, |
136
|
|
|
* the actions will be executed only once. All subsequent calls will do |
137
|
|
|
* nothing as long as the payment status hasn't changed in the meantime. |
138
|
|
|
* |
139
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface $orderItem Order item object |
140
|
|
|
*/ |
141
|
|
|
public function update( \Aimeos\MShop\Order\Item\Iface $orderItem ) |
142
|
|
|
{ |
143
|
|
|
\Aimeos\Controller\Common\Order\Factory::createController( $this->getContext() )->update( $orderItem ); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Creates a new order from the given basket. |
149
|
|
|
* |
150
|
|
|
* Saves the given basket to the storage including the addresses, coupons, |
151
|
|
|
* products, services, etc. and creates/stores a new order item for that |
152
|
|
|
* order. |
153
|
|
|
* |
154
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object to be stored |
155
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface Order item that belongs to the stored basket |
156
|
|
|
* @deprecated 2017.04 Use store() from basket controller instead |
157
|
|
|
*/ |
158
|
|
|
public function store( \Aimeos\MShop\Order\Item\Base\Iface $basket ) |
159
|
|
|
{ |
160
|
|
|
$context = $this->getContext(); |
161
|
|
|
|
162
|
|
|
$orderManager = \Aimeos\MShop\Factory::createManager( $context, 'order' ); |
163
|
|
|
$orderBaseManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' ); |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
$orderBaseManager->begin(); |
167
|
|
|
$orderBaseManager->store( $basket ); |
168
|
|
|
$orderBaseManager->commit(); |
169
|
|
|
|
170
|
|
|
$orderItem = $orderManager->createItem(); |
171
|
|
|
$orderItem->setBaseId( $basket->getId() ); |
172
|
|
|
$orderItem->setType( \Aimeos\MShop\Order\Item\Base::TYPE_WEB ); |
173
|
|
|
$orderManager->saveItem( $orderItem ); |
174
|
|
|
|
175
|
|
|
|
176
|
|
|
return $orderItem; |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|