1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\Msi\Observers\ClearInventorySourceItemObserver |
5
|
|
|
* |
6
|
|
|
* PHP version 7 |
7
|
|
|
* |
8
|
|
|
* @author Tim Wagner <[email protected]> |
9
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
10
|
|
|
* @license https://opensource.org/licenses/MIT |
11
|
|
|
* @link https://github.com/techdivision/import-product-msi |
12
|
|
|
* @link http://www.techdivision.com |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace TechDivision\Import\Product\Msi\Observers; |
16
|
|
|
|
17
|
|
|
use TechDivision\Import\Product\Msi\Utils\ColumnKeys; |
18
|
|
|
use TechDivision\Import\Product\Msi\Services\MsiBunchProcessorInterface; |
19
|
|
|
use TechDivision\Import\Product\Msi\Utils\MemberNames; |
20
|
|
|
use TechDivision\Import\Product\Msi\Utils\SqlStatementKeys; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Observer that removes the MSI product sourch item with the SKU/Source Code found in the CSV file. |
24
|
|
|
* |
25
|
|
|
* @author Tim Wagner <[email protected]> |
26
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
27
|
|
|
* @license https://opensource.org/licenses/MIT |
28
|
|
|
* @link https://github.com/techdivision/import-product-msi |
29
|
|
|
* @link http://www.techdivision.com |
30
|
|
|
*/ |
31
|
|
|
class ClearInventorySourceItemObserver extends AbstractMsiImportObserver |
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The MSI bunch processor instance. |
36
|
|
|
* |
37
|
|
|
* @var \TechDivision\Import\Product\Msi\Services\MsiBunchProcessorInterface |
38
|
|
|
*/ |
39
|
|
|
protected $msiBunchProcessor; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Initialize the observer with the passed MSI bunch processor instance. |
43
|
|
|
* |
44
|
|
|
* @param \TechDivision\Import\Product\Msi\Services\MsiBunchProcessorInterface $msiBunchProcessor The MSI bunch processor instance |
45
|
|
|
*/ |
46
|
|
|
public function __construct(MsiBunchProcessorInterface $msiBunchProcessor) |
47
|
|
|
{ |
48
|
|
|
$this->msiBunchProcessor = $msiBunchProcessor; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Return's the MSI bunch processor instance. |
53
|
|
|
* |
54
|
|
|
* @return \TechDivision\Import\Product\Msi\Services\MsiBunchProcessorInterface The MSI bunch processor instance |
55
|
|
|
*/ |
56
|
|
|
protected function getMsiBunchProcessor() |
57
|
|
|
{ |
58
|
|
|
return $this->msiBunchProcessor; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Process the observer's business logic. |
63
|
|
|
* |
64
|
|
|
* @return array The processed row |
65
|
|
|
*/ |
66
|
|
|
protected function process() |
67
|
|
|
{ |
68
|
|
|
$this->deleteInventorySourceItem( |
69
|
|
|
array( |
70
|
|
|
MemberNames::SKU => $this->getValue(ColumnKeys::SKU), |
71
|
|
|
MemberNames::SOURCE_CODE => $this->getValue(ColumnKeys::SOURCE_CODE) |
72
|
|
|
), |
73
|
|
|
SqlStatementKeys::DELETE_INVENTORY_SOURCE_ITEM_BY_SKU_AND_SOURCE_CODE |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Delete's the entity with the passed attributes. |
79
|
|
|
* |
80
|
|
|
* @param array $row The attributes of the entity to delete |
81
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
82
|
|
|
* |
83
|
|
|
* @return void |
84
|
|
|
*/ |
85
|
|
|
protected function deleteInventorySourceItem($row, $name = null) |
86
|
|
|
{ |
87
|
|
|
$this->getMsiBunchProcessor()->deleteInventorySourceItem($row, $name); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|