PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.8.6
ووسلام – همگام سازی ووکامرس و باسلام v1.8.6
1.10.19 1.10.20 1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 All 53 releases
sync-basalam / includes / Admin / Product / Services / ProductQueryService.php

ProductQueryService.php in ووسلام – همگام سازی ووکامرس و باسلام 1.8.6, at includes/Admin/Product/Services/ProductQueryService.php

88 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam\Admin\Product\Services;
4
5 use SyncBasalam\Utilities\ProductMetaKey;
6
7 defined('ABSPATH') || exit;
8
9 class ProductQueryService
10 {
11 public function getCreatableProducts(array $args = []): array
12 {
13 global $wpdb;
14
15 $postsTable = $wpdb->posts;
16 $metaTable = $wpdb->postmeta;
17
18 $postsPerPage = $args['posts_per_page'] ?? 100;
19 $includeOutOfStock = $args['include_out_of_stock'] ?? false;
20 $lastId = intval($args['last_creatable_product_id'] ?? 0);
21 $productIdMetaKey = ProductMetaKey::basalamProductId();
22
23 $stockCondition = $includeOutOfStock
24 ? ""
25 : "AND stock.meta_value = 'instock'";
26
27 $query = $wpdb->prepare("
28 SELECT p.ID
29 FROM {$postsTable} AS p
30 LEFT JOIN {$metaTable} AS thumb
31 ON thumb.post_id = p.ID
32 AND thumb.meta_key = '_thumbnail_id'
33 LEFT JOIN {$metaTable} AS basalam
34 ON basalam.post_id = p.ID
35 AND basalam.meta_key = %s
36 LEFT JOIN {$metaTable} AS stock
37 ON stock.post_id = p.ID
38 AND stock.meta_key = '_stock_status'
39 LEFT JOIN {$metaTable} AS price
40 ON price.post_id = p.ID
41 AND price.meta_key = '_price'
42 WHERE p.post_type = 'product'
43 AND p.post_status = 'publish'
44 AND thumb.meta_value IS NOT NULL
45 AND basalam.post_id IS NULL
46 AND p.ID > %d
47 AND price.meta_value IS NOT NULL
48 AND CAST(price.meta_value AS DECIMAL(10,2)) > 1000
49 {$stockCondition}
50 ORDER BY p.ID ASC
51 LIMIT %d
52 ", $productIdMetaKey, $lastId, $postsPerPage);
53
54 $ids = $wpdb->get_col($query);
55
56 return array_map('intval', $ids);
57 }
58
59 public function getUpdatableProducts(array $args = []): array
60 {
61 global $wpdb;
62
63 $postsTable = $wpdb->posts;
64 $metaTable = $wpdb->postmeta;
65
66 $postsPerPage = $args['posts_per_page'] ?? 100;
67 $lastId = intval($args['last_updatable_product_id'] ?? 0);
68 $productIdMetaKey = ProductMetaKey::basalamProductId();
69
70 $query = $wpdb->prepare("
71 SELECT p.ID
72 FROM {$postsTable} AS p
73 INNER JOIN {$metaTable} AS basalam
74 ON basalam.post_id = p.ID
75 AND basalam.meta_key = %s
76 WHERE p.post_type = 'product'
77 AND p.post_status = 'publish'
78 AND p.ID > %d
79 ORDER BY p.ID ASC
80 LIMIT %d
81 ", $productIdMetaKey, $lastId, $postsPerPage);
82
83 $ids = $wpdb->get_col($query);
84
85 return array_map('intval', $ids);
86 }
87 }
88