1 | <?php |
||
20 | class Standard |
||
21 | extends \Aimeos\Controller\Frontend\Base |
||
22 | implements Iface, \Aimeos\Controller\Frontend\Common\Iface |
||
23 | { |
||
24 | /** |
||
25 | * Adds and returns a new customer item object |
||
26 | * |
||
27 | * @param array $values Values added to the newly created customer item like "customer.birthday" |
||
28 | * @return \Aimeos\MShop\Customer\Item\Iface Customer item |
||
29 | * @since 2017.04 |
||
30 | */ |
||
31 | public function addItem( array $values ) |
||
42 | |||
43 | |||
44 | /** |
||
45 | * Creates a new customer item object pre-filled with the given values but not yet stored |
||
46 | * |
||
47 | * @return \Aimeos\MShop\Customer\Item\Iface Customer item |
||
48 | */ |
||
49 | public function createItem( array $values = [] ) |
||
60 | |||
61 | |||
62 | /** |
||
63 | * Deletes a customer item that belongs to the current authenticated user |
||
64 | * |
||
65 | * @param string $id Unique customer ID |
||
66 | * @since 2017.04 |
||
67 | */ |
||
68 | public function deleteItem( $id ) |
||
75 | |||
76 | |||
77 | /** |
||
78 | * Updates the customer item identified by its ID |
||
79 | * |
||
80 | * @param string $id Unique customer ID |
||
81 | * @param array $values Values added to the customer item like "customer.birthday" or "customer.city" |
||
82 | * @return \Aimeos\MShop\Customer\Item\Iface Customer item |
||
83 | * @since 2017.04 |
||
84 | */ |
||
85 | public function editItem( $id, array $values ) |
||
98 | |||
99 | |||
100 | /** |
||
101 | * Returns the customer item for the given customer ID |
||
102 | * |
||
103 | * @param string|null $id Unique customer ID or null for current customer item |
||
104 | * @param string[] $domains Domain names of items that are associated with the customers and that should be fetched too |
||
105 | * @return \Aimeos\MShop\Customer\Item\Iface Customer item including the referenced domains items |
||
106 | * @since 2017.04 |
||
107 | */ |
||
108 | public function getItem( $id = null, array $domains = [] ) |
||
120 | |||
121 | |||
122 | /** |
||
123 | * Returns the customer item for the given customer code (usually e-mail address) |
||
124 | * |
||
125 | * This method doesn't check if the customer item belongs to the logged in user! |
||
126 | * |
||
127 | * @param string $code Unique customer code |
||
128 | * @param string[] $domains Domain names of items that are associated with the customers and that should be fetched too |
||
129 | * @return \Aimeos\MShop\Customer\Item\Iface Customer item including the referenced domains items |
||
130 | * @since 2017.04 |
||
131 | */ |
||
132 | public function findItem( $code, array $domains = [] ) |
||
136 | |||
137 | |||
138 | /** |
||
139 | * Stores a modified customer item |
||
140 | * |
||
141 | * @param \Aimeos\MShop\Customer\Item\Iface Customer item |
||
142 | */ |
||
143 | public function saveItem( \Aimeos\MShop\Customer\Item\Iface $item ) |
||
147 | |||
148 | |||
149 | /** |
||
150 | * Creates and returns a new item object |
||
151 | * |
||
152 | * @param array $values Values added to the newly created customer item like "customer.birthday" |
||
153 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item |
||
154 | * @since 2017.04 |
||
155 | */ |
||
156 | public function addAddressItem( array $values ) |
||
170 | |||
171 | |||
172 | /** |
||
173 | * Creates a new customer address item object pre-filled with the given values but not yet stored |
||
174 | * |
||
175 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item |
||
176 | */ |
||
177 | public function createAddressItem( array $values = [] ) |
||
190 | |||
191 | |||
192 | /** |
||
193 | * Deletes a customer item that belongs to the current authenticated user |
||
194 | * |
||
195 | * @param string $id Unique customer address ID |
||
196 | * @since 2017.04 |
||
197 | */ |
||
198 | public function deleteAddressItem( $id ) |
||
206 | |||
207 | |||
208 | /** |
||
209 | * Saves a modified customer item object |
||
210 | * |
||
211 | * @param string $id Unique customer address ID |
||
212 | * @param array $values Values added to the customer item like "customer.address.city" |
||
213 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item |
||
214 | * @since 2017.04 |
||
215 | */ |
||
216 | public function editAddressItem( $id, array $values ) |
||
230 | |||
231 | |||
232 | /** |
||
233 | * Returns the customer item for the given customer ID |
||
234 | * |
||
235 | * @param string $id Unique customer address ID |
||
236 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item |
||
237 | * @since 2017.04 |
||
238 | */ |
||
239 | public function getAddressItem( $id ) |
||
248 | |||
249 | |||
250 | /** |
||
251 | * Stores a modified customer address item |
||
252 | * |
||
253 | * @param \Aimeos\MShop\Customer\Item\Address\Iface Customer address item |
||
254 | */ |
||
255 | public function saveAddressItem( \Aimeos\MShop\Customer\Item\Address\Iface $item ) |
||
259 | |||
260 | |||
261 | /** |
||
262 | * Creates and returns a new list item object |
||
263 | * |
||
264 | * @param array $values Values added to the newly created customer item like "customer.lists.refid" |
||
265 | * @return \Aimeos\MShop\Common\Item\Lists\Iface Customer lists item |
||
266 | * @since 2017.06 |
||
267 | */ |
||
268 | public function addListItem( array $values ) |
||
269 | { |
||
270 | $context = $this->getContext(); |
||
271 | $manager = \Aimeos\MShop\Factory::createManager( $context, 'customer/lists' ); |
||
272 | |||
273 | if( !isset( $values['customer.lists.typeid'] ) ) |
||
274 | { |
||
275 | if( !isset( $values['customer.lists.type'] ) ) { |
||
276 | throw new \Aimeos\Controller\Frontend\Customer\Exception( sprintf( 'No customer lists type code' ) ); |
||
277 | } |
||
278 | |||
279 | if( !isset( $values['customer.lists.domain'] ) ) { |
||
280 | throw new \Aimeos\Controller\Frontend\Customer\Exception( sprintf( 'No customer lists domain' ) ); |
||
281 | } |
||
282 | |||
283 | $typeManager = \Aimeos\MShop\Factory::createManager( $context, 'customer/lists/type' ); |
||
284 | $typeItem = $typeManager->findItem( $values['customer.lists.type'], [], $values['customer.lists.domain'] ); |
||
285 | $values['customer.lists.typeid'] = $typeItem->getId(); |
||
286 | } |
||
287 | |||
288 | $item = $manager->createItem(); |
||
289 | $item->fromArray( $values ); |
||
290 | $item->setId( null ); |
||
291 | $item->setParentId( $context->getUserId() ); |
||
292 | |||
293 | $manager->saveItem( $item ); |
||
294 | |||
295 | return $item; |
||
296 | } |
||
297 | |||
298 | |||
299 | /** |
||
300 | * Returns a new customer lists filter criteria object |
||
301 | * |
||
302 | * @return \Aimeos\MW\Criteria\Iface New filter object |
||
303 | * @since 2017.06 |
||
304 | */ |
||
305 | public function createListsFilter() |
||
315 | |||
316 | |||
317 | /** |
||
318 | * Deletes a customer item that belongs to the current authenticated user |
||
319 | * |
||
320 | * @param string $id Unique customer address ID |
||
321 | * @since 2017.06 |
||
322 | */ |
||
323 | public function deleteListItem( $id ) |
||
324 | { |
||
325 | $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'customer/lists' ); |
||
326 | |||
327 | $this->checkUser( $manager->getItem( $id )->getParentId() ); |
||
328 | |||
329 | $manager->deleteItem( $id ); |
||
330 | } |
||
331 | |||
332 | |||
333 | /** |
||
334 | * Saves a modified customer lists item object |
||
335 | * |
||
336 | * @param string $id Unique customer lists ID |
||
337 | * @param array $values Values added to the customer lists item like "customer.lists.refid" |
||
338 | * @return \Aimeos\MShop\Common\Item\Lists\Iface Customer lists item |
||
339 | * @since 2017.06 |
||
340 | */ |
||
341 | public function editListItem( $id, array $values ) |
||
342 | { |
||
343 | $context = $this->getContext(); |
||
344 | $manager = \Aimeos\MShop\Factory::createManager( $context, 'customer/lists' ); |
||
345 | |||
346 | $item = $manager->getItem( $id, [], true ); |
||
347 | $this->checkUser( $item->getParentId() ); |
||
348 | |||
349 | if( !isset( $values['customer.lists.typeid'] ) ) |
||
350 | { |
||
351 | if( !isset( $values['customer.lists.type'] ) ) { |
||
352 | throw new \Aimeos\Controller\Frontend\Customer\Exception( sprintf( 'No customer lists type code' ) ); |
||
353 | } |
||
354 | |||
355 | if( !isset( $values['customer.lists.domain'] ) ) { |
||
356 | throw new \Aimeos\Controller\Frontend\Customer\Exception( sprintf( 'No customer lists domain' ) ); |
||
357 | } |
||
358 | |||
359 | $typeManager = \Aimeos\MShop\Factory::createManager( $context, 'customer/lists/type' ); |
||
360 | $typeItem = $typeManager->findItem( $values['customer.lists.type'], [], $values['customer.lists.domain'] ); |
||
361 | $values['customer.lists.typeid'] = $typeItem->getId(); |
||
362 | } |
||
363 | |||
364 | $item->fromArray( $values ); |
||
365 | $item->setId( $id ); |
||
366 | |||
367 | $manager->saveItem( $item ); |
||
368 | |||
369 | return $item; |
||
370 | } |
||
371 | |||
372 | |||
373 | /** |
||
374 | * Returns the customer item for the given customer ID |
||
375 | * |
||
376 | * @param string $id Unique customer address ID |
||
377 | * @return \Aimeos\MShop\Customer\Item\Address\Iface Customer address item |
||
378 | * @since 2017.06 |
||
379 | */ |
||
380 | public function getListItem( $id ) |
||
381 | { |
||
382 | $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'customer/lists' ); |
||
383 | $item = $manager->getItem( $id ); |
||
384 | |||
385 | $this->checkUser( $item->getParentId() ); |
||
386 | |||
387 | return $item; |
||
388 | } |
||
389 | |||
390 | |||
391 | /** |
||
392 | * Returns the customer lists items filtered by the given criteria |
||
393 | * |
||
394 | * @param \Aimeos\MW\Criteria\Iface $filter Criteria object which contains the filter conditions |
||
395 | * @param integer &$total Parameter where the total number of found attributes will be stored in |
||
396 | * @return \Aimeos\MShop\Common\Item\Lists\Iface[] Customer list items |
||
397 | * @since 2017.06 |
||
398 | */ |
||
399 | public function searchListItems( \Aimeos\MW\Criteria\Iface $filter, &$total = null ) |
||
400 | { |
||
401 | $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'customer/lists' ); |
||
402 | |||
403 | return $manager->searchItems( $filter, [], $total ); |
||
404 | } |
||
405 | |||
406 | |||
407 | /** |
||
408 | * Checks if the current user is allowed to retrieve the customer data for the given ID |
||
409 | * |
||
410 | * @param string $id Unique customer ID |
||
411 | * @throws \Aimeos\Controller\Frontend\Customer\Exception If access isn't allowed |
||
412 | */ |
||
413 | protected function checkUser( $id ) |
||
421 | } |
||
422 |