Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* Copyright (c) 2020 TechDivision GmbH
* All rights reserved
*
* This product includes proprietary software developed at TechDivision GmbH, Germany
* For more information see http://www.techdivision.com/
*
* To obtain a valid license for using this software please contact us at
* license@techdivision.com
*/
declare(strict_types=1);
namespace TechDivision\CsvSourceTransformationExample\Model\Mapping;
use Magento\Framework\Exception\LocalizedException;
use Magento\Store\Model\StoreManagerInterface;
use TechDivision\CsvSourceTransformationExample\Api\MappingInterface;
/**
* @copyright Copyright (c) 2020 TechDivision GmbH (http://www.techdivision.com)
* @link http://www.techdivision.com/
* @author Vadim Justus <v.justus@techdivision.com>
*/
class WebsiteCode implements MappingInterface
{
/**
* @var StoreManagerInterface
*/
private $storeManager;
/**
* @var string
*/
private $defaultWebsiteCode;
/**
* @param StoreManagerInterface $storeManager
*/
public function __construct(StoreManagerInterface $storeManager)
{
$this->storeManager = $storeManager;
}
/**
* @inheritDoc
*/
public function header(array $row): array
{
return $row;
}
/**
* @return string
* @throws LocalizedException
*/
private function getDefaultWebsiteCode(): string
{
if ($this->defaultWebsiteCode === null) {
$defaultWebsiteId = $this->storeManager->getDefaultStoreView()->getWebsiteId();
$this->defaultWebsiteCode = (string)$this->storeManager->getWebsite($defaultWebsiteId)->getCode();
}
return $this->defaultWebsiteCode;
}
/**
* @inheritDoc
* @throws LocalizedException
*/
public function row(array $row): array
{
$value = $row['product_websites'];
if ($value === '_DEFAULT_') {
$row['product_websites'] = $this->getDefaultWebsiteCode();
}
return $row;
}
}