/
AddressHelper.php
62 lines (51 loc) · 1.52 KB
/
AddressHelper.php
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
<?php
namespace \Service;
use \Entity\Address;
use \Entity\User;
class AddressHelper
{
/**
* This case tells, the address can be added ONLY by administration, agency can't modify it
* Also there is only one main address, not more
*/
const CASE_1 = 1;
/**
* In this case, agency can add a second delivery address
*/
const CASE_1_2 = 2;
/**
* In this case, admin can add multiple address, agency see the drop down list with
* those addresses and can choose it
* User cant modify those
*/
const CASE_1_2_3 = 4;
/**
* @var string
*/
private $addr_handling_case;
public function __construct($addr_handling_case)
{
$this->addr_handling_case = $addr_handling_case;
}
/**
* CHeck if user have rights to use this address in order creation
* @param Address $address
* @param User $user
*
* @return bool true if user can use that address at order creation
*/
public function validateAddress( Address $address, User $user )
{
// check if it is global delivery point and then check if this option is enabled in admin
if($address->getIsGlobalDeliveryPoint()) {
return $this->addr_handling_case === AddressHelper::CASE_1_2_3;
}
if($address->getUser() === $user) {
if(!$address->getIsMainAddress()) {
return $this->addr_handling_case === AddressHelper::CASE_1_2;
}
return true;
}
return false;
}
}