lifeboat-app /
php-sdk
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Lifeboat\Models; |
||
| 4 | |||
| 5 | use Lifeboat\Resource\ObjectResource; |
||
| 6 | use Lifeboat\Services\Orders; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Class Order |
||
| 10 | * @package Lifeboat\Models |
||
| 11 | * |
||
| 12 | * @property string $Status |
||
| 13 | * @property string $Fulfillment |
||
| 14 | * @property string|null $DiscountCode |
||
| 15 | * @property \DateTime|string|null $Created |
||
| 16 | * @property \DateTime|string|null $LastModified |
||
| 17 | * @property string $OID |
||
| 18 | * @property float $Subtotal |
||
| 19 | * @property float $Tax |
||
| 20 | * @property float $Delivery |
||
| 21 | * @property float $Handling |
||
| 22 | * @property float $Discount |
||
| 23 | * @property float $Total |
||
| 24 | * @property \DateTime|string|null $PaidOn |
||
| 25 | * @property \DateTime|string|null $DeliveredOn |
||
| 26 | * @property string $PaymentMethod |
||
| 27 | * @property string $Provider |
||
| 28 | * @property int $FulfillmentType |
||
| 29 | * @property array $Discounts |
||
| 30 | * @property string $Currency |
||
| 31 | * @property array $Products |
||
| 32 | * @property ObjectResource|null $ShipTo |
||
| 33 | * @property ObjectResource|null $BillTo |
||
| 34 | * @property array $Waypoints |
||
| 35 | * @property ObjectResource|null $Route |
||
| 36 | */ |
||
| 37 | class Order extends Model { |
||
| 38 | |||
| 39 | protected static $casting = [ |
||
| 40 | 'Created' => 'lifeboat_date_formatter', |
||
| 41 | 'LastModified' => 'lifeboat_date_formatter', |
||
| 42 | 'Subtotal' => 'floatval', |
||
| 43 | 'Tax' => 'floatval', |
||
| 44 | 'Delivery' => 'floatval', |
||
| 45 | 'Handling' => 'floatval', |
||
| 46 | 'Discount' => 'floatval', |
||
| 47 | 'Total' => 'floatval', |
||
| 48 | 'PaidOn' => 'lifeboat_date_formatter', |
||
| 49 | 'DeliveredOn' => 'lifeboat_date_formatter', |
||
| 50 | ]; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @return string |
||
| 54 | */ |
||
| 55 | public function FulfillmentType(): string |
||
| 56 | { |
||
| 57 | switch ($this->FulfillmentType) { |
||
| 58 | case Orders::FULFILLMENT_SHIP: return 'ship'; |
||
| 59 | case Orders::FULFILLMENT_DELIVER: return 'deliver'; |
||
| 60 | case Orders::FULFILLMENT_PICKUP: return 'pickup'; |
||
| 61 | } |
||
| 62 | |||
| 63 | return ''; |
||
| 64 | } |
||
| 65 | |||
| 66 | |||
| 67 | /** |
||
| 68 | * @return string |
||
| 69 | */ |
||
| 70 | public function Status(): string |
||
| 71 | { |
||
| 72 | switch ($this->Status) { |
||
| 73 | case Orders::STATUS_OPEN: return 'open'; |
||
| 74 | case Orders::STATUS_PAID: return 'paid'; |
||
| 75 | } |
||
| 76 | |||
| 77 | return ''; |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @param string $price |
||
| 82 | * @return string |
||
| 83 | */ |
||
| 84 | public function formatPrice(string $price): string |
||
| 85 | { |
||
| 86 | switch (strtolower($price)) { |
||
| 87 | case 'subtotal' : $value = $this->Subtotal; break; |
||
| 88 | case 'tax' : $value = $this->Tax; break; |
||
| 89 | case 'delivery' : $value = $this->Delivery; break; |
||
| 90 | case 'handling' : $value = $this->Handling; break; |
||
| 91 | case 'discount' : $value = $this->Discount; break; |
||
| 92 | case 'total' : $value = $this->Total; break; |
||
| 93 | default: return ''; |
||
| 94 | } |
||
| 95 | |||
| 96 | return ($value !== 0) ? number_format($value, 2) . $this->Currency : '-'; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 97 | } |
||
| 98 | } |
||
| 99 |