1 <?php
2
3 /* --------------------------------------------------------------
4 OrderItemPropertyRepository.php 2015-11-10
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 MainFactory::load_class('OrderItemAttributeRepositoryInterface');
14
15
16 /**
17 * Class OrderItemPropertyRepository
18 *
19 * @category System
20 * @package Order
21 * @subpackage Repositories
22 */
23 class OrderItemPropertyRepository implements OrderItemAttributeRepositoryInterface
24 {
25 /**
26 * Order item property repository reader.
27 * @var OrderItemPropertyRepositoryReaderInterface
28 */
29 protected $reader;
30
31 /**
32 * Order item property repository writer.
33 * @var OrderItemPropertyRepositoryWriterInterface
34 */
35 protected $writer;
36
37 /**
38 * Order item property repository deleter.
39 * @var OrderItemPropertyRepositoryDeleterInterface
40 */
41 protected $deleter;
42
43
44 /**
45 * OrderItemPropertyRepository constructor.
46 *
47 * @param OrderItemPropertyRepositoryReaderInterface $reader Order item property repository reader.
48 * @param OrderItemPropertyRepositoryWriterInterface $writer Order item property repository writer.
49 * @param OrderItemPropertyRepositoryDeleterInterface $deleter Order item property repository deleter.
50 */
51 public function __construct(OrderItemPropertyRepositoryReaderInterface $reader,
52 OrderItemPropertyRepositoryWriterInterface $writer,
53 OrderItemPropertyRepositoryDeleterInterface $deleter)
54 {
55 $this->reader = $reader;
56 $this->writer = $writer;
57 $this->deleter = $deleter;
58 }
59
60
61 /**
62 * Adds an attribute to an order item.
63 *
64 * @param IdType $orderItemId ID of the order item.
65 * @param OrderItemAttributeInterface $orderItemProperty Order item attribute to add.
66 *
67 * @return int ID of stored order item attribute.
68 */
69 public function addToOrderItem(IdType $orderItemId, OrderItemAttributeInterface $orderItemProperty)
70 {
71 return $this->writer->insertIntoOrderItem($orderItemId, $orderItemProperty);
72 }
73
74
75 /**
76 * Saves the attribute to the repository.
77 *
78 * @param StoredOrderItemAttributeInterface $orderItemProperty Property to save.
79 *
80 * @return OrderItemPropertyRepository Same instance for method chaining.
81 */
82 public function store(StoredOrderItemAttributeInterface $orderItemProperty)
83 {
84 $this->writer->update($orderItemProperty);
85
86 return $this;
87 }
88
89
90 /**
91 * Returns a stored property by the given ID.
92 *
93 * @param IdType $orderItemPropertyId ID of item property.
94 *
95 * @return StoredOrderItemAttributeInterface Stored property.
96 */
97 public function getItemAttributeById(IdType $orderItemPropertyId)
98 {
99 return $this->reader->getPropertyById($orderItemPropertyId);
100 }
101
102
103 /**
104 * Returns a stored property collection by the given order item ID.
105 *
106 * @param IdType $orderItemId ID of order item.
107 *
108 * @return StoredOrderItemAttributeCollection Stored item property collection.
109 */
110 public function getItemAttributesByOrderItemId(IdType $orderItemId)
111 {
112 return $this->reader->getPropertiesByOrderItemId($orderItemId);
113 }
114
115
116 /**
117 * Deletes an item property by the given item property ID.
118 *
119 * @param IdType $orderItemAttributeId ID of order item property.
120 *
121 * @return OrderItemPropertyRepository Same instance for method chaining.
122 */
123 public function deleteItemAttributeById(IdType $orderItemAttributeId)
124 {
125 $this->deleter->deletePropertyById($orderItemAttributeId);
126
127 return $this;
128 }
129
130
131 /**
132 * Deletes an item property by the given order item ID.
133 *
134 * @param IdType $orderItemId ID of order item.
135 *
136 * @return OrderItemPropertyRepository Same instance for method chaining.
137 */
138 public function deleteItemAttributesByOrderItemId(IdType $orderItemId)
139 {
140 $this->deleter->deletePropertiesByOrderItemId($orderItemId);
141
142 return $this;
143 }
144 }