| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Services; |
| 4 |
|
| 5 |
use FluentCart\App\Helpers\CartHelper; |
| 6 |
use FluentCart\Framework\Support\Arr; |
| 7 |
use FluentCart\Framework\Support\Collection; |
| 8 |
|
| 9 |
class CheckoutService |
| 10 |
{ |
| 11 |
public array $onetime = []; |
| 12 |
public array $physicalItems = []; |
| 13 |
public array $digitalItems = []; |
| 14 |
public array $subscriptions = []; |
| 15 |
|
| 16 |
|
| 17 |
public int $count = 0; |
| 18 |
|
| 19 |
public function __construct($items = []) |
| 20 |
{ |
| 21 |
if ((is_array($items) || $items instanceof Collection)) { |
| 22 |
$this->count = is_array($items) ? count($items) : $items->count(); |
| 23 |
foreach ($items as $key => $item) { |
| 24 |
$paymentType = Arr::get($item, 'other_info.payment_type'); |
| 25 |
if ($paymentType === 'subscription') { |
| 26 |
$this->subscriptions[$key] = $item; |
| 27 |
} else { |
| 28 |
$this->onetime[$key] = $item; |
| 29 |
} |
| 30 |
|
| 31 |
$isPhysical = Arr::get($item, 'fulfillment_type') === 'physical'; |
| 32 |
if ($isPhysical) { |
| 33 |
$this->physicalItems[$key] = $item; |
| 34 |
} else { |
| 35 |
$this->digitalItems[$key] = $item; |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
public function isAllPhysical(): bool |
| 42 |
{ |
| 43 |
return $this->count === count($this->physicalItems); |
| 44 |
} |
| 45 |
|
| 46 |
public function isAllDigital(): bool |
| 47 |
{ |
| 48 |
return $this->count === count($this->digitalItems); |
| 49 |
} |
| 50 |
|
| 51 |
public function hasDigitalProduct(): bool |
| 52 |
{ |
| 53 |
return count($this->digitalItems) > 0; |
| 54 |
} |
| 55 |
|
| 56 |
public function hasPhysicalProduct(): bool |
| 57 |
{ |
| 58 |
return count($this->physicalItems) > 0; |
| 59 |
} |
| 60 |
} |
| 61 |
|