1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file was created by developers working at BitBag |
5
|
|
|
* Do you need more information about us and what we do? Visit our https://bitbag.io website! |
6
|
|
|
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
declare(strict_types=1); |
10
|
|
|
|
11
|
|
|
namespace BitBag\SyliusShippingExportPlugin\Entity; |
12
|
|
|
|
13
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
14
|
|
|
use Doctrine\Common\Collections\Collection; |
15
|
|
|
use Sylius\Component\Core\Model\ShippingMethodInterface; |
16
|
|
|
use Webmozart\Assert\Assert; |
17
|
|
|
|
18
|
|
|
class ShippingGateway implements ShippingGatewayInterface |
19
|
|
|
{ |
20
|
|
|
/** @var int */ |
21
|
|
|
protected $id; |
22
|
|
|
|
23
|
|
|
/** @var string|null */ |
24
|
|
|
protected $code; |
25
|
|
|
|
26
|
|
|
/** @var string|null */ |
27
|
|
|
protected $name; |
28
|
|
|
|
29
|
|
|
/** @var array */ |
30
|
|
|
protected $config = []; |
31
|
|
|
|
32
|
|
|
/** @var Collection<int, ShippingMethodInterface>|ShippingMethodInterface[] */ |
33
|
|
|
protected $shippingMethods; |
34
|
|
|
|
35
|
|
|
/** @var Collection<int, ShippingExportInterface>|ShippingExportInterface[] */ |
36
|
|
|
protected $shippingExports; |
37
|
|
|
|
38
|
|
|
public function __construct() |
39
|
|
|
{ |
40
|
|
|
$this->shippingExports = new ArrayCollection(); |
41
|
|
|
$this->shippingMethods = new ArrayCollection(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getId(): ?int |
45
|
|
|
{ |
46
|
|
|
return $this->id; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function setCode(?string $code): void |
50
|
|
|
{ |
51
|
|
|
$this->code = $code; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getCode(): ?string |
55
|
|
|
{ |
56
|
|
|
return $this->code; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function setName(?string $name): void |
60
|
|
|
{ |
61
|
|
|
$this->name = $name; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getName(): ?string |
65
|
|
|
{ |
66
|
|
|
return $this->name; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function setConfig(array $config): void |
70
|
|
|
{ |
71
|
|
|
$this->config = $config; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getConfig(): array |
75
|
|
|
{ |
76
|
|
|
return $this->config; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getConfigValue(string $key) |
80
|
|
|
{ |
81
|
|
|
Assert::keyExists($this->config, $key, sprintf( |
82
|
|
|
'Shipping gateway config named %s does not exist.', |
83
|
|
|
$key |
84
|
|
|
)); |
85
|
|
|
|
86
|
|
|
return $this->config[$key]; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getShippingMethods(): ?Collection |
90
|
|
|
{ |
91
|
|
|
return $this->shippingMethods; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function addShippingMethod(ShippingMethodInterface $shippingMethod): void |
95
|
|
|
{ |
96
|
|
|
if (!$this->hasShippingMethod($shippingMethod)) { |
97
|
|
|
$this->shippingMethods->add($shippingMethod); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function removeShippingMethod(ShippingMethodInterface $shippingMethod): void |
102
|
|
|
{ |
103
|
|
|
if ($this->hasShippingMethod($shippingMethod)) { |
104
|
|
|
$this->shippingMethods->removeElement($shippingMethod); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function hasShippingMethod(ShippingMethodInterface $shippingMethod): bool |
109
|
|
|
{ |
110
|
|
|
return $this->shippingMethods->contains($shippingMethod); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function getShippingExports(): ?Collection |
114
|
|
|
{ |
115
|
|
|
return $this->shippingExports; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function addShippingExport(ShippingExportInterface $shippingExport): void |
119
|
|
|
{ |
120
|
|
|
if (!$this->hasShippingExport($shippingExport)) { |
121
|
|
|
$this->shippingExports->add($shippingExport); |
122
|
|
|
$shippingExport->setShippingGateway($this); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function removeShippingExport(ShippingExportInterface $shippingExport): void |
127
|
|
|
{ |
128
|
|
|
if ($this->hasShippingExport($shippingExport)) { |
129
|
|
|
$this->shippingExports->removeElement($shippingExport); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function hasShippingExport(ShippingExportInterface $shippingExport): bool |
134
|
|
|
{ |
135
|
|
|
return $this->shippingExports->contains($shippingExport); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|