PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.8.5
ووسلام – همگام سازی ووکامرس و باسلام v1.8.5
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 / Utilities / ProductMetaKey.php

ProductMetaKey.php in ووسلام – همگام سازی ووکامرس و باسلام 1.8.5, at includes/Utilities/ProductMetaKey.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\Utilities;
4
5 use SyncBasalam\Admin\Settings\SettingsConfig;
6
7 defined('ABSPATH') || exit;
8
9 class ProductMetaKey
10 {
11 public const PRODUCT_ID = 'sync_basalam_product_id';
12 public const PRODUCT_SYNC_STATUS = 'sync_basalam_product_sync_status';
13 public const PRODUCT_STATUS = 'sync_basalam_product_status';
14
15 public static function basalamProductId($vendorId = null): string
16 {
17 return self::build(self::PRODUCT_ID, $vendorId);
18 }
19
20 public static function basalamProductSyncStatus($vendorId = null): string
21 {
22 return self::build(self::PRODUCT_SYNC_STATUS, $vendorId);
23 }
24
25 public static function basalamProductStatus($vendorId = null): string
26 {
27 return self::build(self::PRODUCT_STATUS, $vendorId);
28 }
29
30 public static function basalamProductMetaKeys($vendorId = null): array
31 {
32 return [
33 self::basalamProductId($vendorId),
34 self::basalamProductSyncStatus($vendorId),
35 self::basalamProductStatus($vendorId),
36 ];
37 }
38
39 private static function build(string $baseKey, $vendorId = null): string
40 {
41 $resolvedVendorId = self::normalizeVendorId($vendorId ?? self::getVendorIdFromSettings());
42
43 if ($resolvedVendorId === '') {
44 return $baseKey;
45 }
46
47 return "{$baseKey}_{$resolvedVendorId}";
48 }
49
50 private static function getVendorIdFromSettings()
51 {
52 return syncBasalamSettings()->getSettings(SettingsConfig::VENDOR_ID);
53 }
54
55 private static function normalizeVendorId($vendorId): string
56 {
57 if ($vendorId === null || $vendorId === '') {
58 return '';
59 }
60
61 return preg_replace('/[^a-zA-Z0-9_-]/', '', (string) $vendorId);
62 }
63 }
64