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

70 lines 1.9 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 public const PRODUCT_VIDEO = '_sync_basalam_product_video';
15
16 public static function basalamProductVideo(): string
17 {
18 return self::PRODUCT_VIDEO;
19 }
20
21 public static function basalamProductId($vendorId = null): string
22 {
23 return self::build(self::PRODUCT_ID, $vendorId);
24 }
25
26 public static function basalamProductSyncStatus($vendorId = null): string
27 {
28 return self::build(self::PRODUCT_SYNC_STATUS, $vendorId);
29 }
30
31 public static function basalamProductStatus($vendorId = null): string
32 {
33 return self::build(self::PRODUCT_STATUS, $vendorId);
34 }
35
36 public static function basalamProductMetaKeys($vendorId = null): array
37 {
38 return [
39 self::basalamProductId($vendorId),
40 self::basalamProductSyncStatus($vendorId),
41 self::basalamProductStatus($vendorId),
42 ];
43 }
44
45 private static function build(string $baseKey, $vendorId = null): string
46 {
47 $resolvedVendorId = self::normalizeVendorId($vendorId ?? self::getVendorIdFromSettings());
48
49 if ($resolvedVendorId === '') {
50 return $baseKey;
51 }
52
53 return "{$baseKey}_{$resolvedVendorId}";
54 }
55
56 private static function getVendorIdFromSettings()
57 {
58 return syncBasalamSettings()->getSettings(SettingsConfig::VENDOR_ID);
59 }
60
61 private static function normalizeVendorId($vendorId): string
62 {
63 if ($vendorId === null || $vendorId === '') {
64 return '';
65 }
66
67 return preg_replace('/[^a-zA-Z0-9_-]/', '', (string) $vendorId);
68 }
69 }
70