1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Customer\Address\Observers\ClearCustomerAddressObserver |
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-address |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Customer\Address\Observers; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Customer\Address\Utils\ColumnKeys; |
24
|
|
|
use TechDivision\Import\Customer\Address\Utils\MemberNames; |
25
|
|
|
use TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Observer that removes the customer address 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-address |
34
|
|
|
* @link http://www.techdivision.com |
35
|
|
|
*/ |
36
|
|
|
class ClearCustomerAddressObserver extends AbstractCustomerAddressImportObserver |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The customer address bunch processor instance. |
41
|
|
|
* |
42
|
|
|
* @var \TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface |
43
|
|
|
*/ |
44
|
|
|
protected $customerAddressBunchProcessor; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Initialize the observer with the passed customer bunch processor instance. |
48
|
|
|
* |
49
|
|
|
* @param \TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface $customerAddressBunchProcessor The customer address bunch processor instance |
50
|
|
|
*/ |
51
|
|
|
public function __construct(CustomerAddressBunchProcessorInterface $customerAddressBunchProcessor) |
52
|
|
|
{ |
53
|
|
|
$this->customerAddressBunchProcessor = $customerAddressBunchProcessor; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Return's the customer address bunch processor instance. |
58
|
|
|
* |
59
|
|
|
* @return \TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface The customer address bunch processor instance |
60
|
|
|
*/ |
61
|
|
|
protected function getCustomerAddressBunchProcessor() |
62
|
|
|
{ |
63
|
|
|
return $this->customerAddressBunchProcessor; |
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 the entity ID |
75
|
|
|
; |
76
|
|
|
|
77
|
|
|
// query whether or not, we've found a new entity ID => means we've found a new customer address |
78
|
|
|
if ($this->isLastEntityId($entityId = $this->getValue(ColumnKeys::ENTITY_ID))) { |
79
|
|
|
return; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
// delete the customer address with the passed entity ID |
83
|
|
|
$this->deleteCustomerAddress(array(MemberNames::ENTITY_ID => $entityId)); |
84
|
|
|
|
85
|
|
|
// flush the cache to remove the deleted customer address (which has previously been cached) |
86
|
|
|
$this->getCustomerAddressBunchProcessor()->cleanUp(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Delete's the entity with the passed attributes. |
91
|
|
|
* |
92
|
|
|
* @param array $row The attributes of the entity to delete |
93
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
94
|
|
|
* |
95
|
|
|
* @return void |
96
|
|
|
*/ |
97
|
|
|
protected function deleteCustomerAddress($row, $name = null) |
98
|
|
|
{ |
99
|
|
|
$this->getCustomerAddressBunchProcessor()->deleteCustomerAddress($row, $name); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|