1 <?php
2
3 /* --------------------------------------------------------------
4 ProductAttributeRepository.inc.php 2016-01-07
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 ProductAttributeRepository
15 *
16 * @category System
17 * @package ProductModule
18 * @subpackage Repositories
19 */
20 class ProductAttributeRepository implements ProductAttributeRepositoryInterface
21 {
22 /**
23 * @var ProductAttributeRepositoryReaderInterface
24 */
25 protected $reader;
26
27 /**
28 * @var ProductAttributeRepositoryWriterInterface
29 */
30 protected $writer;
31
32 /**
33 * @var ProductAttributeRepositoryDeleterInterface
34 */
35 protected $deleter;
36
37
38 /**
39 * Initialize the product attribute repository.
40 *
41 * @param ProductAttributeRepositoryReaderInterface $reader
42 * @param ProductAttributeRepositoryWriterInterface $writer
43 * @param ProductAttributeRepositoryDeleterInterface $deleter
44 */
45 public function __construct(ProductAttributeRepositoryReaderInterface $reader,
46 ProductAttributeRepositoryWriterInterface $writer,
47 ProductAttributeRepositoryDeleterInterface $deleter)
48 {
49 $this->reader = $reader;
50 $this->writer = $writer;
51 $this->deleter = $deleter;
52 }
53
54
55 /**
56 * Adds an product attribute to a product by the given id.
57 *
58 * @param IdType $productId Id of product entity that adds the attribute.
59 * @param ProductAttributeInterface $productAttribute Product attribute entity to add.
60 *
61 * @return int Id of added product attribute entity.
62 */
63 public function addToProduct(IdType $productId, ProductAttributeInterface $productAttribute)
64 {
65 return $this->writer->insertIntoProduct($productId, $productAttribute);
66 }
67
68
69 /**
70 * Stores/Updates the passed product attribute entity.
71 *
72 * @param StoredProductAttributeInterface $productAttribute Product attribute entity to store.
73 *
74 * @return ProductAttributeRepository|$this Same instance for chained method calls.
75 */
76 public function store(StoredProductAttributeInterface $productAttribute)
77 {
78 $this->writer->update($productAttribute);
79
80 return $this;
81 }
82
83
84 /**
85 * Returns a stored product attribute entity by the given product attribute id.
86 *
87 * @param IdType $productAttributeId Id of expected product attribute entity.
88 *
89 * @return StoredProductAttributeInterface Expected stored product attribute entity.
90 */
91 public function getAttributeById(IdType $productAttributeId)
92 {
93 return $this->reader->getAttributeById($productAttributeId);
94 }
95
96
97 /**
98 * Returns a collection with all attribute entities that belongs to a product entity by the given product id.
99 *
100 * @param IdType $productId Id of product entity that contain the expected attributes.
101 *
102 * @return StoredProductAttributeCollection Collection with all attributes that belongs to the product.
103 */
104 public function getAttributesByProductId(IdType $productId)
105 {
106 return $this->reader->getAttributesByProductId($productId);
107 }
108
109
110 /**
111 * Removes a product attribute entity by the given product attribute id.
112 *
113 * @param IdType $productAttributeId Id of product attribute entity that should be deleted.
114 *
115 * @return ProductAttributeRepository|$this Same instance for chained method calls.
116 */
117 public function deleteAttributeById(IdType $productAttributeId)
118 {
119 $this->deleter->deleteAttributeById($productAttributeId);
120
121 return $this;
122 }
123
124
125 /**
126 * Removes product attributes by the given product id.
127 *
128 * @param IdType $productId Id of product entity of the attributes that should be deleted.
129 *
130 * @return ProductAttributeRepository|$this Same instance for chained method calls.
131 */
132 public function deleteAttributesByProductId(IdType $productId)
133 {
134 $this->deleter->deleteAttributesByProductId($productId);
135
136 return $this;
137 }
138 }