|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Product\Observers\ClearProductObserver |
|
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 2016 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-product |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Observers; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Product\Utils\ColumnKeys; |
|
24
|
|
|
use TechDivision\Import\Product\Utils\SqlStatementKeys; |
|
25
|
|
|
use TechDivision\Import\Product\Services\ProductBunchProcessorInterface; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Observer that removes the product with the SKU found in the CSV file. |
|
29
|
|
|
* |
|
30
|
|
|
* @author Tim Wagner <[email protected]> |
|
31
|
|
|
* @copyright 2016 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-product |
|
34
|
|
|
* @link http://www.techdivision.com |
|
35
|
|
|
*/ |
|
36
|
|
|
class ClearProductObserver extends AbstractProductImportObserver |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The product bunch processor instance. |
|
41
|
|
|
* |
|
42
|
|
|
* @var \TechDivision\Import\Product\Services\ProductBunchProcessorInterface |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $productBunchProcessor; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Initialize the observer with the passed product bunch processor instance. |
|
48
|
|
|
* |
|
49
|
|
|
* @param \TechDivision\Import\Product\Services\ProductBunchProcessorInterface $productBunchProcessor The product bunch processor instance |
|
50
|
|
|
*/ |
|
51
|
2 |
|
public function __construct(ProductBunchProcessorInterface $productBunchProcessor) |
|
52
|
|
|
{ |
|
53
|
2 |
|
$this->productBunchProcessor = $productBunchProcessor; |
|
54
|
2 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Return's the product bunch processor instance. |
|
58
|
|
|
* |
|
59
|
|
|
* @return \TechDivision\Import\Product\Services\ProductBunchProcessorInterface The product bunch processor instance |
|
60
|
|
|
*/ |
|
61
|
1 |
|
protected function getProductBunchProcessor() |
|
62
|
|
|
{ |
|
63
|
1 |
|
return $this->productBunchProcessor; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Process the observer's business logic. |
|
68
|
|
|
* |
|
69
|
|
|
* @return array The processed row |
|
70
|
|
|
*/ |
|
71
|
2 |
|
protected function process() |
|
72
|
|
|
{ |
|
73
|
|
|
|
|
74
|
|
|
// query whether or not, we've found a new SKU => means we've found a new product |
|
75
|
2 |
|
if ($this->isLastSku($sku = $this->getValue(ColumnKeys::SKU))) { |
|
76
|
1 |
|
return; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
// FIRST delete the data related with the product with the passed SKU |
|
80
|
1 |
|
$this->deleteStockItem(array(ColumnKeys::SKU => $sku), SqlStatementKeys::DELETE_STOCK_ITEM_BY_SKU); |
|
81
|
1 |
|
$this->deleteProductWebsite(array(ColumnKeys::SKU => $sku), SqlStatementKeys::DELETE_PRODUCT_WEBSITE_BY_SKU); |
|
82
|
1 |
|
$this->deleteCategoryProduct(array(ColumnKeys::SKU => $sku), SqlStatementKeys::DELETE_CATEGORY_PRODUCT_BY_SKU); |
|
83
|
|
|
|
|
84
|
|
|
// delete the product with the passed SKU |
|
85
|
1 |
|
$this->deleteProduct(array(ColumnKeys::SKU => $sku)); |
|
86
|
|
|
|
|
87
|
|
|
// flush the cache to remove the deleted product (which has previously been cached) |
|
88
|
1 |
|
$this->getProductBunchProcessor()->cleanUp(); |
|
89
|
1 |
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Delete's the entity with the passed attributes. |
|
93
|
|
|
* |
|
94
|
|
|
* @param array $row The attributes of the entity to delete |
|
95
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
|
96
|
|
|
* |
|
97
|
|
|
* @return void |
|
98
|
|
|
*/ |
|
99
|
1 |
|
protected function deleteProduct($row, $name = null) |
|
100
|
|
|
{ |
|
101
|
1 |
|
$this->getProductBunchProcessor()->deleteProduct($row, $name); |
|
102
|
1 |
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Delete's the URL rewrite(s) with the passed attributes. |
|
106
|
|
|
* |
|
107
|
|
|
* @param array $row The attributes of the entity to delete |
|
108
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
|
109
|
|
|
* |
|
110
|
|
|
* @return void |
|
111
|
|
|
*/ |
|
112
|
|
|
protected function deleteUrlRewrite($row, $name = null) |
|
113
|
|
|
{ |
|
114
|
|
|
$this->getProductBunchProcessor()->deleteUrlRewrite($row, $name); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Delete's the stock item(s) with the passed attributes. |
|
119
|
|
|
* |
|
120
|
|
|
* @param array $row The attributes of the entity to delete |
|
121
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
|
122
|
|
|
* |
|
123
|
|
|
* @return void |
|
124
|
|
|
*/ |
|
125
|
1 |
|
protected function deleteStockItem($row, $name = null) |
|
126
|
|
|
{ |
|
127
|
1 |
|
$this->getProductBunchProcessor()->deleteStockItem($row, $name); |
|
128
|
1 |
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Delete's the product website relations with the passed attributes. |
|
132
|
|
|
* |
|
133
|
|
|
* @param array $row The attributes of the entity to delete |
|
134
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
|
135
|
|
|
* |
|
136
|
|
|
* @return void |
|
137
|
|
|
*/ |
|
138
|
1 |
|
protected function deleteProductWebsite($row, $name = null) |
|
139
|
|
|
{ |
|
140
|
1 |
|
$this->getProductBunchProcessor()->deleteProductWebsite($row, $name); |
|
141
|
1 |
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Delete's the category product relations with the passed attributes. |
|
145
|
|
|
* |
|
146
|
|
|
* @param array $row The attributes of the entity to delete |
|
147
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
|
148
|
|
|
* |
|
149
|
|
|
* @return void |
|
150
|
|
|
*/ |
|
151
|
1 |
|
protected function deleteCategoryProduct($row, $name = null) |
|
152
|
|
|
{ |
|
153
|
1 |
|
$this->getProductBunchProcessor()->deleteCategoryProduct($row, $name); |
|
154
|
1 |
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|