1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2024 TechDivision GmbH <[email protected]> - TechDivision GmbH |
4
|
|
|
* All rights reserved |
5
|
|
|
* |
6
|
|
|
* This product includes proprietary software developed at TechDivision GmbH, Germany |
7
|
|
|
* For more information see https://www.techdivision.com |
8
|
|
|
* |
9
|
|
|
* To obtain a valid license for using this software, please contact us at |
10
|
|
|
* [email protected] |
11
|
|
|
*/ |
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace TechDivision\Import\Product\Grouped\Actions\Processors; |
15
|
|
|
|
16
|
|
|
use TechDivision\Import\Dbal\Collection\Actions\Processors\AbstractBaseProcessor; |
17
|
|
|
use TechDivision\Import\Product\Grouped\Utils\SqlStatementKeys; |
18
|
|
|
use TechDivision\Import\Product\Utils\MemberNames; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @copyright Copyright (c) 2024 TechDivision GmbH <[email protected]> - TechDivision GmbH |
22
|
|
|
* @link http://www.techdivision.com |
23
|
|
|
* @author MET <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class ProductRelationDeleteProcessor extends AbstractBaseProcessor |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Delete all relations that are not imported. |
29
|
|
|
* |
30
|
|
|
* @param array $row The row to persist |
31
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
32
|
|
|
* @param string|null $primaryKeyMemberName The primary key member name of the entity to use |
33
|
|
|
* |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
|
public function execute($row, $name = null, $primaryKeyMemberName = null): void |
37
|
|
|
{ |
38
|
|
|
// load the SKUs from the row |
39
|
|
|
$skus = $row[MemberNames::SKU]; |
40
|
|
|
|
41
|
|
|
// make sure we've an array |
42
|
|
|
if (!is_array($skus)) { |
43
|
|
|
$skus = [$skus]; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
// all SKUs that should NOT be deleted |
47
|
|
|
$vals = implode(',', $skus); |
48
|
|
|
|
49
|
|
|
// concatenate the SKUs as comma separated SQL string |
50
|
|
|
$vals = str_replace(',', "','", sprintf("'%s'", $vals)); |
51
|
|
|
|
52
|
|
|
// replace the placeholders |
53
|
|
|
$sql = str_replace( |
54
|
|
|
[':parent_id', ':skus'], |
55
|
|
|
[$row[MemberNames::PARENT_ID], $vals], |
56
|
|
|
$this->loadStatement(SqlStatementKeys::DELETE_PRODUCT_RELATION) |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$this->getConnection()->query($sql); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|