PluginProbe
MailerLite – WooCommerce integration / trunk
MailerLite – WooCommerce integration vtrunk
3.1.27 3.1.25 3.1.26 3.1.24 3.1.23 3.1.22 3.1.21 3.1.20 3.1.19 3.1.18 3.1.17 3.1.16 3.1.15 1.8.7 1.8.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 All 148 releases
woo-mailerlite / includes / models / WooMailerLiteProduct.php

WooMailerLiteProduct.php in MailerLite – WooCommerce integration trunk, at includes/models/WooMailerLiteProduct.php

109 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class WooMailerLiteProduct extends WooMailerLiteModel
4 {
5 use WooMailerLiteProductVariantsTrait;
6
7 protected $casts = [
8 'resource_id',
9 'name',
10 'price',
11 'description',
12 'short_description',
13 'image',
14 'category_ids',
15 'created_at',
16 'status',
17 'updated_at',
18 'url',
19 'tracked',
20 'ignored'
21 ];
22
23 protected $isResource = false;
24
25 protected $table = 'posts';
26
27 protected $format = [
28 'tracked' => 'boolean',
29 'image' => 'string',
30 'resource_id' => 'string',
31 ];
32
33 protected $removeEmpty = [
34 'description',
35 'short_description',
36 'image',
37 ];
38
39 const QUERYLIMIT = 1000;
40
41 public function __construct($attributes = [])
42 {
43 parent::__construct($attributes);
44 }
45
46 public static function tracked()
47 {
48 return self::setArgs([
49 'metaQuery' => [
50 [
51 'key' => '_woo_ml_product_tracked',
52 'value' => true,
53 ]
54 ]
55 ]);
56 }
57
58 public static function untracked()
59 {
60 return self::setArgs([
61 'metaQuery' => [
62 'relation' => 'OR', // Ensures at least one condition matches
63 [
64 'key' => '_woo_ml_product_tracked',
65 'value' => false,
66 'compare' => '=', // Looks for products where _woo_ml_product_tracked is explicitly false
67 ],
68 [
69 'key' => '_woo_ml_product_tracked',
70 'compare' => 'NOT EXISTS', // Includes products where this key is missing
71 ],
72 ]
73 ]);
74 }
75
76 public static function getTrackedProductsCount()
77 {
78 return self::tracked()->count();
79 }
80
81 public static function getUntrackedProductsCount()
82 {
83 return self::untracked()->count();
84 }
85
86 public function toArrayWithVariants()
87 {
88 return array_merge(
89 $this->toArray(),
90 ['variants' => $this->getProductVariants($this->resource_id)]
91 );
92 }
93
94 public function isDeleted()
95 {
96 if (isset($this->attributes['status']) && $this->attributes['status'] === 'trash') {
97 return true;
98 }
99
100 // If we have a resource_id, check if the post still exists
101 if (isset($this->attributes['resource_id'])) {
102 $post = get_post($this->attributes['resource_id']);
103 return !$post || $post->post_status === 'trash';
104 }
105
106 return false;
107 }
108 }
109