PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.9
ووسلام – همگام سازی ووکامرس و باسلام v1.10.9
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 / Services / Products / FetchProductsData.php

FetchProductsData.php in ووسلام – همگام سازی ووکامرس و باسلام 1.10.9, at includes/Services/Products/FetchProductsData.php

64 lines 1.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\Services\Products;
4
5 use SyncBasalam\Services\ApiServiceManager;
6 use SyncBasalam\Admin\Settings\SettingsConfig;
7 use SyncBasalam\Config\Endpoints;
8 use SyncBasalam\Logger\Logger;
9
10 defined('ABSPATH') || exit;
11
12 class FetchProductsData
13 {
14 private $baseUrl;
15 private $vendorId;
16
17 public function __construct()
18 {
19 $this->vendorId = syncBasalamSettings()->getSettings(SettingsConfig::VENDOR_ID);
20 $this->baseUrl = Endpoints::PRODUCTS_DATA;
21 }
22
23 public function getProductData($title = null, $cursor = null)
24 {
25 $query = ['per_page' => 30];
26
27 if (!empty($this->vendorId)) $query['vendor_ids'] = $this->vendorId;
28 if (!empty($title)) $query['product_title'] = $title;
29
30 if ($cursor !== null) $query['cursor'] = $cursor;
31
32 $url = $this->baseUrl . '?' . http_build_query($query);
33
34 $apiservice = syncBasalamContainer()->get(ApiServiceManager::class);
35
36 try {
37 $response = $apiservice->get($url);
38 } catch (\Exception $e) {
39 Logger::error('خطا در دریافت اطلاعات �
40 حصولات از باسلا�
41 : ' . $e->getMessage());
42 return [
43 'data' => [],
44 'has_more' => false,
45 'next_cursor' => null,
46 ];
47 }
48
49 $bodyData = [];
50
51 if (!empty($response['body'])) $bodyData = json_decode($response['body'], true);
52
53 $data = isset($bodyData['data']) && is_array($bodyData['data']) ? $bodyData['data'] : [];
54
55 $nextCursor = $bodyData['next_cursor'] ?? null;
56
57 return [
58 'data' => $data,
59 'has_more' => $nextCursor !== null,
60 'next_cursor' => $nextCursor,
61 ];
62 }
63 }
64