PluginProbe
MailerLite – WooCommerce integration / 3.1.17
MailerLite – WooCommerce integration v3.1.17
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 3.1.17, at includes/models/WooMailerLiteProduct.php

99 lines 2.3 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 protected $casts = [
6 'resource_id',
7 'name',
8 'price',
9 'description',
10 'short_description',
11 'image',
12 'category_ids',
13 'created_at',
14 'status',
15 'updated_at',
16 'url',
17 'tracked',
18 'ignored'
19 ];
20
21 protected $isResource = false;
22
23 protected $table = 'posts';
24
25 protected $format = [
26 'tracked' => 'boolean',
27 'image' => 'string',
28 'resource_id' => 'string',
29 ];
30
31 protected $removeEmpty = [
32 'description',
33 'short_description',
34 'image',
35 ];
36
37 const QUERYLIMIT = 1000;
38
39 public function __construct($attributes = [])
40 {
41 parent::__construct($attributes);
42 }
43
44 public static function tracked()
45 {
46 return self::setArgs([
47 'metaQuery' => [
48 [
49 'key' => '_woo_ml_product_tracked',
50 'value' => true,
51 ]
52 ]
53 ]);
54 }
55
56 public static function untracked()
57 {
58 return self::setArgs([
59 'metaQuery' => [
60 'relation' => 'OR', // Ensures at least one condition matches
61 [
62 'key' => '_woo_ml_product_tracked',
63 'value' => false,
64 'compare' => '=', // Looks for products where _woo_ml_product_tracked is explicitly false
65 ],
66 [
67 'key' => '_woo_ml_product_tracked',
68 'compare' => 'NOT EXISTS', // Includes products where this key is missing
69 ],
70 ]
71 ]);
72 }
73
74 public static function getTrackedProductsCount()
75 {
76 return self::tracked()->count();
77 }
78
79 public static function getUntrackedProductsCount()
80 {
81 return self::untracked()->count();
82 }
83
84 public function isDeleted()
85 {
86 if (isset($this->attributes['status']) && $this->attributes['status'] === 'trash') {
87 return true;
88 }
89
90 // If we have a resource_id, check if the post still exists
91 if (isset($this->attributes['resource_id'])) {
92 $post = get_post($this->attributes['resource_id']);
93 return !$post || $post->post_status === 'trash';
94 }
95
96 return false;
97 }
98 }
99