|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file has been created by developers from BitBag. |
|
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
|
6
|
|
|
* another great project. |
|
7
|
|
|
* You can find more information about us on https://bitbag.io and write us |
|
8
|
|
|
* an email on [email protected]. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types=1); |
|
12
|
|
|
|
|
13
|
|
|
namespace BitBag\SyliusVueStorefrontPlugin\Factory\Common; |
|
14
|
|
|
|
|
15
|
|
|
use BitBag\SyliusVueStorefrontPlugin\Factory\Common\Address\RegionViewFactoryInterface; |
|
16
|
|
|
use BitBag\SyliusVueStorefrontPlugin\View\Common\AddressView; |
|
17
|
|
|
use Sylius\Component\Core\Model\AddressInterface as SyliusAddressInterface; |
|
18
|
|
|
|
|
19
|
|
|
final class AddressViewFactory implements AddressViewFactoryInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var string */ |
|
22
|
|
|
private $addressViewClass; |
|
23
|
|
|
|
|
24
|
|
|
/** @var RegionViewFactoryInterface */ |
|
25
|
|
|
private $regionView; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct(string $addressViewClass, RegionViewFactoryInterface $regionView) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->addressViewClass = $addressViewClass; |
|
30
|
|
|
$this->regionView = $regionView; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function create(SyliusAddressInterface $syliusAddress): AddressView |
|
34
|
|
|
{ |
|
35
|
|
|
/** @var AddressView $addressView */ |
|
36
|
|
|
$addressView = new $this->addressViewClass(); |
|
37
|
|
|
$addressView->id = $syliusAddress->getId(); |
|
38
|
|
|
$addressView->region = $this->regionView->create($syliusAddress); |
|
39
|
|
|
$addressView->customer_id = $syliusAddress->getCustomer() ? $syliusAddress->getCustomer()->getId() : 0; |
|
40
|
|
|
$addressView->country_id = $syliusAddress->getCountryCode(); |
|
41
|
|
|
$addressView->street = \explode(' ', $syliusAddress->getStreet()); |
|
42
|
|
|
$addressView->postcode = $syliusAddress->getPostcode(); |
|
43
|
|
|
$addressView->city = $syliusAddress->getCity(); |
|
44
|
|
|
$addressView->firstname = $syliusAddress->getFirstName(); |
|
45
|
|
|
$addressView->lastname = $syliusAddress->getLastName(); |
|
46
|
|
|
$addressView->telephone = $syliusAddress->getPhoneNumber(); |
|
47
|
|
|
|
|
48
|
|
|
return $addressView; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|