|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Product\Magic360\Observers\ClearMagic360Observer |
|
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
|
|
|
* @author Bernhard Wick <[email protected]> |
|
16
|
|
|
* @copyright 2017 TechDivision GmbH <[email protected]> |
|
17
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
18
|
|
|
* @link https://github.com/techdivision/import-product-magic360 |
|
19
|
|
|
* @link http://www.techdivision.com |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace TechDivision\Import\Product\Magic360\Observers; |
|
23
|
|
|
|
|
24
|
|
|
use TechDivision\Import\Product\Magic360\Utils\ColumnKeys; |
|
25
|
|
|
use TechDivision\Import\Product\Magic360\Utils\SqlStatements; |
|
26
|
|
|
use TechDivision\Import\Product\Magic360\Services\ProductMagic360ProcessorInterface; |
|
27
|
|
|
use TechDivision\Import\Product\Observers\AbstractProductImportObserver; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Observer that removes the product with the SKU found in the CSV file. |
|
31
|
|
|
* |
|
32
|
|
|
* @author Tim Wagner <[email protected]> |
|
33
|
|
|
* @author Bernhard Wick <[email protected]> |
|
34
|
|
|
* @copyright 2017 TechDivision GmbH <[email protected]> |
|
35
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
36
|
|
|
* @link https://github.com/techdivision/import-product-magic360 |
|
37
|
|
|
* @link http://www.techdivision.com |
|
38
|
|
|
*/ |
|
39
|
|
|
class ClearMagic360Observer extends AbstractProductImportObserver |
|
40
|
|
|
{ |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* The product magic360 processor instance. |
|
44
|
|
|
* |
|
45
|
|
|
* @var \TechDivision\Import\Product\Services\ProductBunchProcessorInterface |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $productMagic360Processor; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Initialize the observer with the passed product magic360 processor instance. |
|
51
|
|
|
* |
|
52
|
|
|
* @param \TechDivision\Import\Product\Magic360\Services\ProductMagic360ProcessorInterface $productMagic360Processor The product magic360 processor instance |
|
53
|
|
|
*/ |
|
54
|
|
|
public function __construct(ProductMagic360ProcessorInterface $productMagic360Processor) |
|
55
|
|
|
{ |
|
56
|
|
|
$this->productMagic360Processor = $productMagic360Processor; |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Return's the product magic360 processor instance. |
|
61
|
|
|
* |
|
62
|
|
|
* @return \TechDivision\Import\Product\Magic360\Services\ProductMagic360ProcessorInterface The product magic360 processor instance |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function getProductMagic360Processor() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->productMagic360Processor; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Process the observer's business logic. |
|
71
|
|
|
* |
|
72
|
|
|
* @return array The processed row |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function process() |
|
75
|
|
|
{ |
|
76
|
|
|
|
|
77
|
|
|
// query whether or not, we've found a new SKU => means we've found a new product |
|
78
|
|
|
if ($this->isLastSku($sku = $this->getValue(ColumnKeys::SKU))) { |
|
79
|
|
|
return; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
// load the subject |
|
83
|
|
|
$subject = $this->getSubject(); |
|
84
|
|
|
|
|
85
|
|
|
try { |
|
86
|
|
|
// get the mapping to product ID based on the preload entity IDs |
|
87
|
|
|
$productId = $subject->mapSkuToPreloadEntityId($sku); |
|
88
|
|
|
|
|
89
|
|
|
// FIRST delete the data related with the product with the passed SKU |
|
90
|
|
|
$this->deleteMagic360Gallery(array(ColumnKeys::PRODUCT_ID => $productId), SqlStatements::DELETE_MAGIC360_GALLERY); |
|
91
|
|
|
$this->deleteMagic360Columns(array(ColumnKeys::PRODUCT_ID => $productId), SqlStatements::DELETE_MAGIC360_COLUMNS); |
|
92
|
|
|
|
|
93
|
|
|
} catch (\Exception $e) { |
|
94
|
|
|
// query whether or not debug mode has been enabled |
|
95
|
|
|
if ($subject->isDebugMode()) { |
|
96
|
|
|
$subject->getSystemLogger()->warning($subject->appendExceptionSuffix($e->getMessage())); |
|
97
|
|
|
} else { |
|
98
|
|
|
throw $e; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Deletes the gallery entity with the passed attributes. |
|
105
|
|
|
* |
|
106
|
|
|
* @param array $row The attributes of the entity to delete |
|
107
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
|
108
|
|
|
* |
|
109
|
|
|
* @return void |
|
110
|
|
|
*/ |
|
111
|
|
|
public function deleteMagic360Gallery($row, $name = null) |
|
112
|
|
|
{ |
|
113
|
|
|
$this->getProductMagic360Processor()->deleteMagic360Gallery($row, $name); |
|
|
|
|
|
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Deletes the column entity with the passed attributes. |
|
118
|
|
|
* |
|
119
|
|
|
* @param array $row The attributes of the entity to delete |
|
120
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
|
121
|
|
|
* |
|
122
|
|
|
* @return void |
|
123
|
|
|
*/ |
|
124
|
|
|
public function deleteMagic360Columns($row, $name = null) |
|
125
|
|
|
{ |
|
126
|
|
|
$this->getProductMagic360Processor()->deleteMagic360Columns($row, $name); |
|
|
|
|
|
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..