| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Admin\Product\elements\ProductList; |
| 4 |
|
| 5 |
use SyncBasalam\Admin\Settings\SettingsConfig; |
| 6 |
use SyncBasalam\Admin\Components\CommonComponents; |
| 7 |
use SyncBasalam\Utilities\ProductMetaKey; |
| 8 |
|
| 9 |
defined('ABSPATH') || exit; |
| 10 |
|
| 11 |
class MetaBox |
| 12 |
{ |
| 13 |
public static function registerMetaBox() |
| 14 |
{ |
| 15 |
global $post; |
| 16 |
$productId = $post->ID; |
| 17 |
$productStatus = get_post_meta($productId, ProductMetaKey::basalamProductSyncStatus(), true); |
| 18 |
|
| 19 |
switch ($productStatus) { |
| 20 |
case 'synced': |
| 21 |
$statusColor = 'green'; |
| 22 |
$statusTooltip = '� |
| 23 |
حصول با باسلا� |
| 24 |
ه� |
| 25 |
گا� |
| 26 |
است.'; |
| 27 |
|
| 28 |
break; |
| 29 |
case 'pending': |
| 30 |
$statusColor = 'yellow'; |
| 31 |
$statusTooltip = '� |
| 32 |
حصول در حال اجرای ع� |
| 33 |
لیات است.'; |
| 34 |
|
| 35 |
break; |
| 36 |
default: |
| 37 |
$statusColor = 'red'; |
| 38 |
$statusTooltip = '� |
| 39 |
حصول با باسلا� |
| 40 |
ه� |
| 41 |
گا� |
| 42 |
نیست.'; |
| 43 |
|
| 44 |
break; |
| 45 |
} |
| 46 |
|
| 47 |
add_meta_box( |
| 48 |
'sync_basalam_single_product_manage_box', |
| 49 |
'تنظی� |
| 50 |
ات باسلا� |
| 51 |
<span title="' . esc_attr($statusTooltip) . '" style="background:' . esc_attr($statusColor) . ';width: 16px;height: 16px;border-radius: 100%;"> |
| 52 |
<img src="' . esc_url(syncBasalamPlugin()->assetsUrl() . "/icons/info.svg") . '" alt="" class="basalam-img-15"> |
| 53 |
</span>', |
| 54 |
[self::class, 'renderMetaBox'], |
| 55 |
'product', |
| 56 |
'side', |
| 57 |
'high' |
| 58 |
); |
| 59 |
} |
| 60 |
|
| 61 |
public static function renderMetaBox($post) |
| 62 |
{ |
| 63 |
$productId = $post->ID; |
| 64 |
$productStatus = get_post_status($productId); |
| 65 |
|
| 66 |
$basalamProductStatus = get_post_meta($productId, ProductMetaKey::basalamProductStatus(), true); |
| 67 |
$basalamProductSyncStatus = get_post_meta($productId, ProductMetaKey::basalamProductSyncStatus(), true); |
| 68 |
|
| 69 |
$settings = syncBasalamSettings(); |
| 70 |
$BasalamAccessToken = $settings->getSettings(SettingsConfig::TOKEN); |
| 71 |
$syncBasalamVendorId = $settings->getSettings(SettingsConfig::VENDOR_ID); |
| 72 |
|
| 73 |
if ($productStatus == 'publish') { |
| 74 |
if ($basalamProductSyncStatus == 'pending') { |
| 75 |
echo '<p class="basalam-p basalam-font-12">یک ع� |
| 76 |
لیات برای این � |
| 77 |
حصول در جریان است.</p>'; |
| 78 |
} elseif (!$BasalamAccessToken || !$syncBasalamVendorId) { |
| 79 |
echo '<p class="basalam-p basalam-font-12">دسترسی های لاز� |
| 80 |
دریافت نشده است ، ابتدا دسترسی ها را <a href="/wp-admin/admin.php?page=sync_basalam" target="_blank">دریافت</a> ن� |
| 81 |
ایید.</p>'; |
| 82 |
} else { |
| 83 |
if ($basalamProductStatus) { |
| 84 |
$syncBasalamProductId = get_post_meta($productId, ProductMetaKey::basalamProductId(), true); |
| 85 |
CommonComponents::renderBtn('بروزسانی � |
| 86 |
حصول در باسلا� |
| 87 |
', 'update_product_in_basalam', $post->ID, 'update_product_in_basalam_nonce', true); |
| 88 |
if ($basalamProductStatus == 2976) { |
| 89 |
CommonComponents::renderBtn('آرشیو کردن � |
| 90 |
حصول در باسلا� |
| 91 |
', 'archive_exist_product_on_basalam', $post->ID, 'archive_exist_product_on_basalam_nonce', true); |
| 92 |
} else { |
| 93 |
CommonComponents::renderBtn('بازگردانی � |
| 94 |
حصول در باسلا� |
| 95 |
', 'restore_exist_product_on_basalam', $post->ID, 'restore_exist_product_on_basalam_nonce', true); |
| 96 |
} |
| 97 |
$link = "https://basalam.com/p/" . $syncBasalamProductId; |
| 98 |
CommonComponents::renderLink('� |
| 99 |
شاهده � |
| 100 |
حصول در باسلا� |
| 101 |
', $link); |
| 102 |
CommonComponents::renderBtn('قطع اتصال � |
| 103 |
حصول', 'disconnect_exist_product_on_basalam', $post->ID, 'disconnect_exist_product_on_basalam_nonce', true); |
| 104 |
} else { |
| 105 |
CommonComponents::renderBtn('اضافه کردن � |
| 106 |
حصول در باسلا� |
| 107 |
', 'create_product_basalam', $post->ID, 'create_product_basalam_nonce', true); |
| 108 |
require_once syncBasalamPlugin()->templatePath("products/ConnectButton.php"); |
| 109 |
} |
| 110 |
} |
| 111 |
} else { |
| 112 |
echo '<p class="basalam-p basalam-font-12">برای دسترسی به تنظی� |
| 113 |
ات باسلا� |
| 114 |
، وضعیت � |
| 115 |
حصول را به "� |
| 116 |
نتشر شده" تغییر دهید.</p>'; |
| 117 |
} |
| 118 |
$nonceGetBasalamCategoryIdsAction = 'basalam_get_category_ids_nonce'; |
| 119 |
$nonceGetBasalamCategoryIdValue = wp_create_nonce($nonceGetBasalamCategoryIdsAction); |
| 120 |
echo '<hr>'; |
| 121 |
echo '<div> |
| 122 |
<button type="button" id="basalam_fetch_categories_btn" class="basalam-p basalam-button-full-primary" style="padding:4px !important;"> |
| 123 |
دریافت دستهبندیهای پیشنهادی باسلا� |
| 124 |
|
| 125 |
</button> |
| 126 |
<input type="hidden" id="basalam_get_category_ids_nonce" value="' . esc_attr($nonceGetBasalamCategoryIdValue) . '"> |
| 127 |
</div> |
| 128 |
<div id="sync_basalam_category_id" class="basalam-p__small basalam--hidden"> |
| 129 |
</div>'; |
| 130 |
|
| 131 |
$nonceGetBasalamCategoryAttrAction = 'basalam_get_category_attrs_nonce'; |
| 132 |
$nonceGetBasalamCategoryAttrValue = wp_create_nonce($nonceGetBasalamCategoryAttrAction); |
| 133 |
|
| 134 |
echo '<div id="sync_basalam_category_attributes" class="basalam-p__small basalam--hidden"> |
| 135 |
<input type="hidden" id="basalam_get_category_attrs_nonce" value="' . esc_attr($nonceGetBasalamCategoryAttrValue) . '"> |
| 136 |
</div>'; |
| 137 |
} |
| 138 |
} |
| 139 |
|