1 <?php
2 /* --------------------------------------------------------------
3 ProductAttributeService.inc.php 2016-01-18
4 Gambio GmbH
5 http://www.gambio.de
6 Copyright (c) 2016 Gambio GmbH
7 Released under the GNU General Public License (Version 2)
8 [http://www.gnu.org/licenses/gpl-2.0.html]
9 --------------------------------------------------------------
10 */
11
12 /**
13 * Class ProductAttributeService
14 *
15 * @category System
16 * @package ProductModule
17 * @subpackage Interfaces
18 */
19 class ProductAttributeService implements ProductAttributeServiceInterface
20 {
21 /**
22 * @var ProductAttributeRepositoryInterface
23 */
24 protected $productAttributeRepo;
25
26
27 /**
28 * Initialize the product attribute service.
29 *
30 * @param ProductAttributeRepositoryInterface $productAttributeRepo
31 */
32 public function __construct(ProductAttributeRepositoryInterface $productAttributeRepo)
33 {
34 $this->productAttributeRepo = $productAttributeRepo;
35 }
36
37
38 /**
39 * Adds an product attribute to a product by the given id.
40 *
41 * @param IdType $productId Id of product entity that adds the attribute.
42 * @param ProductAttributeInterface $attribute Product attribute entity to add.
43 *
44 * @return int Id of inserted product attribute.
45 */
46 public function addAttribute(IdType $productId, ProductAttributeInterface $attribute)
47 {
48 return $this->productAttributeRepo->addToProduct($productId, $attribute);
49 }
50
51
52 /**
53 * Updates the passed product attribute entity.
54 *
55 * @param StoredProductAttributeInterface $attribute Product attribute entity to update.
56 *
57 * @return $this|ProductAttributeService Same instance for chained method calls.
58 */
59 public function updateAttribute(StoredProductAttributeInterface $attribute)
60 {
61 $this->productAttributeRepo->store($attribute);
62
63 return $this;
64 }
65
66
67 /**
68 * Returns a stored product attribute entity by the given product attribute id.
69 *
70 * @param IdType $productAttributeId Id of expected product attribute entity.
71 *
72 * @return StoredProductAttributeInterface Expected stored product attribute entity.
73 */
74 public function getAttributeById(IdType $productAttributeId)
75 {
76 return $this->productAttributeRepo->getAttributeById($productAttributeId);
77 }
78
79
80 /**
81 * Returns a collection with all attribute entities that belongs to a product entity by the given product id.
82 *
83 * @param IdType $productId Id of product entity that contain the expected attributes.
84 *
85 * @return StoredProductAttributeCollection Collection with all attributes that belongs to the product.
86 */
87 public function getAttributesByProductId(IdType $productId)
88 {
89 return $this->productAttributeRepo->getAttributesByProductId($productId);
90 }
91
92
93 /**
94 * Removes a product attribute entity by the given product attribute id.
95 *
96 * @param IdType $productAttributeId Id of product attribute entity that should be deleted.
97 *
98 * @return ProductAttributeService|$this Same instance for chained method calls.
99 */
100 public function removeAttributeById(IdType $productAttributeId)
101 {
102 $this->productAttributeRepo->deleteAttributeById($productAttributeId);
103
104 return $this;
105 }
106
107
108 /**
109 * Removes product attributes by the given product id.
110 *
111 * @param IdType $productId Id of product entity of the attributes that should be deleted.
112 *
113 * @return ProductAttributeService|$this Same instance for chained method calls.
114 */
115 public function removeAttributesByProductId(IdType $productId)
116 {
117 $this->productAttributeRepo->deleteAttributesByProductId($productId);
118
119 return $this;
120 }
121 }