PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Services / CheckoutService.php

CheckoutService.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Services/CheckoutService.php

61 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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