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 / FetchCommission.php

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

44 lines 1.3 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\Config\Endpoints;
6 use SyncBasalam\Services\ApiServiceManager;
7
8 defined('ABSPATH') || exit;
9 class FetchCommission
10 {
11 public static function fetchCategoryCommission($categoryIds)
12 {
13 $apiservice = syncBasalamContainer()->get(ApiServiceManager::class);
14 $queryParams = [];
15
16 if (isset($categoryIds[0]) && is_numeric($categoryIds[0])) {
17 $queryParams[] = "product.category.level1=" . intval($categoryIds[0]);
18 }
19 if (isset($categoryIds[1]) && is_numeric($categoryIds[1])) {
20 $queryParams[] = "product.category.level2=" . intval($categoryIds[1]);
21 }
22 if (isset($categoryIds[2]) && is_numeric($categoryIds[2])) {
23 $queryParams[] = "product.category.level3=" . intval($categoryIds[2]);
24 }
25
26 if (empty($queryParams)) return false;
27
28 $url = Endpoints::COMMISSION . '?' . implode("&", $queryParams);
29
30 try {
31 $result = $apiservice->get($url);
32 } catch (\Exception $e) {
33 return 0;
34 }
35
36 $decodedBody = json_decode($result['body'], true);
37
38 $commissionPercent = $decodedBody['commission_data']['commission_percent'];
39
40 if ($commissionPercent) return $commissionPercent;
41 return 0;
42 }
43 }
44