1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Customer\Address\Observers\CleanUpObserver |
5
|
|
|
* |
6
|
|
|
* PHP version 7 |
7
|
|
|
* |
8
|
|
|
* @author Tim Wagner <[email protected]> |
9
|
|
|
* @copyright 2018 TechDivision GmbH <[email protected]> |
10
|
|
|
* @license https://opensource.org/licenses/MIT |
11
|
|
|
* @link https://github.com/techdivision/import-product |
12
|
|
|
* @link http://www.techdivision.com |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace TechDivision\Import\Customer\Address\Observers; |
16
|
|
|
|
17
|
|
|
use TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface; |
18
|
|
|
use TechDivision\Import\Customer\Address\Utils\ColumnKeys; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* An observer implementation that handles the process to import customer address bunches. |
22
|
|
|
* |
23
|
|
|
* @author Tim Wagner <[email protected]> |
24
|
|
|
* @copyright 2018 TechDivision GmbH <[email protected]> |
25
|
|
|
* @license https://opensource.org/licenses/MIT |
26
|
|
|
* @link https://github.com/techdivision/import-product |
27
|
|
|
* @link http://www.techdivision.com |
28
|
|
|
*/ |
29
|
|
|
class CleanUpObserver extends AbstractCustomerAddressImportObserver |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The customer address bunch processor instance. |
34
|
|
|
* |
35
|
|
|
* @var \TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface |
36
|
|
|
*/ |
37
|
|
|
protected $customerAddressBunchProcessor; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Initialize the observer with the passed customer bunch processor instance. |
41
|
|
|
* |
42
|
|
|
* @param \TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface $customerAddressBunchProcessor The customer address bunch processor instance |
43
|
|
|
*/ |
44
|
|
|
public function __construct(CustomerAddressBunchProcessorInterface $customerAddressBunchProcessor) |
45
|
|
|
{ |
46
|
|
|
$this->customerAddressBunchProcessor = $customerAddressBunchProcessor; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Return's the customer address bunch processor instance. |
51
|
|
|
* |
52
|
|
|
* @return \TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface The customer address bunch processor instance |
53
|
|
|
*/ |
54
|
|
|
protected function getCustomerAddressBunchProcessor() |
55
|
|
|
{ |
56
|
|
|
return $this->customerAddressBunchProcessor; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Process the observer's business logic. |
61
|
|
|
* |
62
|
|
|
* @return array The processed row |
63
|
|
|
*/ |
64
|
|
|
protected function process() |
65
|
|
|
{ |
66
|
|
|
|
67
|
|
|
// clean-up the repositories etc. to free memory |
68
|
|
|
$this->getCustomerAddressBunchProcessor()->cleanUp(); |
69
|
|
|
|
70
|
|
|
// temporary persist the last customer address entity ID |
71
|
|
|
$this->setLastEntityId($this->getValue(ColumnKeys::ENTITY_ID)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Add the passed mail address/website code => entity ID mapping. |
76
|
|
|
* |
77
|
|
|
* @param string $email The mail address of the customer |
78
|
|
|
* @param string $website The website code the customer is bound to |
79
|
|
|
* |
80
|
|
|
* @return void |
81
|
|
|
*/ |
82
|
|
|
protected function addCustomerIdentifierEntityIdMapping($email, $website) |
83
|
|
|
{ |
84
|
|
|
$this->getSubject()->addCustomerIdentifierEntityIdMapping($email, $website); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Set's the ID of the customer address that has been created recently. |
89
|
|
|
* |
90
|
|
|
* @param string $lastEntityId The entity ID |
91
|
|
|
* |
92
|
|
|
* @return void |
93
|
|
|
*/ |
94
|
|
|
protected function setLastEntityId($lastEntityId) |
95
|
|
|
{ |
96
|
|
|
$this->getSubject()->setLastEntityId($lastEntityId); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|