1 <?php
2
3 /* --------------------------------------------------------------
4 OrderReadService.php 2015-11-03
5 Gambio GmbH
6 http://www.gambio.de
7 Copyright (c) 2015 Gambio GmbH
8 Released under the GNU General Public License (Version 2)
9 [http://www.gnu.org/licenses/gpl-2.0.html]
10 --------------------------------------------------------------
11 */
12
13 MainFactory::load_class('OrderReadServiceInterface');
14
15 /**
16 * Class OrderReadService
17 *
18 * @category System
19 * @package Order
20 */
21 class OrderReadService implements OrderReadServiceInterface
22 {
23 /**
24 * @var OrderRepositoryInterface
25 */
26 protected $orderRepository;
27
28 /**
29 * @var OrderItemRepositoryInterface
30 */
31 protected $orderItemRepository;
32
33 /**
34 * @var OrderListGenerator
35 */
36 protected $orderListGenerator;
37
38
39 /**
40 * OrderReadService Constructor
41 *
42 * @param OrderRepositoryInterface $orderRepository
43 * @param OrderItemRepositoryInterface $orderItemRepository
44 * @param OrderListGeneratorInterface $orderListGenerator
45 */
46 public function __construct(OrderRepositoryInterface $orderRepository,
47 OrderItemRepositoryInterface $orderItemRepository,
48 OrderListGeneratorInterface $orderListGenerator)
49 {
50 $this->orderRepository = $orderRepository;
51 $this->orderItemRepository = $orderItemRepository;
52 $this->orderListGenerator = $orderListGenerator;
53 }
54
55
56 /**
57 * Get Order by ID
58 *
59 * Returns an order, depending on the provided order ID.
60 *
61 * @param \IdType $orderId Order ID of the wanted order
62 *
63 * @return OrderInterface
64 */
65 public function getOrderById(IdType $orderId)
66 {
67 return $this->orderRepository->getById($orderId);
68 }
69
70
71 /**
72 * Get a stored order item by ID.
73 *
74 * Returns a stored order item, depending on the provided order item ID.
75 *
76 * @param IdType $orderItemId
77 *
78 * @return StoredOrderItemInterface
79 */
80 public function getOrderItemById(IdType $orderItemId)
81 {
82 return $this->orderItemRepository->getItemById($orderItemId);
83 }
84
85
86 /**
87 * Get Order List
88 *
89 * Returns an OrderListItemCollection depending on the provided arguments.
90 *
91 * @param IntType $startIndex Start index of order list item collections which should be returned.
92 * @param IntType $maxCount Maximum amount of collections.
93 * @param StringType $orderBy Argument to specify the order.
94 *
95 * @return \OrderListItemCollection
96 */
97 public function getOrderList(IntType $startIndex = null, IntType $maxCount = null, StringType $orderBy = null)
98 {
99 return $this->orderListGenerator->getOrderListByConditions(array(), $startIndex, $maxCount, $orderBy);
100 }
101
102
103 /**
104 * Get Order List by Customer ID
105 *
106 * Returns an OrderListItemCollection depending on the provided customer ID.
107 *
108 * @param IdType $customerId Customer ID
109 * @param IntType $startIndex Start index of order list item collections which should be returned.
110 * @param IntType $maxCount Maximum amount of collections.
111 * @param StringType $orderBy Argument to specify the order.
112 *
113 * @return \OrderListItemCollection
114 */
115 public function getOrderListByCustomerId(IdType $customerId,
116 IntType $startIndex = null,
117 IntType $maxCount = null,
118 StringType $orderBy = null)
119 {
120 return $this->orderListGenerator->getOrderListByConditions(array('orders.customers_id' => $customerId->asInt()),
121 $startIndex, $maxCount, $orderBy);
122 }
123
124
125 /**
126 * Get Order List by Order Status ID
127 *
128 * Returns an OrderListItemCollection depending on the provided order status ID.
129 *
130 * @param \IdType $orderStatusId Order status ID
131 * @param IntType $startIndex Start index of order list item collections which should be returned.
132 * @param IntType $maxCount Maximum amount of collections.
133 * @param StringType $orderBy Argument to specify the order.
134 *
135 * @return \OrderListItemCollection
136 */
137 public function getOrderListByOrderStatusId(IdType $orderStatusId,
138 IntType $startIndex = null,
139 IntType $maxCount = null,
140 StringType $orderBy = null)
141 {
142 return $this->orderListGenerator->getOrderListByConditions(array('orders.orders_status' => $orderStatusId->asInt()),
143 $startIndex, $maxCount, $orderBy);
144 }
145
146
147 /**
148 * Filter the order list by a string keyword.
149 *
150 * @param StringType $keyword Keyword to be used for searching the order list items.
151 * @param IntType $startIndex Start index of order list item collections which should be returned.
152 * @param IntType $maxCount Maximum amount of collections.
153 * @param StringType $orderBy Argument to specify the order.
154 *
155 * @return OrderListItemCollection
156 */
157 public function getOrderListByKeyword(StringType $keyword,
158 IntType $startIndex = null,
159 IntType $maxCount = null,
160 StringType $orderBy = null)
161 {
162 return $this->orderListGenerator->getOrderListByKeyword($keyword, $startIndex, $maxCount, $orderBy);
163 }
164 }