AbandonedCheckout.php
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Models; |
| 4 | |
| 5 | use SureCart\Models\Traits\HasCheckout; |
| 6 | use SureCart\Models\Traits\HasCustomer; |
| 7 | use SureCart\Models\Traits\HasDates; |
| 8 | use SureCart\Models\Traits\HasPromotion; |
| 9 | use SureCart\Support\TimeDate; |
| 10 | |
| 11 | /** |
| 12 | * Order model |
| 13 | */ |
| 14 | class AbandonedCheckout extends Model { |
| 15 | use HasCustomer; |
| 16 | use HasCheckout; |
| 17 | use HasDates; |
| 18 | use HasPromotion; |
| 19 | |
| 20 | /** |
| 21 | * Rest API endpoint |
| 22 | * |
| 23 | * @var string |
| 24 | */ |
| 25 | protected $endpoint = 'abandoned_checkouts'; |
| 26 | |
| 27 | /** |
| 28 | * Object name |
| 29 | * |
| 30 | * @var string |
| 31 | */ |
| 32 | protected $object_name = 'abandoned_checkout'; |
| 33 | |
| 34 | /** |
| 35 | * Set the latest checkout session attribute |
| 36 | * |
| 37 | * @param array $value Checkout session properties. |
| 38 | * @return void |
| 39 | */ |
| 40 | protected function setLatestRecoverableCheckoutAttribute( $value ) { |
| 41 | $this->setRelation( 'recovered_checkout', $value, Checkout::class ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Get stats for the order. |
| 46 | * |
| 47 | * @param array $args Array of arguments for the statistics. |
| 48 | * |
| 49 | * @return \SureCart\Models\Statistic; |
| 50 | */ |
| 51 | protected function stats( $args = [] ) { |
| 52 | $stat = new Statistic(); |
| 53 | return $stat->where( $args )->find( 'abandoned_checkouts' ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Get the notifications scheduled at date and time attribute. |
| 58 | * |
| 59 | * @return string |
| 60 | */ |
| 61 | public function getNotificationsScheduledAtDateTimeAttribute() { |
| 62 | return array_map( |
| 63 | function ( $scheduled_at ) { |
| 64 | return TimeDate::formatDateAndTime( $scheduled_at ); |
| 65 | }, |
| 66 | $this->notifications_scheduled_at ?? [] |
| 67 | ); |
| 68 | } |
| 69 | } |
| 70 |