| @@ 35-75 (lines=41) @@ | ||
| 32 | * @link https://github.com/techdivision/import-product |
|
| 33 | * @link http://www.techdivision.com |
|
| 34 | */ |
|
| 35 | class ClearProductObserver extends AbstractProductImportObserver |
|
| 36 | { |
|
| 37 | ||
| 38 | /** |
|
| 39 | * Will be invoked by the action on the events the listener has been registered for. |
|
| 40 | * |
|
| 41 | * @param array $row The row to handle |
|
| 42 | * |
|
| 43 | * @return array The modified row |
|
| 44 | * @see \TechDivision\Import\Product\Observers\ImportObserverInterface::handle() |
|
| 45 | */ |
|
| 46 | public function handle(array $row) |
|
| 47 | { |
|
| 48 | ||
| 49 | // load the header information |
|
| 50 | $headers = $this->getHeaders(); |
|
| 51 | ||
| 52 | // query whether or not, we've found a new SKU => means we've found a new product |
|
| 53 | if ($this->isLastSku($sku = $row[$headers[ColumnKeys::SKU]])) { |
|
| 54 | return $row; |
|
| 55 | } |
|
| 56 | ||
| 57 | // remove the product with the passed SKU |
|
| 58 | $this->removeProduct(array($sku)); |
|
| 59 | ||
| 60 | // return the prepared row |
|
| 61 | return $row; |
|
| 62 | } |
|
| 63 | ||
| 64 | /** |
|
| 65 | * Remove's the entity with the passed attributes. |
|
| 66 | * |
|
| 67 | * @param array $row The attributes of the entity to remove |
|
| 68 | * |
|
| 69 | * @return void |
|
| 70 | */ |
|
| 71 | public function removeProduct($row) |
|
| 72 | { |
|
| 73 | $this->getSubject()->removeProduct($row); |
|
| 74 | } |
|
| 75 | } |
|
| 76 | ||
| @@ 36-77 (lines=42) @@ | ||
| 33 | * @link https://github.com/techdivision/import-product |
|
| 34 | * @link http://www.techdivision.com |
|
| 35 | */ |
|
| 36 | class ClearUrlRewriteObserver extends AbstractProductImportObserver |
|
| 37 | { |
|
| 38 | ||
| 39 | /** |
|
| 40 | * Will be invoked by the action on the events the listener has been registered for. |
|
| 41 | * |
|
| 42 | * @param array $row The row to handle |
|
| 43 | * |
|
| 44 | * @return array The modified row |
|
| 45 | * @see \TechDivision\Import\Product\Observers\ImportObserverInterface::handle() |
|
| 46 | */ |
|
| 47 | public function handle(array $row) |
|
| 48 | { |
|
| 49 | ||
| 50 | // load the header information |
|
| 51 | $headers = $this->getHeaders(); |
|
| 52 | ||
| 53 | // query whether or not, we've found a new SKU => means we've found a new product |
|
| 54 | if ($this->isLastSku($sku = $row[$headers[ColumnKeys::SKU]])) { |
|
| 55 | return $row; |
|
| 56 | } |
|
| 57 | ||
| 58 | // remove the product with the passed SKU |
|
| 59 | $this->removeUrlRewrite(array($sku), SqlStatements::REMOVE_URL_REWRITE_BY_SKU); |
|
| 60 | ||
| 61 | // return the prepared row |
|
| 62 | return $row; |
|
| 63 | } |
|
| 64 | ||
| 65 | /** |
|
| 66 | * Remove's the entity with the passed attributes. |
|
| 67 | * |
|
| 68 | * @param array $row The attributes of the entity to remove |
|
| 69 | * @param string|null $name The name of the prepared statement that has to be executed |
|
| 70 | * |
|
| 71 | * @return void |
|
| 72 | */ |
|
| 73 | public function removeUrlRewrite($row, $name = null) |
|
| 74 | { |
|
| 75 | $this->getSubject()->removeUrlRewrite($row, $name); |
|
| 76 | } |
|
| 77 | } |
|
| 78 | ||