1 <?php
2 /* --------------------------------------------------------------
3 CustomerAddressRepository.inc.php 2015-07-06 gm
4 Gambio GmbH
5 http://www.gambio.de
6 Copyright (c) 2015 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 MainFactory::load_class('CustomerAddressRepositoryInterface');
13
14 /**
15 * Class CustomerAddressRepository
16 *
17 * This class contains basic methods for finding, creating and deleting customer addresses
18 *
19 * @category System
20 * @package Customer
21 * @subpackage Address
22 * @implements CustomerAddressRepositoryInterface
23 */
24 class CustomerAddressRepository implements CustomerAddressRepositoryInterface
25 {
26 /**
27 * @var CustomerAddressWriterInterface
28 */
29 protected $customerAddressWriter;
30 /**
31 * @var CustomerAddressDeleterInterface
32 */
33 protected $customerAddressDeleter;
34 /**
35 * @var CustomerAddressReaderInterface
36 */
37 protected $customerAddressReader;
38 /**
39 * @var AbstractCustomerFactory
40 */
41 protected $customerFactory;
42
43
44 /**
45 * Constructor of the class CustomerAddressRepository
46 *
47 * @param CustomerAddressWriterInterface $customerAddressWriter
48 * @param CustomerAddressDeleterInterface $customerAddressDeleter
49 * @param CustomerAddressReaderInterface $customerAddressReader
50 * @param AbstractCustomerFactory $customerFactory
51 */
52 public function __construct(CustomerAddressWriterInterface $customerAddressWriter,
53 CustomerAddressDeleterInterface $customerAddressDeleter,
54 CustomerAddressReaderInterface $customerAddressReader,
55 AbstractCustomerFactory $customerFactory)
56 {
57 $this->customerAddressWriter = $customerAddressWriter;
58 $this->customerAddressDeleter = $customerAddressDeleter;
59 $this->customerAddressReader = $customerAddressReader;
60 $this->customerFactory = $customerFactory;
61 }
62
63
64 /**
65 * @return CustomerAddress
66 */
67 public function getNewAddress()
68 {
69 $address = $this->customerFactory->createCustomerAddress();
70 $this->customerAddressWriter->write($address);
71 return $address;
72 }
73
74 /**
75 * Stores the customer address
76 *
77 * @param CustomerAddressInterface $address
78 */
79 public function store(CustomerAddressInterface $address)
80 {
81 $this->customerAddressWriter->write($address);
82 }
83
84 /**
85 * Deletes the customer address
86 *
87 * @param CustomerInterface $customer
88 */
89 public function deleteCustomerAddressesByCustomer(CustomerInterface $customer)
90 {
91 $this->customerAddressDeleter->deleteByCustomer($customer);
92 }
93
94
95 public function deleteCustomerAddress(CustomerAddressInterface $address)
96 {
97 $this->customerAddressDeleter->delete($address);
98 }
99
100
101 /**
102 * Get all registered address records.
103 *
104 * @return array Returns an array of CustomerAddress objects.
105 */
106 public function getAllAddresses()
107 {
108 return $this->customerAddressReader->getAllAddresses();
109 }
110
111
112 /**
113 * Filter existing address records by provided string.
114 *
115 * @param string $p_keyword
116 *
117 * @return array Returns an array of CustomerAddress objects.
118 */
119 public function filterAddresses($p_keyword)
120 {
121 return $this->customerAddressReader->filterAddresses($p_keyword);
122 }
123
124 /**
125 * Gets all customer addresses
126 *
127 * @param CustomerInterface $customer
128 *
129 * @return array of CustomerAddress objects
130 */
131 public function getCustomerAddresses(CustomerInterface $customer)
132 {
133 $customerAddressArray = $this->customerAddressReader->findAddressesByCustomer($customer);
134 return $customerAddressArray;
135 }
136
137
138 /**
139 * @param IdType $addressBookId
140 *
141 * @return CustomerAddress
142 */
143 public function getById(IdType $addressBookId)
144 {
145 $customerAddress = $this->customerAddressReader->findById($addressBookId);
146 return $customerAddress;
147 }
148
149
150 /**
151 * @param IdType $addressBookId
152 *
153 * @return CustomerAddress
154 */
155 public function findById(IdType $addressBookId)
156 {
157 $customerAddress = $this->customerAddressReader->findById($addressBookId);
158 return $customerAddress;
159 }
160 }
161