| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Registrar; |
| 4 |
|
| 5 |
use SyncBasalam\Actions\RegisterActions; |
| 6 |
use SyncBasalam\Admin\Pages; |
| 7 |
use SyncBasalam\Registrar\Contracts\RegistrarInterface; |
| 8 |
use SyncBasalam\Admin\Product\elements\ProductList\StatusColumn; |
| 9 |
use SyncBasalam\Admin\Product\elements\ProductList\MetaBox; |
| 10 |
use SyncBasalam\Admin\Product\elements\ProductList\BulkEdit; |
| 11 |
use SyncBasalam\Admin\Product\elements\SingleProduct\Tab; |
| 12 |
use SyncBasalam\Admin\Product\elements\SingleProduct\VideoField; |
| 13 |
use SyncBasalam\Admin\Product\elements\ProductList\Filter; |
| 14 |
use SyncBasalam\Admin\Product\elements\ProductList\Actions; |
| 15 |
use SyncBasalam\Admin\Order\OrderColumn; |
| 16 |
use SyncBasalam\Admin\Order\OrderMetaBox; |
| 17 |
use SyncBasalam\Admin\Components\OrderPageComponents; |
| 18 |
use SyncBasalam\Admin\Order\OrderStatuses; |
| 19 |
use SyncBasalam\Admin\Product\Operations\ConnectProduct; |
| 20 |
use SyncBasalam\Admin\Announcement\AnnouncementCenter; |
| 21 |
use SyncBasalam\Admin\Onboarding\PointerTour; |
| 22 |
use SyncBasalam\Services\Products\DuplicateConnectionReport; |
| 23 |
use SyncBasalam\Services\Products\ProductConnection; |
| 24 |
use SyncBasalam\Services\SystemResourceMonitor; |
| 25 |
use SyncBasalam\Utilities\ProductMetaKey; |
| 26 |
use SyncBasalam\Utilities\ChatWidget; |
| 27 |
use SyncBasalam\Utilities\TicketFlashNotice; |
| 28 |
use SyncBasalam\Admin\Settings\SettingsPageHandler; |
| 29 |
use SyncBasalam\Admin\FinancialManagement\Menu as FinancialManagementMenu; |
| 30 |
use SyncBasalam\Admin\FinancialManagement\BalanceSettlement; |
| 31 |
use SyncBasalam\Admin\FinancialManagement\FinancialManagementHistory; |
| 32 |
|
| 33 |
defined("ABSPATH") || exit; |
| 34 |
|
| 35 |
class AdminRegistrar implements RegistrarInterface |
| 36 |
{ |
| 37 |
public static function register(): void |
| 38 |
{ |
| 39 |
$container = syncBasalamContainer(); |
| 40 |
$pages = $container->get(Pages::class); |
| 41 |
$filter = $container->get(Filter::class); |
| 42 |
$orderColumn = $container->get(OrderColumn::class); |
| 43 |
$orderMetaBox = $container->get(OrderMetaBox::class); |
| 44 |
$orderStatuses = $container->get(OrderStatuses::class); |
| 45 |
$actions = $container->get(Actions::class); |
| 46 |
$bulkEdit = $container->get(BulkEdit::class); |
| 47 |
|
| 48 |
// Initialize Admin Actions |
| 49 |
$container->get(RegisterActions::class); |
| 50 |
|
| 51 |
// Admin Menu |
| 52 |
\add_action("admin_menu", [$pages, "registerMenus"]); |
| 53 |
\add_filter("script_loader_tag", [ChatWidget::class, "addTokenToWidgetScript"], 10, 3); |
| 54 |
|
| 55 |
// Admin Scripts & Styles |
| 56 |
\add_action("admin_enqueue_scripts", [self::class, "adminEnqueueStyles"]); |
| 57 |
\add_action("admin_enqueue_scripts", [self::class, "adminEnqueueScripts"]); |
| 58 |
\add_action("admin_enqueue_scripts", [self::class, "financialManagementEnqueueAssets"]); |
| 59 |
\add_action("admin_footer", [AnnouncementCenter::class, 'renderPanel']); |
| 60 |
|
| 61 |
// Financial Management (� |
| 62 |
دیریت � |
| 63 |
الی) |
| 64 |
FinancialManagementHistory::register(); |
| 65 |
BalanceSettlement::register(); |
| 66 |
|
| 67 |
// Product Columns |
| 68 |
\add_filter("manage_edit-product_columns", [StatusColumn::class, "registerStatusColumn"]); |
| 69 |
\add_action("manage_product_posts_custom_column", [StatusColumn::class, "renderStatusColumnContent"], 10, 2); |
| 70 |
|
| 71 |
// Product Meta Boxes |
| 72 |
\add_action("add_meta_boxes_product", [MetaBox::class, "registerMetaBox"]); |
| 73 |
|
| 74 |
// Basalam Product Settings Tab |
| 75 |
\add_filter('woocommerce_product_data_tabs', [Tab::class, 'registerTab']); |
| 76 |
\add_action('woocommerce_product_data_panels', [Tab::class, 'renderTabContent']); |
| 77 |
\add_action('woocommerce_process_product_meta', [Tab::class, 'saveTabData']); |
| 78 |
|
| 79 |
// Basalam Product Video Meta Box (sidebar, like product image/gallery) |
| 80 |
\add_action('add_meta_boxes_product', [VideoField::class, 'registerMetaBox']); |
| 81 |
\add_action('woocommerce_process_product_meta', [VideoField::class, 'save']); |
| 82 |
|
| 83 |
// Product Filter |
| 84 |
\add_action("restrict_manage_posts", [$filter, "renderFilterDropdown"]); |
| 85 |
\add_action("pre_get_posts", [$filter, "applyFilterToQuery"]); |
| 86 |
|
| 87 |
// Order Columns (HPOS) |
| 88 |
\add_action("manage_woocommerce_page_wc-orders_custom_column", [$orderColumn, "renderColumn"], 10, 2); |
| 89 |
\add_filter("manage_woocommerce_page_wc-orders_columns", [$orderColumn, "addColumn"]); |
| 90 |
|
| 91 |
// Order Columns (Traditional CPT - non-HPOS) |
| 92 |
\add_action("manage_shop_order_posts_custom_column", [$orderColumn, "renderColumn"], 10, 2); |
| 93 |
\add_filter("manage_edit-shop_order_columns", [$orderColumn, "addColumn"]); |
| 94 |
|
| 95 |
// Order Meta Boxes |
| 96 |
\add_action("add_meta_boxes", [$orderMetaBox, "registerMetaBox"], 10); |
| 97 |
|
| 98 |
// Order Meta Boxes (Traditional CPT - non-HPOS) |
| 99 |
\add_action("add_meta_boxes_shop_order", [$orderMetaBox, "registerMetaBox"], 10); |
| 100 |
|
| 101 |
// Order Statuses |
| 102 |
\add_filter("wc_order_statuses", [$orderStatuses, "registerorderStatuses"]); |
| 103 |
|
| 104 |
// Order Stock Levels |
| 105 |
\add_action("woocommerce_order_status_bslm-rejected", "wc_maybe_increase_stock_levels"); |
| 106 |
\add_action("woocommerce_order_status_bslm-preparation", "wc_maybe_reduce_stock_levels"); |
| 107 |
\add_action("woocommerce_order_status_bslm-shipping", "wc_maybe_reduce_stock_levels"); |
| 108 |
\add_action("woocommerce_order_status_bslm-completed", "wc_maybe_reduce_stock_levels"); |
| 109 |
|
| 110 |
// Bulk Actions |
| 111 |
\add_filter("bulk_actions-edit-product", [$actions, "registerBulkActions"]); |
| 112 |
\add_filter("handle_bulk_actions-edit-product", [$actions, "handleBulkAction"], 10, 3); |
| 113 |
\add_action('bulk_edit_custom_box', [$bulkEdit, 'renderFields'], 10, 2); |
| 114 |
\add_action('admin_action_sync_basalam_bulk_edit', [$bulkEdit, 'save']); |
| 115 |
|
| 116 |
// Product Duplicate |
| 117 |
// نسخه کپی یک � |
| 118 |
حصول تازه است و نباید هیچ داده ووسلا� |
| 119 |
ی از � |
| 120 |
حصول اصلی به ارث ببرد؛ |
| 121 |
// � |
| 122 |
خصوصا شناسه اتصال، وگرنه بروزرسانی نسخه کپی، � |
| 123 |
حصول اصلی را در باسلا� |
| 124 |
تغییر � |
| 125 |
یدهد. |
| 126 |
\add_filter("woocommerce_duplicate_product_exclude_meta", [self::class, "excludePluginMetaFromDuplicate"], 10, 2); |
| 127 |
|
| 128 |
\add_action("woocommerce_product_duplicate", function ($newProduct) { |
| 129 |
if (!is_object($newProduct) || !method_exists($newProduct, "get_id")) return; |
| 130 |
|
| 131 |
ProductConnection::purgeAll($newProduct->get_id()); |
| 132 |
}, 10, 1); |
| 133 |
|
| 134 |
// Product Duplicate (third party plugins, e.g. Yoast Duplicate Post) |
| 135 |
foreach (["dp_duplicate_post", "dp_duplicate_page", "duplicate_post_post_copy"] as $duplicateHook) { |
| 136 |
\add_action($duplicateHook, function ($newPostId, $sourcePost = null) { |
| 137 |
if (!is_scalar($newPostId) || \get_post_type((int) $newPostId) !== "product") return; |
| 138 |
|
| 139 |
// اگر هوک، پست � |
| 140 |
بدا را ه� |
| 141 |
بدهد � |
| 142 |
ط� |
| 143 |
ئنی� |
| 144 |
شناسه اول نسخه کپی است. |
| 145 |
if (is_object($sourcePost) && !empty($sourcePost->ID) && (int) $sourcePost->ID !== (int) $newPostId) { |
| 146 |
ProductConnection::purgeAll((int) $newPostId); |
| 147 |
|
| 148 |
return; |
| 149 |
} |
| 150 |
|
| 151 |
// در غیر این صورت � |
| 152 |
حافظهکارانه ع� |
| 153 |
ل � |
| 154 |
یکنی� |
| 155 |
تا داده � |
| 156 |
حصول اصلی پاک نشود. |
| 157 |
ProductConnection::purgeIfCopy((int) $newPostId); |
| 158 |
}, 10, 2); |
| 159 |
} |
| 160 |
|
| 161 |
// Duplicate connection report (admin notice + dismiss handler) |
| 162 |
DuplicateConnectionReport::registerHooks(); |
| 163 |
|
| 164 |
// Order Check Buttons (HPOS) |
| 165 |
\add_action("woocommerce_order_list_table_extra_tablenav", [OrderPageComponents::class, "renderCheckOrdersButton"], 20, 1); |
| 166 |
|
| 167 |
// Order Check Buttons (Traditional CPT - uses same hook as product filter) |
| 168 |
\add_action("restrict_manage_posts", [OrderPageComponents::class, "renderCheckOrdersButtonTraditional"]); |
| 169 |
|
| 170 |
// Initialize AJAX handlers |
| 171 |
$connectProduct = $container->get(ConnectProduct::class); |
| 172 |
add_action('wp_ajax_basalam_search_products', [$connectProduct, 'handleSearchProducts']); |
| 173 |
add_action('wp_ajax_sync_basalam_mark_pointer_onboarding_completed', [PointerTour::class, 'markPointerOnboardingCompleted']); |
| 174 |
add_action('wp_ajax_' . AnnouncementCenter::MARK_SEEN_ACTION, [AnnouncementCenter::class, 'markAllSeen']); |
| 175 |
add_action('wp_ajax_' . AnnouncementCenter::FETCH_PAGE_ACTION, [AnnouncementCenter::class, 'fetchPage']); |
| 176 |
|
| 177 |
// Tasks per minute calculation handler |
| 178 |
add_action('wp_ajax_basalam_calculate_tasks_per_minute', function () { |
| 179 |
check_ajax_referer('basalam_update_setting_nonce', 'nonce', true); |
| 180 |
|
| 181 |
$monitor = syncBasalamContainer()->get(SystemResourceMonitor::class); |
| 182 |
$optimal = $monitor->calculateOptimalTasksPerMinute(); |
| 183 |
|
| 184 |
wp_send_json_success([ |
| 185 |
'optimal_tasks_per_minute' => $optimal |
| 186 |
]); |
| 187 |
}); |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
/** |
| 192 |
* حذف ه� |
| 193 |
ه � |
| 194 |
تاهای ووسلا� |
| 195 |
از نسخه کپی، پیش از ذخیره شدن آن توسط ووکا� |
| 196 |
رس. |
| 197 |
* ووکا� |
| 198 |
رس ه� |
| 199 |
ین فهرست را روی تنوعهای کپی شده ه� |
| 200 |
اع� |
| 201 |
ال � |
| 202 |
یکند. |
| 203 |
* |
| 204 |
* @param array $excludedMeta کلیدهایی که تا اینجا برای حذف انتخاب شدهاند. |
| 205 |
* @param array $productMetaKeys کلیدهای � |
| 206 |
تای � |
| 207 |
حصول اصلی. |
| 208 |
*/ |
| 209 |
public static function excludePluginMetaFromDuplicate($excludedMeta, $productMetaKeys = []) |
| 210 |
{ |
| 211 |
$excludedMeta = is_array($excludedMeta) ? $excludedMeta : []; |
| 212 |
|
| 213 |
foreach ((array) $productMetaKeys as $metaKey) { |
| 214 |
if (ProductConnection::isPluginMetaKey($metaKey)) $excludedMeta[] = $metaKey; |
| 215 |
} |
| 216 |
|
| 217 |
// کلیدهای تنوعها در فهرست � |
| 218 |
تای � |
| 219 |
حصول والد نیستند و باید دستی اضافه شوند. |
| 220 |
$excludedMeta = array_merge( |
| 221 |
$excludedMeta, |
| 222 |
ProductMetaKey::basalamProductMetaKeys(), |
| 223 |
[ProductMetaKey::basalamVariationId(), ProductMetaKey::DISCOUNTED] |
| 224 |
); |
| 225 |
|
| 226 |
return array_values(array_unique($excludedMeta)); |
| 227 |
} |
| 228 |
|
| 229 |
public static function assetsUrl($path = null) |
| 230 |
{ |
| 231 |
return plugin_dir_url(dirname(__FILE__, 2)) . "assets/" . $path; |
| 232 |
} |
| 233 |
|
| 234 |
public static function isWoosalamRelatedAdminScreen($hook = ''): bool |
| 235 |
{ |
| 236 |
return self::isPluginAdminPage($hook) |
| 237 |
|| self::isProductAdminScreen($hook) |
| 238 |
|| self::isOrderAdminScreen($hook); |
| 239 |
} |
| 240 |
|
| 241 |
private static function isPluginAdminPage($hook = ''): bool |
| 242 |
{ |
| 243 |
$page = self::currentAdminPage(); |
| 244 |
|
| 245 |
if ($page !== '' && in_array($page, self::pluginAdminPages(), true)) { |
| 246 |
return true; |
| 247 |
} |
| 248 |
|
| 249 |
return is_string($hook) && strpos($hook, 'sync_basalam') !== false; |
| 250 |
} |
| 251 |
|
| 252 |
private static function isProductAdminScreen($hook = ''): bool |
| 253 |
{ |
| 254 |
$screen = function_exists('get_current_screen') ? get_current_screen() : null; |
| 255 |
|
| 256 |
if ($screen && isset($screen->post_type) && $screen->post_type === 'product') { |
| 257 |
return true; |
| 258 |
} |
| 259 |
|
| 260 |
$postType = isset($_GET['post_type']) ? sanitize_key(wp_unslash($_GET['post_type'])) : ''; |
| 261 |
if ($postType === 'product') { |
| 262 |
return true; |
| 263 |
} |
| 264 |
|
| 265 |
$postId = isset($_GET['post']) ? absint($_GET['post']) : 0; |
| 266 |
if ($postId > 0 && function_exists('get_post_type') && get_post_type($postId) === 'product') { |
| 267 |
return true; |
| 268 |
} |
| 269 |
|
| 270 |
return in_array((string) $hook, ['edit-product', 'product'], true); |
| 271 |
} |
| 272 |
|
| 273 |
private static function isOrderAdminScreen($hook = ''): bool |
| 274 |
{ |
| 275 |
$screen = function_exists('get_current_screen') ? get_current_screen() : null; |
| 276 |
|
| 277 |
if ($screen) { |
| 278 |
$screenId = isset($screen->id) ? (string) $screen->id : ''; |
| 279 |
$postType = isset($screen->post_type) ? (string) $screen->post_type : ''; |
| 280 |
|
| 281 |
if ($postType === 'shop_order' || $screenId === 'woocommerce_page_wc-orders') { |
| 282 |
return true; |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
$page = self::currentAdminPage(); |
| 287 |
if ($page === 'wc-orders') { |
| 288 |
return true; |
| 289 |
} |
| 290 |
|
| 291 |
$postType = isset($_GET['post_type']) ? sanitize_key(wp_unslash($_GET['post_type'])) : ''; |
| 292 |
if ($postType === 'shop_order') { |
| 293 |
return true; |
| 294 |
} |
| 295 |
|
| 296 |
$postId = isset($_GET['post']) ? absint($_GET['post']) : 0; |
| 297 |
if ($postId > 0 && function_exists('get_post_type') && get_post_type($postId) === 'shop_order') { |
| 298 |
return true; |
| 299 |
} |
| 300 |
|
| 301 |
return in_array((string) $hook, ['edit-shop_order', 'shop_order', 'woocommerce_page_wc-orders'], true); |
| 302 |
} |
| 303 |
|
| 304 |
private static function isProductEditScreen($hook = ''): bool |
| 305 |
{ |
| 306 |
$screen = function_exists('get_current_screen') ? get_current_screen() : null; |
| 307 |
|
| 308 |
if ($screen && isset($screen->post_type, $screen->base)) { |
| 309 |
return $screen->post_type === 'product' && in_array($screen->base, ['post', 'post-new'], true); |
| 310 |
} |
| 311 |
|
| 312 |
return self::isProductAdminScreen($hook) && in_array((string) $hook, ['post.php', 'post-new.php', 'product'], true); |
| 313 |
} |
| 314 |
|
| 315 |
private static function isPluginPage(string $page): bool |
| 316 |
{ |
| 317 |
return self::currentAdminPage() === $page; |
| 318 |
} |
| 319 |
|
| 320 |
private static function isTicketPage(): bool |
| 321 |
{ |
| 322 |
return in_array(self::currentAdminPage(), [ |
| 323 |
'sync_basalam_tickets', |
| 324 |
'sync_basalam_ticket', |
| 325 |
'sync_basalam_new_ticket', |
| 326 |
], true); |
| 327 |
} |
| 328 |
|
| 329 |
private static function currentAdminPage(): string |
| 330 |
{ |
| 331 |
return isset($_GET['page']) ? sanitize_key(wp_unslash($_GET['page'])) : ''; |
| 332 |
} |
| 333 |
|
| 334 |
private static function pluginAdminPages(): array |
| 335 |
{ |
| 336 |
return [ |
| 337 |
'sync_basalam', |
| 338 |
'sync_basalam_logs', |
| 339 |
'sync_basalam_vendor_info', |
| 340 |
'sync_basalam_help', |
| 341 |
'sync_basalam_category_mapping', |
| 342 |
FinancialManagementMenu::PAGE_SLUG, |
| 343 |
'basalam-onboarding', |
| 344 |
'basalam-save-token', |
| 345 |
'basalam-show-products', |
| 346 |
'sync_basalam_tickets', |
| 347 |
'sync_basalam_ticket', |
| 348 |
'sync_basalam_new_ticket', |
| 349 |
]; |
| 350 |
} |
| 351 |
|
| 352 |
public static function adminEnqueueStyles($hook = '') |
| 353 |
{ |
| 354 |
if (!self::isWoosalamRelatedAdminScreen($hook)) { |
| 355 |
return; |
| 356 |
} |
| 357 |
|
| 358 |
$version = syncbasalamplugin()->getVersion(); |
| 359 |
|
| 360 |
wp_enqueue_style( |
| 361 |
"basalam-admin-style", |
| 362 |
self::assetsUrl("css/style.css"), |
| 363 |
array(), |
| 364 |
$version |
| 365 |
); |
| 366 |
wp_enqueue_style( |
| 367 |
"basalam-admin-font-style", |
| 368 |
self::assetsUrl("css/font.css"), |
| 369 |
array(), |
| 370 |
$version |
| 371 |
); |
| 372 |
if (self::isPluginPage('sync_basalam_vendor_info')) { |
| 373 |
wp_enqueue_style( |
| 374 |
"basalam-admin-social-style", |
| 375 |
self::assetsUrl("css/social.css"), |
| 376 |
array(), |
| 377 |
$version |
| 378 |
); |
| 379 |
} |
| 380 |
|
| 381 |
if (self::isPluginPage('sync_basalam_logs')) { |
| 382 |
wp_enqueue_style( |
| 383 |
"basalam-admin-logs-style", |
| 384 |
self::assetsUrl("css/logs.css"), |
| 385 |
array(), |
| 386 |
$version |
| 387 |
); |
| 388 |
} |
| 389 |
|
| 390 |
if (self::isPluginPage('basalam-onboarding')) { |
| 391 |
wp_enqueue_style( |
| 392 |
"basalam-admin-onboarding-style", |
| 393 |
self::assetsUrl("css/onboarding.css"), |
| 394 |
array(), |
| 395 |
$version |
| 396 |
); |
| 397 |
} |
| 398 |
wp_enqueue_style( |
| 399 |
"basalam-admin-toast-style", |
| 400 |
self::assetsUrl("css/toast.css"), |
| 401 |
array(), |
| 402 |
$version |
| 403 |
); |
| 404 |
|
| 405 |
if (PointerTour::shouldLoadPointerTour((string) $hook)) { |
| 406 |
wp_enqueue_style('wp-pointer'); |
| 407 |
} |
| 408 |
} |
| 409 |
|
| 410 |
public static function adminEnqueueScripts($hook = '') |
| 411 |
{ |
| 412 |
$version = syncbasalamplugin()->getVersion(); |
| 413 |
|
| 414 |
if (ChatWidget::shouldLoadWidget()) { |
| 415 |
wp_enqueue_script( |
| 416 |
"basalam-chat-widget-script", |
| 417 |
self::assetsUrl("chat/widget-loader.js"), |
| 418 |
[], |
| 419 |
$version, |
| 420 |
true |
| 421 |
); |
| 422 |
} |
| 423 |
|
| 424 |
$shouldLoadPointerTour = PointerTour::shouldLoadPointerTour((string) $hook); |
| 425 |
$shouldLoadAssets = self::isWoosalamRelatedAdminScreen($hook); |
| 426 |
|
| 427 |
if (!$shouldLoadAssets && !$shouldLoadPointerTour) { |
| 428 |
return; |
| 429 |
} |
| 430 |
|
| 431 |
$isPluginPage = self::isPluginAdminPage($hook); |
| 432 |
$isMainPage = self::isPluginPage('sync_basalam'); |
| 433 |
$isProductScreen = self::isProductAdminScreen($hook); |
| 434 |
$isProductEditScreen = self::isProductEditScreen($hook); |
| 435 |
$isOrderScreen = self::isOrderAdminScreen($hook); |
| 436 |
|
| 437 |
if ($shouldLoadPointerTour) { |
| 438 |
wp_enqueue_script('wp-pointer'); |
| 439 |
} |
| 440 |
|
| 441 |
wp_enqueue_script( |
| 442 |
"basalam-admin-toast-script", |
| 443 |
self::assetsUrl("js/toast.js"), |
| 444 |
[], |
| 445 |
$version, |
| 446 |
true |
| 447 |
); |
| 448 |
|
| 449 |
$ticketNotice = TicketFlashNotice::pull(); |
| 450 |
if ($ticketNotice !== null) { |
| 451 |
wp_add_inline_script( |
| 452 |
"basalam-admin-toast-script", |
| 453 |
sprintf( |
| 454 |
'window.addEventListener("DOMContentLoaded",function(){if(window.BasalamToast){window.BasalamToast.show(%s,%s);}});', |
| 455 |
wp_json_encode($ticketNotice['message'], JSON_UNESCAPED_UNICODE), |
| 456 |
wp_json_encode($ticketNotice['type']) |
| 457 |
), |
| 458 |
'after' |
| 459 |
); |
| 460 |
} |
| 461 |
|
| 462 |
$settingsValidationError = SettingsPageHandler::pullValidationError(); |
| 463 |
if ($settingsValidationError !== '') { |
| 464 |
wp_add_inline_script( |
| 465 |
"basalam-admin-toast-script", |
| 466 |
sprintf( |
| 467 |
'window.addEventListener("DOMContentLoaded",function(){if(window.BasalamToast){window.BasalamToast.error(%s);}});', |
| 468 |
wp_json_encode($settingsValidationError, JSON_UNESCAPED_UNICODE) |
| 469 |
), |
| 470 |
'after' |
| 471 |
); |
| 472 |
} |
| 473 |
|
| 474 |
if (self::isPluginPage('sync_basalam_logs')) { |
| 475 |
wp_enqueue_script( |
| 476 |
"basalam-admin-logs-script", |
| 477 |
self::assetsUrl("js/logs.js"), |
| 478 |
["jquery", "basalam-admin-toast-script"], |
| 479 |
$version, |
| 480 |
true |
| 481 |
); |
| 482 |
} |
| 483 |
|
| 484 |
if (self::isPluginPage('sync_basalam_help')) { |
| 485 |
wp_enqueue_script( |
| 486 |
"basalam-admin-help-script", |
| 487 |
self::assetsUrl("js/help.js"), |
| 488 |
["jquery", "basalam-admin-toast-script"], |
| 489 |
$version, |
| 490 |
true |
| 491 |
); |
| 492 |
} |
| 493 |
|
| 494 |
if ($isProductEditScreen) { |
| 495 |
wp_enqueue_script( |
| 496 |
"basalam-admin-product-fields-script", |
| 497 |
self::assetsUrl("js/product-fields.js"), |
| 498 |
["jquery", "basalam-admin-toast-script"], |
| 499 |
$version, |
| 500 |
true |
| 501 |
); |
| 502 |
wp_enqueue_script( |
| 503 |
"basalam-admin-connect-modal-script", |
| 504 |
self::assetsUrl("js/connect-modal.js"), |
| 505 |
["jquery", "basalam-admin-toast-script"], |
| 506 |
$version, |
| 507 |
true |
| 508 |
); |
| 509 |
wp_enqueue_script( |
| 510 |
"basalam-get-category-script", |
| 511 |
self::assetsUrl("js/get-category.js"), |
| 512 |
["jquery", "basalam-admin-toast-script"], |
| 513 |
$version, |
| 514 |
true |
| 515 |
); |
| 516 |
wp_enqueue_script( |
| 517 |
"basalam-generate-product-variation-script", |
| 518 |
self::assetsUrl("js/generate-product-variation.js"), |
| 519 |
["jquery", "basalam-admin-toast-script"], |
| 520 |
$version, |
| 521 |
true |
| 522 |
); |
| 523 |
} |
| 524 |
|
| 525 |
if ($isMainPage || $isProductEditScreen) { |
| 526 |
wp_enqueue_script( |
| 527 |
"basalam-admin-manage-box-script", |
| 528 |
self::assetsUrl("js/manage-box.js"), |
| 529 |
["jquery", "basalam-admin-toast-script"], |
| 530 |
$version, |
| 531 |
true |
| 532 |
); |
| 533 |
} |
| 534 |
|
| 535 |
if ($isMainPage) { |
| 536 |
wp_enqueue_script( |
| 537 |
"basalam-map-category-option-script", |
| 538 |
self::assetsUrl("js/map-category-option.js"), |
| 539 |
["jquery", "basalam-admin-toast-script"], |
| 540 |
$version, |
| 541 |
true |
| 542 |
); |
| 543 |
} |
| 544 |
|
| 545 |
if ($isMainPage || $isProductScreen) { |
| 546 |
wp_enqueue_script( |
| 547 |
"basalam-round-script", |
| 548 |
self::assetsUrl("js/round.js"), |
| 549 |
["jquery", "basalam-admin-toast-script"], |
| 550 |
$version, |
| 551 |
true |
| 552 |
); |
| 553 |
} |
| 554 |
|
| 555 |
if ($isOrderScreen) { |
| 556 |
wp_enqueue_script( |
| 557 |
"basalam-order-script", |
| 558 |
self::assetsUrl("js/order.js"), |
| 559 |
["jquery", "basalam-admin-toast-script"], |
| 560 |
$version, |
| 561 |
true |
| 562 |
); |
| 563 |
} |
| 564 |
|
| 565 |
if ($isMainPage || $isOrderScreen) { |
| 566 |
wp_enqueue_script( |
| 567 |
"basalam-check-sync-script", |
| 568 |
self::assetsUrl("js/check-sync.js"), |
| 569 |
["jquery", "basalam-admin-toast-script"], |
| 570 |
$version, |
| 571 |
true |
| 572 |
); |
| 573 |
} |
| 574 |
|
| 575 |
if ($isPluginPage || $isProductScreen || $isOrderScreen || $shouldLoadPointerTour) { |
| 576 |
$adminScriptPath = syncBasalamPlugin()->pluginPath() . '/assets/js/admin.js'; |
| 577 |
$adminScriptVersion = file_exists($adminScriptPath) |
| 578 |
? $version . '-' . filemtime($adminScriptPath) |
| 579 |
: $version; |
| 580 |
wp_enqueue_script( |
| 581 |
"basalam-admin-script", |
| 582 |
self::assetsUrl("js/admin.js"), |
| 583 |
$shouldLoadPointerTour ? ["jquery", "wp-pointer", "basalam-admin-toast-script"] : ["jquery", "basalam-admin-toast-script"], |
| 584 |
$adminScriptVersion, |
| 585 |
true |
| 586 |
); |
| 587 |
} |
| 588 |
|
| 589 |
if (self::isTicketPage()) { |
| 590 |
$ticketScriptPath = syncBasalamPlugin()->pluginPath() . '/assets/js/ticket.js'; |
| 591 |
$ticketScriptVersion = file_exists($ticketScriptPath) |
| 592 |
? $version . '-' . filemtime($ticketScriptPath) |
| 593 |
: $version; |
| 594 |
wp_enqueue_script( |
| 595 |
"basalam-ticket-script", |
| 596 |
self::assetsUrl("js/ticket.js"), |
| 597 |
["basalam-admin-toast-script"], |
| 598 |
$ticketScriptVersion, |
| 599 |
true |
| 600 |
); |
| 601 |
} |
| 602 |
|
| 603 |
if ($shouldLoadPointerTour) { |
| 604 |
wp_localize_script('basalam-admin-script', 'basalamPointerTour', PointerTour::getPointerTourConfig()); |
| 605 |
} |
| 606 |
|
| 607 |
if (wp_script_is('basalam-admin-script', 'enqueued') && AnnouncementCenter::shouldLoadAnnouncement()) { |
| 608 |
wp_localize_script('basalam-admin-script', 'basalamAnnouncements', AnnouncementCenter::getConfig()); |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
public static function financialManagementEnqueueAssets($hook = '') |
| 613 |
{ |
| 614 |
$page = isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : ''; |
| 615 |
if ($page !== FinancialManagementMenu::PAGE_SLUG) { |
| 616 |
return; |
| 617 |
} |
| 618 |
|
| 619 |
$version = syncbasalamplugin()->getVersion(); |
| 620 |
|
| 621 |
wp_enqueue_style( |
| 622 |
'sync-basalam-finance-style', |
| 623 |
self::assetsUrl('css/finance.css'), |
| 624 |
[], |
| 625 |
$version |
| 626 |
); |
| 627 |
|
| 628 |
wp_enqueue_script( |
| 629 |
'sync-basalam-finance-history-pagination', |
| 630 |
self::assetsUrl('js/finance-history-pagination.js'), |
| 631 |
[], |
| 632 |
$version, |
| 633 |
true |
| 634 |
); |
| 635 |
|
| 636 |
wp_localize_script('sync-basalam-finance-history-pagination', 'syncBasalamHistoryPagination', [ |
| 637 |
'ajaxUrl' => admin_url('admin-ajax.php'), |
| 638 |
'action' => FinancialManagementHistory::AJAX_ACTION, |
| 639 |
'nonce' => wp_create_nonce(FinancialManagementHistory::AJAX_ACTION), |
| 640 |
'pageSlug' => FinancialManagementMenu::PAGE_SLUG, |
| 641 |
'errorMessage' => 'بارگذاری تاریخچه تسویه انجا� |
| 642 |
نشد.', |
| 643 |
]); |
| 644 |
|
| 645 |
wp_enqueue_script( |
| 646 |
'sync-basalam-finance-balance-settlement', |
| 647 |
self::assetsUrl('js/finance-balance-settlement.js'), |
| 648 |
[], |
| 649 |
$version, |
| 650 |
true |
| 651 |
); |
| 652 |
|
| 653 |
wp_localize_script('sync-basalam-finance-balance-settlement', 'syncBasalamBalanceSettlement', [ |
| 654 |
'ajaxUrl' => admin_url('admin-ajax.php'), |
| 655 |
'action' => BalanceSettlement::AJAX_ACTION, |
| 656 |
'bankAccountsAction' => BalanceSettlement::AJAX_ACTION_BANK_ACCOUNTS, |
| 657 |
'nonce' => wp_create_nonce(BalanceSettlement::AJAX_ACTION), |
| 658 |
'submitText' => 'ثبت درخواست', |
| 659 |
'loadingText' => 'در حال ارسال...', |
| 660 |
'errorMessage' => 'خطا در ثبت درخواست تسویه.', |
| 661 |
'successMessage' => 'درخواست تسویه با � |
| 662 |
وفقیت ثبت شد.', |
| 663 |
'amountError' => 'لطفاً � |
| 664 |
بلغ � |
| 665 |
عتبری وارد کنید.', |
| 666 |
'walletTitle' => 'انتقال به کیف پول', |
| 667 |
'bankTitle' => 'انتقال به حساب بانکی', |
| 668 |
'bankAccountsError' => 'خطا در دریافت لیست حسابهای بانکی.', |
| 669 |
]); |
| 670 |
} |
| 671 |
|
| 672 |
} |
| 673 |
|