| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Admin\Product\Data\Services; |
| 4 |
|
| 5 |
defined('ABSPATH') || exit; |
| 6 |
|
| 7 |
class GoldDataHandler |
| 8 |
{ |
| 9 |
public static function getGoldAttributesAsArray($product): array |
| 10 |
{ |
| 11 |
$goldData = self::getGoldData($product); |
| 12 |
|
| 13 |
return [ |
| 14 |
[ |
| 15 |
'attribute_id' => 1785, |
| 16 |
'value' => $goldData['purity'] ?? '', |
| 17 |
], |
| 18 |
[ |
| 19 |
'attribute_id' => 1786, |
| 20 |
'value' => $goldData['weight'] ?? '', |
| 21 |
], |
| 22 |
]; |
| 23 |
} |
| 24 |
|
| 25 |
public static function getGoldData($product): array |
| 26 |
{ |
| 27 |
return [ |
| 28 |
'purity' => get_post_meta($product->get_id(), '_sync_basalam_gold_purity', true), |
| 29 |
'weight' => get_post_meta($product->get_id(), '_sync_basalam_gold_weight', true), |
| 30 |
]; |
| 31 |
} |
| 32 |
|
| 33 |
public static function hasGoldData($product): bool |
| 34 |
{ |
| 35 |
$fields = [ |
| 36 |
'_sync_basalam_gold_purity', |
| 37 |
'_sync_basalam_gold_weight', |
| 38 |
]; |
| 39 |
|
| 40 |
foreach ($fields as $field) { |
| 41 |
if (!empty(get_post_meta($product->get_id(), $field, true))) { |
| 42 |
return true; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
return false; |
| 47 |
} |
| 48 |
|
| 49 |
public static function getAllGoldFields(): array |
| 50 |
{ |
| 51 |
return [ |
| 52 |
'purity' => 'عیار طلا (� |
| 53 |
بنای 1000)', |
| 54 |
'weight' => 'وزن طلا (� |
| 55 |
یلی گر� |
| 56 |
)', |
| 57 |
]; |
| 58 |
} |
| 59 |
} |
| 60 |
|