-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.php
executable file
·55 lines (45 loc) · 1.38 KB
/
helpers.php
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
<?php
use Juzaweb\Ecommerce\Contracts\CartManagerContract;
use Juzaweb\Ecommerce\Http\Resources\CartItemCollectionResource;
use Juzaweb\Ecommerce\Http\Resources\PaymentMethodCollectionResource;
use Juzaweb\Ecommerce\Models\PaymentMethod;
use Juzaweb\Ecommerce\Contracts\CartContract;
if (!function_exists('ecom_get_cart')) {
function ecom_get_cart(): array
{
/**
* @var CartContract $cart
*/
$cart = app(CartManagerContract::class)->find();
return [
'code' => $cart->getCode(),
'items' => ecom_get_cart_items($cart),
];
}
}
if (!function_exists('ecom_get_cart_items')) {
function ecom_get_cart_items(CartContract $cart = null): array
{
$cart = $cart ?: app(CartContract::class);
$items = $cart->getCollectionItems();
return (new CartItemCollectionResource($items))
->toArray(request());
}
}
if (!function_exists('ecom_get_payment_methods')) {
function ecom_get_payment_methods(): array
{
$methods = PaymentMethod::active()->get();
return (new PaymentMethodCollectionResource($methods))
->toArray(request());
}
}
if (!function_exists('ecom_price_with_unit')) {
function ecom_price_with_unit(?float $price): ?string
{
if (is_null($price)) {
return null;
}
return '$'.$price;
}
}