1 | <?php |
||
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) |
|
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) |
|
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) |
|
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) |
|
155 | } |
||
156 |