|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Shop\Checkout; |
|
4
|
|
|
|
|
5
|
|
|
use App\Shop\Carts\Repositories\CartRepository; |
|
6
|
|
|
use App\Shop\Carts\ShoppingCart; |
|
7
|
|
|
use App\Shop\OrderDetails\OrderProduct; |
|
8
|
|
|
use App\Shop\OrderDetails\Repositories\OrderProductRepository; |
|
9
|
|
|
use App\Shop\Orders\Order; |
|
10
|
|
|
use App\Shop\Orders\Repositories\OrderRepository; |
|
11
|
|
|
|
|
12
|
|
|
class CheckoutRepository |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @param array $data |
|
16
|
|
|
* @return Order |
|
17
|
|
|
*/ |
|
18
|
|
|
public function buildCheckoutItems(array $data) : Order |
|
19
|
|
|
{ |
|
20
|
|
|
$orderRepo = new OrderRepository(new Order); |
|
21
|
|
|
$cartRepo = new CartRepository(new ShoppingCart); |
|
22
|
|
|
$orderProductRepo = new OrderProductRepository(new OrderProduct); |
|
23
|
|
|
|
|
24
|
|
|
$order = $orderRepo->create([ |
|
25
|
|
|
'reference' => $data['reference'], |
|
26
|
|
|
'courier_id' => $data['courier_id'], |
|
27
|
|
|
'customer_id' => $data['customer_id'], |
|
28
|
|
|
'address_id' => $data['address_id'], |
|
29
|
|
|
'order_status_id' => $data['order_status_id'], |
|
30
|
|
|
'payment' => $data['payment'], |
|
31
|
|
|
'discounts' => $data['discounts'], |
|
32
|
|
|
'total_products' => $data['total_products'], |
|
33
|
|
|
'total' => $data['total'], |
|
34
|
|
|
'total_paid' => $data['total_paid'], |
|
35
|
|
|
'tax' => $data['tax'] |
|
36
|
|
|
]); |
|
37
|
|
|
|
|
38
|
|
|
$orderProductRepo->buildOrderDetails($order, $cartRepo->getCartItems()); |
|
39
|
|
|
|
|
40
|
|
|
return $order; |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|