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\ProductGroup; |
11
|
|
|
|
12
|
|
|
use Orm\Zed\ProductGroup\Persistence\SpyProductAbstractGroupQuery; |
13
|
|
|
use Orm\Zed\ProductGroup\Persistence\SpyProductGroupQuery; |
14
|
|
|
use Pyz\Zed\DataImport\Business\Model\Product\Repository\ProductRepository; |
15
|
|
|
use Spryker\Zed\DataImport\Business\Model\DataImportStep\DataImportStepInterface; |
16
|
|
|
use Spryker\Zed\DataImport\Business\Model\DataImportStep\PublishAwareStep; |
17
|
|
|
use Spryker\Zed\DataImport\Business\Model\DataSet\DataSetInterface; |
18
|
|
|
use Spryker\Zed\ProductGroup\Dependency\ProductGroupEvents; |
19
|
|
|
|
20
|
|
|
class ProductGroupWriter extends PublishAwareStep implements DataImportStepInterface |
21
|
|
|
{ |
22
|
|
|
public const BULK_SIZE = 100; |
23
|
|
|
|
24
|
|
|
public const COLUMN_ABSTRACT_SKU = 'abstract_sku'; |
25
|
|
|
|
26
|
|
|
public const COLUMN_PRODUCT_GROUP_KEY = 'group_key'; |
27
|
|
|
|
28
|
|
|
public const COLUMN_POSITION = 'position'; |
29
|
|
|
|
30
|
|
|
protected ProductRepository $productRepository; |
31
|
|
|
|
32
|
|
|
public function __construct(ProductRepository $productRepository) |
33
|
|
|
{ |
34
|
|
|
$this->productRepository = $productRepository; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function execute(DataSetInterface $dataSet): void |
38
|
|
|
{ |
39
|
|
|
$productGroupEntity = SpyProductGroupQuery::create() |
40
|
|
|
->filterByProductGroupKey($dataSet[static::COLUMN_PRODUCT_GROUP_KEY]) |
41
|
|
|
->findOneOrCreate(); |
42
|
|
|
|
43
|
|
|
$productGroupEntity->save(); |
44
|
|
|
|
45
|
|
|
$idProductAbstract = $this->productRepository->getIdProductAbstractByAbstractSku($dataSet[static::COLUMN_ABSTRACT_SKU]); |
46
|
|
|
|
47
|
|
|
$productAbstractGroup = SpyProductAbstractGroupQuery::create() |
48
|
|
|
->filterByFkProductAbstract($idProductAbstract) |
49
|
|
|
->filterByFkProductGroup($productGroupEntity->getIdProductGroup()) |
50
|
|
|
->findOneOrCreate(); |
51
|
|
|
|
52
|
|
|
$productAbstractGroup |
53
|
|
|
->setPosition($dataSet[static::COLUMN_POSITION]) |
54
|
|
|
->save(); |
55
|
|
|
|
56
|
|
|
$this->addPublishEvents(ProductGroupEvents::PRODUCT_GROUP_PUBLISH, $productAbstractGroup->getFkProductAbstract()); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|