feat: Implement upsell functionality with repository and service layers

This commit is contained in:
2026-05-02 23:30:23 +03:30
parent 4928901a08
commit 5930c1ad6f
26 changed files with 3130 additions and 126 deletions

170
admin/views/dashboard.php Normal file
View File

@@ -0,0 +1,170 @@
<?php
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
$summary = $dashboardData['summary'];
$salesChart = $dashboardData['sales_chart'];
$rulePerformance = $dashboardData['rule_performance'];
$userBehavior = $dashboardData['user_behavior'];
$insights = $dashboardData['insights'];
$current_page = sanitize_text_field($_GET['page'] ?? 'sodino-dashboard');
?>
<div id="sodino-app" class="min-h-screen bg-gray-50" dir="rtl">
<!-- Header -->
<div class="bg-white border-b border-gray-200">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="py-6">
<div class="flex items-center justify-between">
<div>
<h1 class="text-3xl font-bold text-gray-900"><?php _e('سودینو', 'sodino'); ?></h1>
<p class="mt-1 text-sm text-gray-500"><?php _e('بهینه‌سازی هوشمند فروش', 'sodino'); ?></p>
</div>
</div>
</div>
</div>
</div>
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<div class="flex gap-8">
<!-- Sidebar -->
<aside class="w-64 flex-shrink-0">
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<h2 class="text-lg font-semibold text-gray-900 mb-4"><?php _e('منوی سودینو', 'sodino'); ?></h2>
<nav class="space-y-2">
<a href="<?php echo admin_url('admin.php?page=sodino-dashboard'); ?>" class="block px-3 py-2 rounded-md text-sm font-medium <?php echo $current_page === 'sodino-dashboard' ? 'bg-blue-50 text-blue-700 border-r-2 border-blue-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'; ?>">
<?php _e('داشبورد', 'sodino'); ?>
</a>
<a href="<?php echo admin_url('admin.php?page=sodino-rules'); ?>" class="block px-3 py-2 rounded-md text-sm font-medium <?php echo $current_page === 'sodino-rules' ? 'bg-blue-50 text-blue-700 border-r-2 border-blue-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'; ?>">
<?php _e('قوانین', 'sodino'); ?>
</a>
<a href="<?php echo admin_url('admin.php?page=sodino-add-rule'); ?>" class="block px-3 py-2 rounded-md text-sm font-medium <?php echo $current_page === 'sodino-add-rule' ? 'bg-blue-50 text-blue-700 border-r-2 border-blue-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'; ?>">
<?php _e('افزودن قانون', 'sodino'); ?>
</a>
<a href="<?php echo admin_url('admin.php?page=sodino-upsells'); ?>" class="block px-3 py-2 rounded-md text-sm font-medium <?php echo $current_page === 'sodino-upsells' ? 'bg-blue-50 text-blue-700 border-r-2 border-blue-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'; ?>">
<?php _e('آپسل (پیشنهاد فروش)', 'sodino'); ?>
</a>
<a href="<?php echo admin_url('admin.php?page=sodino-add-upsell'); ?>" class="block px-3 py-2 rounded-md text-sm font-medium <?php echo $current_page === 'sodino-add-upsell' ? 'bg-blue-50 text-blue-700 border-r-2 border-blue-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'; ?>">
<?php _e('افزودن آپسل', 'sodino'); ?>
</a>
<a href="<?php echo admin_url('admin.php?page=sodino-competitor-price'); ?>" class="block px-3 py-2 rounded-md text-sm font-medium <?php echo $current_page === 'sodino-competitor-price' ? 'bg-blue-50 text-blue-700 border-r-2 border-blue-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'; ?>">
<?php _e('قیمت رقبا (به‌زودی)', 'sodino'); ?>
</a>
<a href="<?php echo admin_url('admin.php?page=sodino-settings'); ?>" class="block px-3 py-2 rounded-md text-sm font-medium <?php echo $current_page === 'sodino-settings' ? 'bg-blue-50 text-blue-700 border-r-2 border-blue-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'; ?>">
<?php _e('تنظیمات', 'sodino'); ?>
</a>
</nav>
</div>
</aside>
<!-- Main Content -->
<main class="flex-1 min-w-0">
<!-- Overview Card -->
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6 mb-8">
<h2 class="text-xl font-semibold text-gray-900 mb-2"><?php _e('نمای کلی داشبورد', 'sodino'); ?></h2>
<p class="text-gray-600"><?php _e('نمایش سریع KPIها، عملکرد قوانین و رفتار مشتریان.', 'sodino'); ?></p>
</div>
<!-- Stats Grid -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
<div class="bg-gradient-to-br from-blue-600 to-blue-700 rounded-lg p-6 text-white">
<h3 class="text-sm font-medium opacity-90"><?php _e('درآمد کل', 'sodino'); ?></h3>
<div class="text-2xl font-bold mt-2"><?php echo wc_price($summary['total_revenue']); ?></div>
</div>
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<h3 class="text-sm font-medium text-gray-600"><?php _e('میزان تخفیف داده شده', 'sodino'); ?></h3>
<div class="text-2xl font-bold text-gray-900 mt-2"><?php echo wc_price($summary['total_discount']); ?></div>
</div>
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<h3 class="text-sm font-medium text-gray-600"><?php _e('نرخ تبدیل تقریبی', 'sodino'); ?></h3>
<div class="text-2xl font-bold text-gray-900 mt-2"><?php echo esc_html($summary['conversion_rate']); ?>%</div>
</div>
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<h3 class="text-sm font-medium text-gray-600"><?php _e('بهترین قانون', 'sodino'); ?></h3>
<div class="text-2xl font-bold text-gray-900 mt-2"><?php echo esc_html($summary['best_rule'] ?? __('بدون داده', 'sodino')); ?></div>
</div>
</div>
<!-- Charts Grid -->
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6 mb-8">
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<h3 class="text-lg font-semibold text-gray-900 mb-4"><?php _e('نمودار فروش (قبل و بعد)', 'sodino'); ?></h3>
<div class="h-64">
<canvas id="sodinoSalesChart" class="w-full h-full"></canvas>
</div>
</div>
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<h3 class="text-lg font-semibold text-gray-900 mb-4"><?php _e('تاثیر تخفیف', 'sodino'); ?></h3>
<div class="h-64">
<canvas id="sodinoDiscountChart" class="w-full h-full"></canvas>
</div>
</div>
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<h3 class="text-lg font-semibold text-gray-900 mb-4"><?php _e('عملکرد قوانین', 'sodino'); ?></h3>
<div class="h-64">
<canvas id="sodinoRuleChart" class="w-full h-full"></canvas>
</div>
</div>
</div>
<!-- User Behavior and Insights -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<h3 class="text-lg font-semibold text-gray-900 mb-4"><?php _e('رفتار کاربران', 'sodino'); ?></h3>
<div class="grid grid-cols-2 gap-4">
<div class="bg-gray-50 rounded-lg p-4">
<div class="text-sm font-medium text-gray-600"><?php _e('بازدید محصول', 'sodino'); ?></div>
<div class="text-2xl font-bold text-gray-900 mt-1"><?php echo esc_html($userBehavior['product_views']); ?></div>
</div>
<div class="bg-gray-50 rounded-lg p-4">
<div class="text-sm font-medium text-gray-600"><?php _e('افزودن به سبد', 'sodino'); ?></div>
<div class="text-2xl font-bold text-gray-900 mt-1"><?php echo esc_html($userBehavior['add_to_cart']); ?></div>
</div>
<div class="bg-gray-50 rounded-lg p-4">
<div class="text-sm font-medium text-gray-600"><?php _e('شروع پرداخت', 'sodino'); ?></div>
<div class="text-2xl font-bold text-gray-900 mt-1"><?php echo esc_html($userBehavior['checkout_start']); ?></div>
</div>
<div class="bg-gray-50 rounded-lg p-4">
<div class="text-sm font-medium text-gray-600"><?php _e('خرید', 'sodino'); ?></div>
<div class="text-2xl font-bold text-gray-900 mt-1"><?php echo esc_html($userBehavior['purchases']); ?></div>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<h3 class="text-lg font-semibold text-gray-900 mb-4"><?php _e('بینش‌ها', 'sodino'); ?></h3>
<div class="space-y-3">
<?php foreach ($insights as $insight) : ?>
<div class="bg-gray-50 rounded-lg p-4">
<div class="text-sm text-gray-600"><?php echo esc_html($insight); ?></div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</main>
</div>
</div>
</div>
<script id="sodino-dashboard-data" type="application/json">
<?php echo wp_json_encode([
'salesChart' => $salesChart,
'summary' => $summary,
'rulePerformance' => [
'names' => array_column($rulePerformance, 'name'),
'revenue' => array_column($rulePerformance, 'revenue'),
'discount' => array_column($rulePerformance, 'discount'),
],
'translations' => [
'afterApplying' => __('پس از اعمال سودینو', 'sodino'),
'beforeApplying' => __('قبل از اعمال سودینو', 'sodino'),
'totalDiscount' => __('مجموع تخفیف', 'sodino'),
'totalRevenue' => __('درآمد پس از تخفیف', 'sodino'),
'discountEffect' => __('تاثیر تخفیف', 'sodino'),
'ruleRevenue' => __('درآمد ایجاد شده', 'sodino'),
'ruleDiscount' => __('تخفیف ثبت شده', 'sodino'),
],
], JSON_UNESCAPED_UNICODE); ?>
</script>