54 lines
1.9 KiB
PHP
54 lines
1.9 KiB
PHP
<?php
|
|
namespace Sodino\Models;
|
|
|
|
/**
|
|
* Upsell Model
|
|
*/
|
|
class Upsell {
|
|
public $id;
|
|
public $title;
|
|
public $trigger_type;
|
|
public $trigger_value;
|
|
public $target_product_id;
|
|
public $discount_type;
|
|
public $discount_value;
|
|
public $status;
|
|
public $priority;
|
|
public $created_at;
|
|
public $updated_at;
|
|
|
|
public function __construct($data = []) {
|
|
$this->id = isset($data['id']) ? (int) $data['id'] : null;
|
|
$this->title = $data['title'] ?? '';
|
|
$this->trigger_type = $data['trigger_type'] ?? 'product';
|
|
$this->trigger_value = isset($data['trigger_value']) ? (string) $data['trigger_value'] : '';
|
|
$this->target_product_id = isset($data['target_product_id']) ? (int) $data['target_product_id'] : 0;
|
|
$this->discount_type = $data['discount_type'] ?? 'percentage';
|
|
$this->discount_value = isset($data['discount_value']) ? floatval($data['discount_value']) : 0;
|
|
$this->status = isset($data['status']) ? (int) $data['status'] : 1;
|
|
$this->priority = isset($data['priority']) ? (int) $data['priority'] : 10;
|
|
$this->created_at = $data['created_at'] ?? null;
|
|
$this->updated_at = $data['updated_at'] ?? null;
|
|
}
|
|
|
|
public function isActive() {
|
|
return (bool) $this->status;
|
|
}
|
|
|
|
public function toArray() {
|
|
return [
|
|
'id' => $this->id,
|
|
'title' => sanitize_text_field($this->title),
|
|
'trigger_type' => sanitize_text_field($this->trigger_type),
|
|
'trigger_value' => sanitize_text_field($this->trigger_value),
|
|
'target_product_id' => $this->target_product_id,
|
|
'discount_type' => sanitize_text_field($this->discount_type),
|
|
'discount_value' => floatval($this->discount_value),
|
|
'status' => $this->status,
|
|
'priority' => $this->priority,
|
|
'created_at' => $this->created_at,
|
|
'updated_at' => $this->updated_at,
|
|
];
|
|
}
|
|
}
|