1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Customer\Observers\ClearCustomerObserver |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2018 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import-customer |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Customer\Observers; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Customer\Utils\ColumnKeys; |
24
|
|
|
use TechDivision\Import\Customer\Utils\MemberNames; |
25
|
|
|
use TechDivision\Import\Customer\Services\CustomerBunchProcessorInterface; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Observer that removes the customer with the identifier found in the CSV file. |
29
|
|
|
* |
30
|
|
|
* @author Tim Wagner <[email protected]> |
31
|
|
|
* @copyright 2018 TechDivision GmbH <[email protected]> |
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
33
|
|
|
* @link https://github.com/techdivision/import-customer |
34
|
|
|
* @link http://www.techdivision.com |
35
|
|
|
*/ |
36
|
|
|
class ClearCustomerObserver extends AbstractCustomerImportObserver |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The customer bunch processor instance. |
41
|
|
|
* |
42
|
|
|
* @var \TechDivision\Import\Customer\Services\CustomerBunchProcessorInterface |
43
|
|
|
*/ |
44
|
|
|
protected $customerBunchProcessor; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Initialize the observer with the passed customer bunch processor instance. |
48
|
|
|
* |
49
|
|
|
* @param \TechDivision\Import\Customer\Services\CustomerBunchProcessorInterface $customerBunchProcessor The customer bunch processor instance |
50
|
|
|
*/ |
51
|
|
|
public function __construct(CustomerBunchProcessorInterface $customerBunchProcessor) |
52
|
|
|
{ |
53
|
|
|
$this->customerBunchProcessor = $customerBunchProcessor; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Return's the customer bunch processor instance. |
58
|
|
|
* |
59
|
|
|
* @return \TechDivision\Import\Customer\Services\CustomerBunchProcessorInterface The customer bunch processor instance |
60
|
|
|
*/ |
61
|
|
|
protected function getCustomerBunchProcessor() |
62
|
|
|
{ |
63
|
|
|
return $this->customerBunchProcessor; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Process the observer's business logic. |
68
|
|
|
* |
69
|
|
|
* @return array The processed row |
70
|
|
|
*/ |
71
|
|
|
protected function process() |
72
|
|
|
{ |
73
|
|
|
|
74
|
|
|
// load email and website code |
75
|
|
|
$email = $this->getValue(ColumnKeys::EMAIL); |
76
|
|
|
$website = $this->getValue(ColumnKeys::WEBSITE); |
77
|
|
|
|
78
|
|
|
// query whether or not, we've found a customer identifier => means we've found a new customer |
79
|
|
|
if ($this->isLastIdentifier(array($email, $website))) { |
80
|
|
|
return; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
// delete the customer with the passed identifier |
84
|
|
|
$this->deleteCustomer( |
85
|
|
|
array( |
86
|
|
|
MemberNames::EMAIL => $email, |
87
|
|
|
MemberNames::WEBSITE_ID => $this->getStoreWebsiteIdByCode($this->getValue(ColumnKeys::WEBSITE)) |
88
|
|
|
) |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
// flush the cache to remove the deleted customer (which has previously been cached) |
92
|
|
|
$this->getCustomerBunchProcessor()->cleanUp(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Delete's the entity with the passed attributes. |
97
|
|
|
* |
98
|
|
|
* @param array $row The attributes of the entity to delete |
99
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
100
|
|
|
* |
101
|
|
|
* @return void |
102
|
|
|
*/ |
103
|
|
|
protected function deleteCustomer($row, $name = null) |
104
|
|
|
{ |
105
|
|
|
$this->getCustomerBunchProcessor()->deleteCustomer($row, $name); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Return's the store website for the passed code. |
110
|
|
|
* |
111
|
|
|
* @param string $code The code of the store website to return the ID for |
112
|
|
|
* |
113
|
|
|
* @return integer The store website ID |
114
|
|
|
* @throws \Exception Is thrown, if the store website with the requested code is not available |
115
|
|
|
*/ |
116
|
|
|
protected function getStoreWebsiteIdByCode($code) |
117
|
|
|
{ |
118
|
|
|
return $this->getSubject()->getStoreWebsiteIdByCode($code); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|