1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017 |
6
|
|
|
* @package Controller |
7
|
|
|
* @subpackage Frontend |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Frontend\Stock; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Default implementation of the stock frontend controller |
16
|
|
|
* |
17
|
|
|
* @package Controller |
18
|
|
|
* @subpackage Frontend |
19
|
|
|
*/ |
20
|
|
|
class Standard |
21
|
|
|
extends \Aimeos\Controller\Frontend\Base |
|
|
|
|
22
|
|
|
implements Iface, \Aimeos\Controller\Frontend\Common\Iface |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Returns the given search filter with the conditions attached for filtering by product code |
26
|
|
|
* |
27
|
|
|
* @param \Aimeos\MW\Criteria\Iface $filter Criteria object used for stock search |
28
|
|
|
* @param array $codes List of product codes |
29
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
30
|
|
|
* @since 2017.03 |
31
|
|
|
*/ |
32
|
|
|
public function addFilterCodes( \Aimeos\MW\Criteria\Iface $filter, array $codes ) |
33
|
|
|
{ |
34
|
|
|
$expr = [ |
35
|
|
|
$filter->compare( '==', 'stock.productcode', $codes ), |
36
|
|
|
$filter->getConditions(), |
37
|
|
|
]; |
38
|
|
|
$filter->setConditions( $filter->combine( '&&', $expr ) ); |
39
|
|
|
|
40
|
|
|
return $filter; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns the given search filter with the conditions attached for filtering by type code |
46
|
|
|
* |
47
|
|
|
* @param \Aimeos\MW\Criteria\Iface $filter Criteria object used for stock search |
48
|
|
|
* @param array $codes List of stock type codes |
49
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
50
|
|
|
* @since 2017.03 |
51
|
|
|
*/ |
52
|
|
|
public function addFilterTypes( \Aimeos\MW\Criteria\Iface $filter, array $codes ) |
53
|
|
|
{ |
54
|
|
|
if( !empty( $codes ) ) |
55
|
|
|
{ |
56
|
|
|
$expr = [ |
57
|
|
|
$filter->compare( '==', 'stock.type.code', $codes ), |
58
|
|
|
$filter->getConditions(), |
59
|
|
|
]; |
60
|
|
|
$filter->setConditions( $filter->combine( '&&', $expr ) ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $filter; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Returns the default stock filter |
69
|
|
|
* |
70
|
|
|
* @param boolean True to add default criteria |
71
|
|
|
* @return \Aimeos\MW\Criteria\Iface Criteria object containing the conditions for searching |
72
|
|
|
* @since 2017.03 |
73
|
|
|
*/ |
74
|
|
|
public function createFilter() |
75
|
|
|
{ |
76
|
|
|
return \Aimeos\MShop\Factory::createManager( $this->getContext(), 'stock' )->createSearch( true ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Returns the stock item for the given stock ID |
82
|
|
|
* |
83
|
|
|
* @param string $id Unique stock ID |
84
|
|
|
* @param string[] $domains Domain names of items that are associated with the stocks and that should be fetched too |
|
|
|
|
85
|
|
|
* @return \Aimeos\MShop\Stock\Item\Iface Stock item including the referenced domains items |
86
|
|
|
* @since 2017.03 |
87
|
|
|
*/ |
88
|
|
|
public function getItem( $id ) |
89
|
|
|
{ |
90
|
|
|
return \Aimeos\MShop\Factory::createManager( $this->getContext(), 'stock' )->getItem( $id ); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Returns the stocks filtered by the given criteria object |
96
|
|
|
* |
97
|
|
|
* @param \Aimeos\MW\Criteria\Iface $filter Critera object which contains the filter conditions |
98
|
|
|
* @param integer &$total Parameter where the total number of found stocks will be stored in |
99
|
|
|
* @return array Ordered list of stock items implementing \Aimeos\MShop\Stock\Item\Iface |
100
|
|
|
* @since 2017.03 |
101
|
|
|
*/ |
102
|
|
|
public function searchItems( \Aimeos\MW\Criteria\Iface $filter, &$total = null ) |
103
|
|
|
{ |
104
|
|
|
return \Aimeos\MShop\Factory::createManager( $this->getContext(), 'stock' )->searchItems( $filter, [], $total ); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|