1 <?php
2
3 /* --------------------------------------------------------------
4 ProductReadService.inc.php 2016-01-28
5 Gambio GmbH
6 http://www.gambio.de
7 Copyright (c) 2016 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 /**
14 * Class ProductReadService
15 *
16 * @category System
17 * @package Product
18 */
19 class ProductReadService implements ProductReadServiceInterface
20 {
21 /**
22 * @var ProductRepositoryInterface
23 */
24 protected $productRepo;
25
26 /**
27 * @var ProductListProviderFactoryInterface
28 */
29 protected $listProviderFactory;
30
31 /**
32 * The product category linker.
33 *
34 * @var ProductCategoryLinkerInterface
35 */
36 protected $productLinker;
37
38
39 /**
40 * ProductReadService constructor.
41 *
42 * @param ProductRepositoryInterface $productRepo
43 * @param ProductListProviderFactoryInterface $listProviderFactory
44 * @param ProductCategoryLinkerInterface $productLinker
45 */
46 public function __construct(ProductRepositoryInterface $productRepo,
47 ProductListProviderFactoryInterface $listProviderFactory,
48 ProductCategoryLinkerInterface $productLinker)
49 {
50 $this->productRepo = $productRepo;
51 $this->listProviderFactory = $listProviderFactory;
52 $this->productLinker = $productLinker;
53 }
54
55
56 /**
57 * Get Product by ID
58 *
59 * Returns a specific product, depending on the provided ID.
60 *
61 * @param IdType $productId The ID of the product to return.
62 *
63 * @return StoredProductInterface The stored product.
64 */
65 public function getProductById(IdType $productId)
66 {
67 return $this->productRepo->getProductById($productId);
68 }
69
70
71 /**
72 * Get Product List
73 *
74 * Returns a specific product list.
75 *
76 * @param LanguageCode $languageCode The language code.
77 * @param IdType|null $categoryId The category ID of the product list.
78 * @param IdType|null $customerStatusLimit The customers status limit.
79 *
80 * @return ProductListItemCollection
81 */
82 public function getProductList(LanguageCode $languageCode,
83 IdType $categoryId = null,
84 IdType $customerStatusLimit = null)
85 {
86 $conditions = array();
87
88 if($customerStatusLimit !== null)
89 {
90 $conditions = array('group_permission_' . $customerStatusLimit->asInt() => '1');
91 }
92
93 $productListProvider = $this->listProviderFactory->createProductListProvider($languageCode, $conditions);
94
95 if($categoryId !== null)
96 {
97 $collection = $productListProvider->getByCategoryId($categoryId);
98 }
99 else
100 {
101 $collection = $productListProvider->getAll();
102 }
103
104 return $collection;
105 }
106
107
108 /**
109 * Get Active Product List
110 *
111 * Returns an active products list.
112 *
113 * @param LanguageCode $languageCode The language code.
114 * @param IdType|null $categoryId The category ID of the product list.
115 * @param IdType|null $customerStatusLimit The customers status limit.
116 *
117 * @return ProductListItemCollection
118 */
119 public function getActiveProductList(LanguageCode $languageCode,
120 IdType $categoryId = null,
121 IdType $customerStatusLimit = null)
122 {
123 $conditions = array(
124 'products_status' => '1'
125 );
126
127 if($customerStatusLimit !== null)
128 {
129 $conditions['group_permission_' . $customerStatusLimit->asInt()] = '1';
130 }
131
132 $productListProvider = $this->listProviderFactory->createProductListProvider($languageCode, $conditions);
133
134 if($categoryId !== null)
135 {
136 $collection = $productListProvider->getByCategoryId($categoryId);
137 }
138 else
139 {
140 $collection = $productListProvider->getAll();
141 }
142
143 return $collection;
144 }
145
146
147 /**
148 * Returns the category Ids which are linked with given product id.
149 *
150 * @param IdType $productId
151 *
152 * @return IdCollection
153 */
154 public function getProductLinks(IdType $productId)
155 {
156 return $this->productLinker->getProductLinks($productId);
157 }
158 }