|
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\User\OrderHistory; |
|
14
|
|
|
|
|
15
|
|
|
use BitBag\SyliusVueStorefrontPlugin\Factory\Cart\CartItemViewFactory; |
|
16
|
|
|
use BitBag\SyliusVueStorefrontPlugin\View\User\OrderHistory\ShippingAssignmentView; |
|
17
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
18
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
|
19
|
|
|
|
|
20
|
|
|
final class ShippingAssignmentViewFactory implements ShippingAssignmentViewFactoryInteface |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var string */ |
|
23
|
|
|
private $shippingAssignmentViewClass; |
|
24
|
|
|
|
|
25
|
|
|
/** @var ShippingViewFactoryInterface */ |
|
26
|
|
|
private $shippingViewFactory; |
|
27
|
|
|
|
|
28
|
|
|
/** @var CartItemViewFactory */ |
|
29
|
|
|
private $cartItemViewFactory; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct( |
|
32
|
|
|
string $shippingAssignmentViewClass, |
|
33
|
|
|
ShippingViewFactoryInterface $shippingViewFactory, |
|
34
|
|
|
CartItemViewFactory $cartItemViewFactory |
|
35
|
|
|
) { |
|
36
|
|
|
$this->shippingAssignmentViewClass = $shippingAssignmentViewClass; |
|
37
|
|
|
$this->shippingViewFactory = $shippingViewFactory; |
|
38
|
|
|
$this->cartItemViewFactory = $cartItemViewFactory; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function create(OrderInterface $syliusOrder): ShippingAssignmentView |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->createFromOrder($syliusOrder); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function createList(array $syliusOrders): array |
|
47
|
|
|
{ |
|
48
|
|
|
$ordersList = []; |
|
49
|
|
|
|
|
50
|
|
|
foreach ($syliusOrders as $syliusOrder) { |
|
51
|
|
|
$ordersList[] = $this->createFromOrder($syliusOrder); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return $ordersList; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
private function createFromOrder(OrderInterface $syliusOrder): ShippingAssignmentView |
|
58
|
|
|
{ |
|
59
|
|
|
/** @var ShippingAssignmentView $shippingAssignmentView */ |
|
60
|
|
|
$shippingAssignmentView = new $this->shippingAssignmentViewClass(); |
|
61
|
|
|
$shippingAssignmentView->shipping = $this->shippingViewFactory->create($syliusOrder); |
|
62
|
|
|
|
|
63
|
|
|
if ($syliusOrder->getItems()) { |
|
64
|
|
|
$shippingAssignmentView->items = $this->cartItemViewFactory->createList($syliusOrder->getItems()); |
|
65
|
|
|
} else { |
|
66
|
|
|
$shippingAssignmentView->items = $this->cartItemViewFactory->createList(new ArrayCollection()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return $shippingAssignmentView; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|