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\Navigation; |
11
|
|
|
|
12
|
|
|
use Orm\Zed\Navigation\Persistence\SpyNavigation; |
13
|
|
|
use Orm\Zed\Navigation\Persistence\SpyNavigationQuery; |
14
|
|
|
use Spryker\Zed\DataImport\Business\Model\DataImportStep\DataImportStepInterface; |
15
|
|
|
use Spryker\Zed\DataImport\Business\Model\DataImportStep\PublishAwareStep; |
16
|
|
|
use Spryker\Zed\DataImport\Business\Model\DataSet\DataSetInterface; |
17
|
|
|
use Spryker\Zed\Navigation\Dependency\NavigationEvents; |
18
|
|
|
|
19
|
|
|
class NavigationWriterStep extends PublishAwareStep implements DataImportStepInterface |
20
|
|
|
{ |
21
|
|
|
public const BULK_SIZE = 100; |
22
|
|
|
|
23
|
|
|
public const NAME = 'name'; |
24
|
|
|
|
25
|
|
|
public const KEY = 'key'; |
26
|
|
|
|
27
|
|
|
public const KEY_IS_ACTIVE = 'is_active'; |
28
|
|
|
|
29
|
|
|
public function execute(DataSetInterface $dataSet): void |
30
|
|
|
{ |
31
|
|
|
$navigationEntity = SpyNavigationQuery::create() |
32
|
|
|
->filterByKey($dataSet[static::KEY]) |
33
|
|
|
->findOneOrCreate(); |
34
|
|
|
|
35
|
|
|
$navigationEntity |
36
|
|
|
->setName($this->getName($navigationEntity, $dataSet)) |
37
|
|
|
->setIsActive((bool)$dataSet[static::KEY_IS_ACTIVE]) |
38
|
|
|
->save(); |
39
|
|
|
|
40
|
|
|
$this->addPublishEvents(NavigationEvents::NAVIGATION_KEY_PUBLISH, $navigationEntity->getIdNavigation()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function getName(SpyNavigation $navigationEntity, DataSetInterface $dataSet): string |
44
|
|
|
{ |
45
|
|
|
if (isset($dataSet[static::NAME]) && !empty($dataSet[static::NAME])) { |
46
|
|
|
return $dataSet[static::NAME]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $navigationEntity->getName(); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|