1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
<?php
/* --------------------------------------------------------------
CustomerReadService.inc.php 2015-08-29
Gambio GmbH
http://www.gambio.de
Copyright (c) 2015 Gambio GmbH
Released under the GNU General Public License (Version 2)
[http://www.gnu.org/licenses/gpl-2.0.html]
--------------------------------------------------------------
*/
MainFactory::load_class('CustomerReadServiceInterface');
/**
* Class CustomerReadService
*
* This class provides methods for reading customer data.
*
* @category System
* @package Customer
* @implements CustomerReadServiceInterface
*/
class CustomerReadService implements CustomerReadServiceInterface
{
/**
* Customer repository.
* @var CustomerRepositoryInterface
*/
protected $customerRepository;
/**
* Constructor of the class CustomerService.
*
* @param CustomerRepositoryInterface $customerRepository Customer repository.
*/
public function __construct(CustomerRepositoryInterface $customerRepository)
{
$this->customerRepository = $customerRepository;
}
/**
* Finds a customer by an entered ID.
*
* @param IdType $customerId Customer ID.
*
* @return Customer Customer.
*/
public function getCustomerById(IdType $customerId)
{
return $this->customerRepository->getCustomerById($customerId);
}
/**
* Finds a customer by its email address. Returns null if no customer is found.
*
* @param CustomerEmailInterface $emailAddress
*
* @return Customer|null
*/
public function findCustomerByEmail(CustomerEmailInterface $emailAddress)
{
$customer = $this->customerRepository->getRegistreeByEmail($emailAddress);
if($customer === null)
{
$customer = $this->customerRepository->getGuestByEmail($emailAddress);
}
return $customer;
}
/**
* Checks if the email address of the registree already exists.
*
* @param CustomerEmailInterface $email Customer's E-Mail address.
*
* @return bool Does the E-Mail address already exist?
*/
public function registreeEmailExists(CustomerEmailInterface $email)
{
$customer = $this->customerRepository->getRegistreeByEmail($email);
if($customer === null)
{
return false;
}
return true;
}
/**
* Checks if address is the default address of the customer.
*
* @param CustomerAddressInterface $customerAddress Customer's address.
*
* @return bool Is provided address the customer's default address?
*/
public function addressIsDefaultCustomerAddress(CustomerAddressInterface $customerAddress)
{
$customer = $this->getCustomerById(new IdType((string)$customerAddress->getCustomerId()));
return $customer->getDefaultAddress()->getId() == new IdType((string)$customerAddress->getCustomerId());
}
/**
* Filters customer records and returns an array with results.
*
* Example:
* $service->filterCustomers('customers_id' => 1);
*
* @param array $conditions Associative array containing the desired field and value.
* @param int $limit MySQL limit applied to the records.
* @param int $offset MySQL offset applied to the records.
*
* @return array Returns an array that contains customer objects.
*/
public function filterCustomers(array $conditions = array(), $limit = null, $offset = null)
{
return $this->customerRepository->filterCustomers($conditions, $limit, $offset);
}
}