| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Admin\Product\Data\Services; |
| 4 |
|
| 5 |
defined('ABSPATH') || exit; |
| 6 |
|
| 7 |
class MobileDataHandler |
| 8 |
{ |
| 9 |
public static function getMobileAttributesAsArray($product): array |
| 10 |
{ |
| 11 |
$mobileData = self::getMobileData($product); |
| 12 |
|
| 13 |
return [ |
| 14 |
[ |
| 15 |
'attribute_id' => 1707, |
| 16 |
'value' => $mobileData['storage'] ?? '', |
| 17 |
], |
| 18 |
[ |
| 19 |
'attribute_id' => 1708, |
| 20 |
'value' => $mobileData['cpu_type'] ?? '', |
| 21 |
], |
| 22 |
[ |
| 23 |
'attribute_id' => 1709, |
| 24 |
'value' => $mobileData['ram'] ?? '', |
| 25 |
], |
| 26 |
[ |
| 27 |
'attribute_id' => 1710, |
| 28 |
'value' => $mobileData['screen_size'] ?? '', |
| 29 |
], |
| 30 |
[ |
| 31 |
'attribute_id' => 1711, |
| 32 |
'value' => $mobileData['rear_camera'] ?? '', |
| 33 |
], |
| 34 |
[ |
| 35 |
'attribute_id' => 1712, |
| 36 |
'value' => $mobileData['battery_capacity'] ?? '', |
| 37 |
], |
| 38 |
]; |
| 39 |
} |
| 40 |
|
| 41 |
public static function getMobileData($product): array |
| 42 |
{ |
| 43 |
return [ |
| 44 |
'storage' => get_post_meta($product->get_id(), '_sync_basalam_mobile_storage', true), |
| 45 |
'cpu_type' => get_post_meta($product->get_id(), '_sync_basalam_cpu_type', true), |
| 46 |
'ram' => get_post_meta($product->get_id(), '_sync_basalam_mobile_ram', true), |
| 47 |
'screen_size' => get_post_meta($product->get_id(), '_sync_basalam_screen_size', true), |
| 48 |
'rear_camera' => get_post_meta($product->get_id(), '_sync_basalam_rear_camera', true), |
| 49 |
'battery_capacity' => get_post_meta($product->get_id(), '_sync_basalam_battery_capacity', true), |
| 50 |
]; |
| 51 |
} |
| 52 |
|
| 53 |
public static function saveMobileData($product): void |
| 54 |
{ |
| 55 |
// No longer needed - individual fields are saved directly by MobileFields |
| 56 |
} |
| 57 |
|
| 58 |
public static function deleteMobileData($product): void |
| 59 |
{ |
| 60 |
// No longer needed - individual fields are deleted directly by MobileFields |
| 61 |
} |
| 62 |
|
| 63 |
public static function hasMobileData($product): bool |
| 64 |
{ |
| 65 |
$fields = [ |
| 66 |
'_sync_basalam_mobile_storage', |
| 67 |
'_sync_basalam_cpu_type', |
| 68 |
'_sync_basalam_mobile_ram', |
| 69 |
'_sync_basalam_screen_size', |
| 70 |
'_sync_basalam_rear_camera', |
| 71 |
'_sync_basalam_battery_capacity', |
| 72 |
]; |
| 73 |
|
| 74 |
foreach ($fields as $field) { |
| 75 |
if (!empty(get_post_meta($product->get_id(), $field, true))) { |
| 76 |
return true; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
return false; |
| 81 |
} |
| 82 |
|
| 83 |
public static function getMobileFieldValue($product, string $field): string |
| 84 |
{ |
| 85 |
$fieldMap = [ |
| 86 |
'storage' => '_sync_basalam_mobile_storage', |
| 87 |
'cpu_type' => '_sync_basalam_cpu_type', |
| 88 |
'ram' => '_sync_basalam_mobile_ram', |
| 89 |
'screen_size' => '_sync_basalam_screen_size', |
| 90 |
'rear_camera' => '_sync_basalam_rear_camera', |
| 91 |
'battery_capacity' => '_sync_basalam_battery_capacity', |
| 92 |
]; |
| 93 |
|
| 94 |
$metaKey = $fieldMap[$field] ?? null; |
| 95 |
return $metaKey ? get_post_meta($product->get_id(), $metaKey, true) : ''; |
| 96 |
} |
| 97 |
|
| 98 |
public static function getAllMobileFields(): array |
| 99 |
{ |
| 100 |
return [ |
| 101 |
'storage' => 'حافظه داخلی', |
| 102 |
'cpu_type' => 'نوع پردازنده - CPU', |
| 103 |
'ram' => 'حافظه RAM', |
| 104 |
'screen_size' => 'سایز صفحه ن� |
| 105 |
ایش', |
| 106 |
'rear_camera' => 'دوربین پشت', |
| 107 |
'battery_capacity' => 'ظرفیت باتری', |
| 108 |
]; |
| 109 |
} |
| 110 |
} |