|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Spryker Commerce OS. |
|
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types = 1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Pyz\Zed\DataImport\Business\Model\ProductAttributeKey; |
|
11
|
|
|
|
|
12
|
|
|
use Orm\Zed\Product\Persistence\Map\SpyProductAttributeKeyTableMap; |
|
13
|
|
|
use Orm\Zed\Product\Persistence\SpyProductAttributeKeyQuery; |
|
14
|
|
|
use Propel\Runtime\Formatter\SimpleArrayFormatter; |
|
15
|
|
|
use Spryker\Zed\DataImport\Business\Model\DataImportStep\DataImportStepInterface; |
|
16
|
|
|
use Spryker\Zed\DataImport\Business\Model\DataSet\DataSetInterface; |
|
17
|
|
|
|
|
18
|
|
|
class AddProductAttributeKeysStep implements DataImportStepInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
public const KEY_TARGET = 'attributeKeys'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var array<string, int> |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $productAttributeKeys = []; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param \Spryker\Zed\DataImport\Business\Model\DataSet\DataSetInterface $dataSet |
|
32
|
|
|
* |
|
33
|
|
|
* @return void |
|
34
|
|
|
*/ |
|
35
|
|
|
public function execute(DataSetInterface $dataSet): void |
|
36
|
|
|
{ |
|
37
|
|
|
if (!$this->productAttributeKeys) { |
|
|
|
|
|
|
38
|
|
|
$query = SpyProductAttributeKeyQuery::create() |
|
39
|
|
|
->select([ |
|
40
|
|
|
SpyProductAttributeKeyTableMap::COL_ID_PRODUCT_ATTRIBUTE_KEY, |
|
41
|
|
|
SpyProductAttributeKeyTableMap::COL_KEY, |
|
42
|
|
|
]) |
|
43
|
|
|
->setFormatter(new SimpleArrayFormatter()); |
|
44
|
|
|
|
|
45
|
|
|
/** @var array<array<string, mixed>> $productAttributeKeys */ |
|
46
|
|
|
$productAttributeKeys = $query->find(); |
|
47
|
|
|
foreach ($productAttributeKeys as $productAttributeKey) { |
|
48
|
|
|
/** @var string $key */ |
|
49
|
|
|
$key = $productAttributeKey[SpyProductAttributeKeyTableMap::COL_KEY]; |
|
50
|
|
|
$value = $productAttributeKey[SpyProductAttributeKeyTableMap::COL_ID_PRODUCT_ATTRIBUTE_KEY]; |
|
51
|
|
|
|
|
52
|
|
|
$this->productAttributeKeys[$key] = $value; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$dataSet[static::KEY_TARGET] = $this->productAttributeKeys; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.