1 <?php
2
3 /* --------------------------------------------------------------
4 ProductListItem.inc.php 2015-12-09
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 /**
14 * Class ProductListItem
15 *
16 * @category System
17 * @package Product
18 * @subpackage Entities
19 */
20 class ProductListItem
21 {
22 /**
23 * Product repository.
24 *
25 * @var ProductRepositoryInterface
26 */
27 protected $productRepo;
28
29 /**
30 * Product ID.
31 *
32 * @var int
33 */
34 protected $productId;
35
36 /**
37 * Is product active?
38 *
39 * @var boolean
40 */
41 protected $active;
42
43 /**
44 * Product name.
45 *
46 * @var string
47 */
48 protected $name;
49
50 /**
51 * URL keywords.
52 *
53 * @var string
54 */
55 protected $urlKeywords;
56
57 /**
58 * Image.
59 *
60 * @var string
61 */
62 protected $image;
63
64 /**
65 * Image alternative text.
66 *
67 * @var string
68 */
69 protected $imageAltText;
70
71
72 /**
73 * ProductListItem constructor.
74 *
75 * @param ProductRepositoryInterface $productRepo Product Repository.
76 * @param IdType $productId Product ID.
77 * @param BoolType $isActive Is the product active?
78 * @param StringType $name Product name.
79 * @param StringType $urlKeywords URL keywords.
80 * @param StringType $image Product image.
81 * @param StringType $imageAltText Product image alternative text.
82 *
83 */
84 public function __construct(ProductRepositoryInterface $productRepo,
85 IdType $productId,
86 BoolType $isActive,
87 StringType $name,
88 StringType $urlKeywords,
89 StringType $image,
90 StringType $imageAltText)
91 {
92 $this->productRepo = $productRepo;
93 $this->productId = $productId->asInt();
94 $this->active = $isActive->asBool();
95 $this->name = $name->asString();
96 $this->urlKeywords = $urlKeywords->asString();
97 $this->image = $image->asString();
98 $this->imageAltText = $imageAltText->asString();
99 }
100
101
102 /**
103 * Returns the product ID.
104 *
105 * @return int
106 */
107 public function getProductId()
108 {
109 return $this->productId;
110 }
111
112
113 /**
114 * Checks if product is active or not.
115 *
116 * @return boolean
117 */
118 public function isActive()
119 {
120 return $this->active;
121 }
122
123
124 /**
125 * Returns the name of the product.
126 *
127 * @return string
128 */
129 public function getName()
130 {
131 return $this->name;
132 }
133
134
135 /**
136 * Returns the URL keywords.
137 *
138 * @return string
139 */
140 public function getUrlKeywords()
141 {
142 return $this->urlKeywords;
143 }
144
145
146 /**
147 * Returns the image.
148 *
149 * @return string
150 */
151 public function getImage()
152 {
153 return $this->image;
154 }
155
156
157 /**
158 * Returns the alternative image text.
159 *
160 * @return string
161 */
162 public function getImageAltText()
163 {
164 return $this->imageAltText;
165 }
166
167
168 /**
169 * Returns the product object.
170 *
171 * @throws InvalidArgumentException if the product ID is not valid.
172 *
173 * @return ProductListItem Same instance for chained method calls.
174 */
175 public function getProductObject()
176 {
177 $id = new IdType($this->getProductId());
178
179 return $this->productRepo->getProductById($id);
180 }
181 }