feat(shop): complete storefront archive, seller edit, revenue

Wire product cat/tag archives to settings-driven sort and AJAX paging,
seller product options/video/params editing, revenue withdraw form and
order review submit — finishing remaining shop frontend gaps after buy-path.
This commit is contained in:
kate522 committed 2026-07-12 10:38:02 +08:00
1 parent 5a8f08db8a
commit f3db6c89cc
17 files changed
+1024 -248

No files matched your search

+2 -2
View File
@@ -92,7 +92,7 @@ $tabs = [
<div class="aksrt-orders-page__card-items">
<?php if (!empty($items)) : ?>
<?php foreach ($items as $item) : ?>
<div class="aksrt-orders-page__card-item">
<div class="aksrt-orders-page__card-item" data-product-id="<?php echo esc_attr((string) ($item['product_id'] ?? 0)); ?>">
<?php if (!empty($item['image'])) : ?>
<img src="<?php echo esc_url((string) $item['image']); ?>" alt="" class="aksrt-orders-page__card-img">
<?php endif; ?>
@@ -109,7 +109,7 @@ $tabs = [
</div>
<?php endforeach; ?>
<?php else : ?>
<div class="aksrt-orders-page__card-item">
<div class="aksrt-orders-page__card-item" data-product-id="<?php echo esc_attr((string) ($item['product_id'] ?? 0)); ?>">
<span class="aksrt-orders-page__card-item-title"><?php echo esc_html((string) ($order['product_name'] ?? __('商品订单', 'aksrt'))); ?></span>
<strong>¥<?php echo esc_html(number_format((float) ($order['amount'] ?? 0), 2)); ?></strong>
</div>
+42
View File
@@ -91,7 +91,49 @@ $product = (array) ($edit_view['product'] ?? []);
</label>
</div>
<div class="aksrt-product-editor__panel">
<h2><?php esc_html_e('规格选项', 'aksrt'); ?></h2>
<p class="aksrt-product-editor__hint"><?php esc_html_e('每行一组:规格名|选项1:加价,选项2:加价。例如:颜色|红:0,蓝:10', 'aksrt'); ?></p>
<label class="aksrt-product-editor__field">
<span><?php esc_html_e('规格配置', 'aksrt'); ?></span>
<textarea name="options_text" class="aksrt-product-editor__textarea" rows="6" data-aksrt-options-text placeholder="颜色|红:0,蓝:10&#10;尺码|M:0,L:5"><?php
$opt_lines = [];
foreach ((array) ($product['options'] ?? []) as $group) {
$vals = [];
foreach ((array) ($group['values'] ?? []) as $v) {
$vals[] = (string) ($v['label'] ?? '') . ':' . (string) ($v['price_change'] ?? 0);
}
if (!empty($group['name']) && $vals) {
$opt_lines[] = (string) $group['name'] . '|' . implode(',', $vals);
}
}
echo esc_textarea(implode("\n", $opt_lines));
?></textarea>
</label>
<div class="aksrt-product-editor__columns">
<label class="aksrt-product-editor__field">
<span><?php esc_html_e('起售价', 'aksrt'); ?></span>
<input type="number" name="start_price" class="aksrt-product-editor__input" min="0" step="0.01" value="<?php echo esc_attr((string) ($product['start_price'] ?? 0)); ?>">
</label>
<label class="aksrt-product-editor__field">
<span><?php esc_html_e('支付模式', 'aksrt'); ?></span>
<select name="pay_modo" class="aksrt-product-editor__input">
<option value="0" <?php selected((string) ($product['pay_modo'] ?? '0'), '0'); ?>><?php esc_html_e('现金', 'aksrt'); ?></option>
<option value="points" <?php selected((string) ($product['pay_modo'] ?? '0'), 'points'); ?>><?php esc_html_e('积分', 'aksrt'); ?></option>
</select>
</label>
</div>
<label class="aksrt-product-editor__field">
<span><?php esc_html_e('商品参数(每行 名称:值)', 'aksrt'); ?></span>
<textarea name="product_params" class="aksrt-product-editor__textarea" rows="4"><?php echo esc_textarea((string) ($product['product_params'] ?? '')); ?></textarea>
</label>
<label class="aksrt-product-editor__field">
<span><?php esc_html_e('视频地址(每行一个 URL)', 'aksrt'); ?></span>
<textarea name="product_video" class="aksrt-product-editor__textarea" rows="3"><?php echo esc_textarea(implode("\n", (array) ($product['product_video'] ?? []))); ?></textarea>
</label>
</div>
<div class="aksrt-product-editor__panel">
<h2><?php esc_html_e('发货与售后', 'aksrt'); ?></h2>
<div class="aksrt-product-editor__columns">
<label class="aksrt-product-editor__field">
+140 -95
View File
@@ -3,7 +3,7 @@
* Template Name: AKSRT - Revenue
* Template Post Type: page
*
* 创作者收益中心页面 — 显示收益概览、分成记录和提现入口
* Creator revenue center: overview, ledger, withdraw request.
*
* @package AKSRT
*/
@@ -13,115 +13,160 @@ defined('ABSPATH') || exit;
get_header();
if (!is_user_logged_in()) {
$login_url = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(get_permalink());
wp_safe_redirect($login_url);
exit;
$login_url = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(get_permalink());
wp_safe_redirect($login_url);
exit;
}
$user_id = get_current_user_id();
// 通过 helper 获取收益视图模型
$revenue_view = function_exists('aksrt_get_revenue_page_view')
? aksrt_get_revenue_page_view($user_id)
: ['balance' => 0, 'total_earned' => 0, 'total_withdrawn' => 0, 'records' => []];
? aksrt_get_revenue_page_view($user_id)
: ['balance' => 0, 'total_earned' => 0, 'total_withdrawn' => 0, 'records' => []];
$balance = (float) ($revenue_view['balance'] ?? 0);
$total_earned = (float) ($revenue_view['total_earned'] ?? 0);
$balance = (float) ($revenue_view['balance'] ?? 0);
$total_earned = (float) ($revenue_view['total_earned'] ?? 0);
$total_withdrawn = (float) ($revenue_view['total_withdrawn'] ?? 0);
$records = $revenue_view['records'] ?? [];
$records = $revenue_view['records'] ?? [];
$per_page = 20;
$paged = max(1, (int) ($_GET['rev_page'] ?? 1));
$settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_withdrawal_settings() : [];
$min_amount = (float) ($settings['min_amount'] ?? 50);
$fee_rate = (float) ($settings['service_charge_rate'] ?? 0);
$withdraw_text = (string) ($settings['text'] ?? '');
$withdrawals = [];
if (class_exists('AKSRT_Withdrawal')) {
$withdrawals = AKSRT_Withdrawal::get_instance()->get_user_withdrawals($user_id, ['limit' => 20]);
}
$per_page = 20;
$paged = max(1, (int) ($_GET['rev_page'] ?? 1));
$total_records = count($records);
$total_pages = max(1, (int) ceil($total_records / $per_page));
$total_pages = max(1, (int) ceil(max(1, $total_records) / $per_page));
if ($total_records === 0) {
$total_pages = 1;
}
$paged_records = array_slice($records, ($paged - 1) * $per_page, $per_page);
?>
<div class="container aksrt-revenue-page">
<div class="aksrt-revenue-page__header">
<h2><?php esc_html_e('创作收益', 'aksrt'); ?></h2>
</div>
<main id="main-content" class="site-main content-shell" tabindex="-1">
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
<!-- 收益概览 -->
<div class="aksrt-revenue-page__stats">
<div class="aksrt-revenue-page__stat-card">
<div class="aksrt-revenue-page__stat-icon"><i class="fas fa-wallet"></i></div>
<div class="aksrt-revenue-page__stat-info">
<span class="aksrt-revenue-page__stat-value">¥<?php echo esc_html(number_format($balance, 2)); ?></span>
<span class="aksrt-revenue-page__stat-label"><?php esc_html_e('可提现余额', 'aksrt'); ?></span>
</div>
</div>
<div class="aksrt-revenue-page__stat-card">
<div class="aksrt-revenue-page__stat-icon"><i class="fas fa-chart-line"></i></div>
<div class="aksrt-revenue-page__stat-info">
<span class="aksrt-revenue-page__stat-value">¥<?php echo esc_html(number_format($total_earned, 2)); ?></span>
<span class="aksrt-revenue-page__stat-label"><?php esc_html_e('累计收益', 'aksrt'); ?></span>
</div>
</div>
<div class="aksrt-revenue-page__stat-card">
<div class="aksrt-revenue-page__stat-icon"><i class="fas fa-money-check-alt"></i></div>
<div class="aksrt-revenue-page__stat-info">
<span class="aksrt-revenue-page__stat-value">¥<?php echo esc_html(number_format($total_withdrawn, 2)); ?></span>
<span class="aksrt-revenue-page__stat-label"><?php esc_html_e('已提现', 'aksrt'); ?></span>
</div>
</div>
</div>
<div class="container aksrt-revenue-page" data-aksrt-revenue-page
data-min-amount="<?php echo esc_attr((string) $min_amount); ?>"
data-fee-rate="<?php echo esc_attr((string) $fee_rate); ?>">
<div class="aksrt-revenue-page__header">
<h1><?php esc_html_e('创作收益', 'aksrt'); ?></h1>
<p class="aksrt-revenue-page__subtitle"><?php esc_html_e('查看分成明细并发起提现。', 'aksrt'); ?></p>
</div>
<!-- 提现按钮 -->
<?php if ($balance > 0) : ?>
<div class="aksrt-revenue-page__actions">
<a href="<?php echo esc_url(add_query_arg(['action' => 'withdraw'])); ?>" class="aksrt-revenue-page__withdraw-btn">
<i class="fas fa-hand-holding-usd"></i> <?php esc_html_e('申请提现', 'aksrt'); ?>
</a>
</div>
<?php endif; ?>
<div class="aksrt-revenue-page__stats">
<div class="aksrt-revenue-page__stat-card">
<div class="aksrt-revenue-page__stat-icon"><i class="fas fa-wallet"></i></div>
<div class="aksrt-revenue-page__stat-info">
<span class="aksrt-revenue-page__stat-value" data-aksrt-revenue-balance>¥<?php echo esc_html(number_format($balance, 2)); ?></span>
<span class="aksrt-revenue-page__stat-label"><?php esc_html_e('可提现余额', 'aksrt'); ?></span>
</div>
</div>
<div class="aksrt-revenue-page__stat-card">
<div class="aksrt-revenue-page__stat-icon"><i class="fas fa-chart-line"></i></div>
<div class="aksrt-revenue-page__stat-info">
<span class="aksrt-revenue-page__stat-value">¥<?php echo esc_html(number_format($total_earned, 2)); ?></span>
<span class="aksrt-revenue-page__stat-label"><?php esc_html_e('累计收益', 'aksrt'); ?></span>
</div>
</div>
<div class="aksrt-revenue-page__stat-card">
<div class="aksrt-revenue-page__stat-icon"><i class="fas fa-money-check-alt"></i></div>
<div class="aksrt-revenue-page__stat-info">
<span class="aksrt-revenue-page__stat-value">¥<?php echo esc_html(number_format($total_withdrawn, 2)); ?></span>
<span class="aksrt-revenue-page__stat-label"><?php esc_html_e('已提现', 'aksrt'); ?></span>
</div>
</div>
</div>
<!-- 分成记录 -->
<div class="aksrt-revenue-page__section">
<h3><?php esc_html_e('收益明细', 'aksrt'); ?></h3>
<div class="aksrt-revenue-page__layout">
<section class="aksrt-revenue-page__panel">
<h2><?php esc_html_e('申请提现', 'aksrt'); ?></h2>
<?php if ($withdraw_text !== '') : ?>
<div class="aksrt-revenue-page__note"><?php echo wp_kses_post(wpautop($withdraw_text)); ?></div>
<?php endif; ?>
<form class="aksrt-revenue-page__withdraw-form" data-aksrt-withdraw-form>
<label>
<span><?php esc_html_e('提现金额', 'aksrt'); ?></span>
<input type="number" name="amount" min="<?php echo esc_attr((string) $min_amount); ?>" step="0.01" required>
</label>
<label>
<span><?php esc_html_e('提现方式', 'aksrt'); ?></span>
<select name="method">
<option value="alipay"><?php esc_html_e('支付宝', 'aksrt'); ?></option>
<option value="wechat"><?php esc_html_e('微信', 'aksrt'); ?></option>
<option value="bank"><?php esc_html_e('银行卡', 'aksrt'); ?></option>
</select>
</label>
<label>
<span><?php esc_html_e('收款账户信息', 'aksrt'); ?></span>
<textarea name="account_info" rows="3" required></textarea>
</label>
<p class="aksrt-revenue-page__fee-hint"><?php printf(esc_html__('手续费 %s%%', 'aksrt'), esc_html((string) $fee_rate)); ?></p>
<button type="submit" class="btn-primary"><?php esc_html_e('提交提现申请', 'aksrt'); ?></button>
<p class="aksrt-revenue-page__form-msg" data-aksrt-withdraw-msg hidden></p>
</form>
</section>
<?php if (!empty($paged_records)) : ?>
<div class="aksrt-revenue-page__list">
<?php foreach ($paged_records as $record) :
$r_type = (string) ($record['type'] ?? 'earning');
?>
<div class="aksrt-revenue-page__item">
<div class="aksrt-revenue-page__item-icon">
<i class="<?php echo $r_type === 'withdrawal' ? 'fas fa-arrow-up' : 'fas fa-arrow-down'; ?>"
style="color: <?php echo $r_type === 'withdrawal' ? '#f5222d' : '#52c41a'; ?>;"></i>
</div>
<div class="aksrt-revenue-page__item-info">
<span class="aksrt-revenue-page__item-title"><?php echo esc_html($record['title'] ?? ''); ?></span>
<span class="aksrt-revenue-page__item-time"><?php echo esc_html($record['created_at'] ?? ''); ?></span>
</div>
<div class="aksrt-revenue-page__item-amount" style="color: <?php echo $r_type === 'withdrawal' ? '#f5222d' : '#52c41a'; ?>;">
<?php echo $r_type === 'withdrawal' ? '-' : '+'; ?>¥<?php echo esc_html(number_format((float) ($record['amount'] ?? 0), 2)); ?>
</div>
</div>
<?php endforeach; ?>
</div>
<section class="aksrt-revenue-page__panel">
<h2><?php esc_html_e('提现记录', 'aksrt'); ?></h2>
<?php if (!empty($withdrawals)) : ?>
<div class="aksrt-revenue-page__list" data-aksrt-withdraw-list>
<?php foreach ($withdrawals as $w) : ?>
<div class="aksrt-revenue-page__item">
<div>
<strong>¥<?php echo esc_html(number_format((float) ($w['amount'] ?? 0), 2)); ?></strong>
<span><?php echo esc_html((string) ($w['method'] ?? '')); ?></span>
</div>
<div>
<span><?php echo esc_html((string) ($w['status'] ?? '')); ?></span>
<time><?php echo esc_html((string) ($w['created_at'] ?? '')); ?></time>
</div>
</div>
<?php endforeach; ?>
</div>
<?php else : ?>
<p class="aksrt-revenue-page__empty"><?php esc_html_e('暂无提现记录', 'aksrt'); ?></p>
<?php endif; ?>
</section>
</div>
<?php if ($total_pages > 1) : ?>
<div class="aksrt-revenue-page__pagination">
<?php for ($i = 1; $i <= $total_pages; $i++) :
$page_url = add_query_arg(['rev_page' => $i]);
?>
<?php if ($i === $paged) : ?>
<span class="aksrt-revenue-page__page-chip is-active"><?php echo esc_html((string) $i); ?></span>
<?php else : ?>
<a href="<?php echo esc_url($page_url); ?>" class="aksrt-revenue-page__page-chip"><?php echo esc_html((string) $i); ?></a>
<?php endif; ?>
<?php endfor; ?>
</div>
<?php endif; ?>
<?php else : ?>
<div class="aksrt-revenue-page__empty">
<i class="fas fa-chart-pie"></i>
<p><?php esc_html_e('暂无收益记录', 'aksrt'); ?></p>
</div>
<?php endif; ?>
</div>
<section class="aksrt-revenue-page__section">
<h2><?php esc_html_e('收益明细', 'aksrt'); ?></h2>
<?php if (!empty($paged_records)) : ?>
<div class="aksrt-revenue-page__list">
<?php foreach ($paged_records as $rec) : ?>
<div class="aksrt-revenue-page__item">
<div>
<strong><?php echo esc_html((string) ($rec['title'] ?? '')); ?></strong>
<time><?php echo esc_html((string) ($rec['created_at'] ?? '')); ?></time>
</div>
<span class="<?php echo (($rec['type'] ?? '') === 'withdrawal') ? 'is-out' : 'is-in'; ?>">
<?php echo (($rec['type'] ?? '') === 'withdrawal') ? '-' : '+'; ?>¥<?php echo esc_html(number_format((float) ($rec['amount'] ?? 0), 2)); ?>
</span>
</div>
<?php endforeach; ?>
</div>
<?php if ($total_pages > 1 && $total_records > 0) : ?>
<nav class="aksrt-revenue-page__pagination">
<?php for ($i = 1; $i <= $total_pages; $i++) :
$url = add_query_arg(['rev_page' => $i]);
?>
<a class="<?php echo $i === $paged ? 'is-active' : ''; ?>" href="<?php echo esc_url($url); ?>"><?php echo (int) $i; ?></a>
<?php endfor; ?>
</nav>
<?php endif; ?>
<?php else : ?>
<p class="aksrt-revenue-page__empty"><?php esc_html_e('暂无收益明细', 'aksrt'); ?></p>
<?php endif; ?>
</section>
</div>
</main>
<?php get_footer(); ?>
<?php
wp_enqueue_script('aksrt-revenue', get_template_directory_uri() . '/assets/js/revenue.js', ['aksrt-script'], AKSRT_VERSION, true);
get_footer();
+83 -34
View File
@@ -11,56 +11,98 @@ get_header();
$term = get_queried_object();
$paged = max(1, (int) get_query_var('paged'));
$orderby = isset($_GET['shop_orderby']) ? sanitize_key(wp_unslash((string) $_GET['shop_orderby'])) : '';
$shop = class_exists('AKSRT_Shop') ? AKSRT_Shop::get_instance() : null;
$view = $shop ? $shop->get_product_archive_view([
'taxonomy' => 'aksrt_product_cat',
'term_id' => $term->term_id,
'term_id' => $term ? (int) $term->term_id : 0,
'paged' => $paged,
]) : ['products' => [], 'term' => null, 'total' => 0, 'max_pages' => 0];
'orderby' => $orderby,
]) : ['products' => [], 'term' => null, 'total' => 0, 'max_pages' => 0, 'orderby' => 'date', 'paging' => 'number'];
$products = $view['products'];
$total = $view['total'];
$max_pages = $view['max_pages'];
$products = $view['products'] ?? [];
$total = (int) ($view['total'] ?? 0);
$max_pages = (int) ($view['max_pages'] ?? 0);
$term_name = $term->name ?? '';
$term_desc = $term->description ?? '';
$active_orderby = (string) ($view['orderby'] ?? 'date');
$paging = (string) ($view['paging'] ?? 'number');
$ias_s = !empty($view['ias_s']);
$ias_max = (int) ($view['ias_max'] ?? 5);
$style = (string) ($view['style'] ?? 'default');
$sales_cfg = is_array($view['sales'] ?? null) ? $view['sales'] : [];
$order_options = [
'date' => __('最新', 'aksrt'),
'sales' => __('销量', 'aksrt'),
'price_asc' => __('价格升序', 'aksrt'),
'price_desc' => __('价格降序', 'aksrt'),
'comments' => __('评价', 'aksrt'),
];
?>
<main id="main-content" class="site-main content-shell" tabindex="-1">
<?php if (function_exists('aksrt_breadcrumbs')) aksrt_breadcrumbs(); ?>
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
<div class="aksrt-product-archive container"
data-aksrt-product-archive
data-taxonomy="aksrt_product_cat"
data-term-id="<?php echo esc_attr((string) ($term->term_id ?? 0)); ?>"
data-orderby="<?php echo esc_attr($active_orderby); ?>"
data-page="<?php echo esc_attr((string) $paged); ?>"
data-max-pages="<?php echo esc_attr((string) $max_pages); ?>"
data-paging="<?php echo esc_attr($paging); ?>"
data-ias="<?php echo $ias_s ? '1' : '0'; ?>"
data-ias-max="<?php echo esc_attr((string) $ias_max); ?>"
data-style="<?php echo esc_attr($style); ?>">
<div class="aksrt-product-archive container">
<header class="aksrt-product-archive__header">
<div class="aksrt-product-archive__eyebrow"><?php esc_html_e('商城商品', 'aksrt'); ?></div>
<h1 class="aksrt-product-archive__title"><?php echo esc_html($term_name); ?></h1>
<?php if ($term_desc) : ?>
<p class="aksrt-product-archive__desc"><?php echo esc_html($term_desc); ?></p>
<?php endif; ?>
<p class="aksrt-product-archive__count"><?php printf(esc_html__('共 %d 件商品', 'aksrt'), $total); ?></p>
<p class="aksrt-product-archive__count" data-aksrt-archive-count><?php printf(esc_html__('共 %d 件商品', 'aksrt'), $total); ?></p>
</header>
<nav class="aksrt-product-archive__toolbar" aria-label="<?php esc_attr_e('商品排序', 'aksrt'); ?>">
<?php foreach ($order_options as $key => $label) :
$url = add_query_arg(['shop_orderby' => $key]);
?>
<a class="aksrt-product-archive__sort<?php echo $active_orderby === $key ? ' is-active' : ''; ?>"
href="<?php echo esc_url($url); ?>"
data-aksrt-shop-orderby="<?php echo esc_attr($key); ?>">
<?php echo esc_html($label); ?>
</a>
<?php endforeach; ?>
</nav>
<?php if (!empty($products)) : ?>
<div class="aksrt-product-archive__grid" id="aksrt-product-grid">
<?php foreach ($products as $product) : ?>
<div class="aksrt-product-archive__grid aksrt-product-archive__grid--<?php echo esc_attr($style); ?>" id="aksrt-product-grid" data-aksrt-product-grid>
<?php foreach ($products as $product) :
$sales = (int) ($product['sales'] ?? 0);
$mode = (string) ($sales_cfg['show'] ?? 'show');
$min_sales = max(0, (int) ($sales_cfg['show_min'] ?? 0));
$show_sales = ($mode === 'show' && $sales > 0) || ($mode === 'threshold' && $sales >= $min_sales);
?>
<article class="aksrt-product-card">
<a href="<?php echo esc_url($product['permalink']); ?>" class="aksrt-product-card__link">
<?php if ($product['image']) : ?>
<a href="<?php echo esc_url((string) ($product['permalink'] ?? '#')); ?>" class="aksrt-product-card__link">
<?php if (!empty($product['image'])) : ?>
<div class="aksrt-product-card__image">
<img src="<?php echo esc_url($product['image']); ?>" alt="<?php echo esc_attr($product['title']); ?>"<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('other') : ' loading="lazy"'; ?>>
<img src="<?php echo esc_url((string) $product['image']); ?>" alt="<?php echo esc_attr((string) ($product['title'] ?? '')); ?>" loading="lazy">
</div>
<?php else : ?>
<div class="aksrt-product-card__image aksrt-product-card__image--placeholder">
<i class="fas fa-image"></i>
</div>
<div class="aksrt-product-card__image aksrt-product-card__image--placeholder"><i class="fas fa-image"></i></div>
<?php endif; ?>
<div class="aksrt-product-card__body">
<h3 class="aksrt-product-card__title"><?php echo esc_html($product['title']); ?></h3>
<?php if ($product['excerpt']) : ?>
<p class="aksrt-product-card__excerpt"><?php echo esc_html(wp_trim_words($product['excerpt'], 15)); ?></p>
<h3 class="aksrt-product-card__title"><?php echo esc_html((string) ($product['title'] ?? '')); ?></h3>
<?php if (!empty($product['excerpt'])) : ?>
<p class="aksrt-product-card__excerpt"><?php echo esc_html(wp_trim_words((string) $product['excerpt'], 15)); ?></p>
<?php endif; ?>
<div class="aksrt-product-card__footer">
<span class="aksrt-product-card__price">¥<?php echo esc_html(number_format($product['price'], 2)); ?></span>
<?php if ($product['sales'] > 0) : ?>
<span class="aksrt-product-card__sales"><?php printf(esc_html__('已售 %d', 'aksrt'), $product['sales']); ?></span>
<span class="aksrt-product-card__price">¥<?php echo esc_html(number_format((float) ($product['price'] ?? 0), 2)); ?></span>
<?php if ($show_sales) : ?>
<span class="aksrt-product-card__sales"><?php printf(esc_html__('已售 %d', 'aksrt'), $sales); ?></span>
<?php endif; ?>
</div>
</div>
@@ -70,26 +112,33 @@ $term_desc = $term->description ?? '';
</div>
<?php if ($max_pages > 1) : ?>
<nav class="aksrt-product-archive__pagination" aria-label="<?php esc_attr_e('商品分页', 'aksrt'); ?>">
<?php
echo paginate_links([
'total' => $max_pages,
'current' => $paged,
'prev_text' => '<i class="fas fa-chevron-left"></i>',
'next_text' => '<i class="fas fa-chevron-right"></i>',
]);
?>
</nav>
<?php if ($paging === 'ajax') : ?>
<div class="aksrt-product-archive__load-more">
<button type="button" class="aksrt-load-more-btn" data-aksrt-shop-load-more><?php esc_html_e('加载更多', 'aksrt'); ?></button>
</div>
<?php else : ?>
<nav class="aksrt-product-archive__pagination" aria-label="<?php esc_attr_e('商品分页', 'aksrt'); ?>">
<?php
echo paginate_links([
'total' => $max_pages,
'current' => $paged,
'prev_text' => '<i class="fas fa-chevron-left"></i>',
'next_text' => '<i class="fas fa-chevron-right"></i>',
'add_args' => $active_orderby ? ['shop_orderby' => $active_orderby] : [],
]);
?>
</nav>
<?php endif; ?>
<?php endif; ?>
<?php else : ?>
<div class="aksrt-product-archive__empty">
<i class="fas fa-box-open"></i>
<p><?php esc_html_e('该分类下暂无商品', 'aksrt'); ?></p>
<p><?php esc_html_e('内容空空如也', 'aksrt'); ?></p>
</div>
<?php endif; ?>
</div>
</main>
<?php
wp_enqueue_script('aksrt-product-archive', get_template_directory_uri() . '/assets/js/product-archive.js', [], AKSRT_VERSION, true);
wp_enqueue_script('aksrt-product-archive', get_template_directory_uri() . '/assets/js/product-archive.js', ['aksrt-script'], AKSRT_VERSION, true);
get_footer();
+88 -38
View File
@@ -11,55 +11,98 @@ get_header();
$term = get_queried_object();
$paged = max(1, (int) get_query_var('paged'));
$orderby = isset($_GET['shop_orderby']) ? sanitize_key(wp_unslash((string) $_GET['shop_orderby'])) : '';
$shop = class_exists('AKSRT_Shop') ? AKSRT_Shop::get_instance() : null;
$view = $shop ? $shop->get_product_archive_view([
'taxonomy' => 'aksrt_product_tag',
'term_id' => $term->term_id,
'term_id' => $term ? (int) $term->term_id : 0,
'paged' => $paged,
]) : ['products' => [], 'term' => null, 'total' => 0, 'max_pages' => 0];
'orderby' => $orderby,
]) : ['products' => [], 'term' => null, 'total' => 0, 'max_pages' => 0, 'orderby' => 'date', 'paging' => 'number'];
$products = $view['products'];
$total = $view['total'];
$max_pages = $view['max_pages'];
$products = $view['products'] ?? [];
$total = (int) ($view['total'] ?? 0);
$max_pages = (int) ($view['max_pages'] ?? 0);
$term_name = $term->name ?? '';
$term_desc = $term->description ?? '';
$active_orderby = (string) ($view['orderby'] ?? 'date');
$paging = (string) ($view['paging'] ?? 'number');
$ias_s = !empty($view['ias_s']);
$ias_max = (int) ($view['ias_max'] ?? 5);
$style = (string) ($view['style'] ?? 'default');
$sales_cfg = is_array($view['sales'] ?? null) ? $view['sales'] : [];
$order_options = [
'date' => __('最新', 'aksrt'),
'sales' => __('销量', 'aksrt'),
'price_asc' => __('价格升序', 'aksrt'),
'price_desc' => __('价格降序', 'aksrt'),
'comments' => __('评价', 'aksrt'),
];
?>
<main id="main-content" class="site-main content-shell" tabindex="-1">
<?php if (function_exists('aksrt_breadcrumbs')) aksrt_breadcrumbs(); ?>
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
<div class="aksrt-product-archive container"
data-aksrt-product-archive
data-taxonomy="aksrt_product_tag"
data-term-id="<?php echo esc_attr((string) ($term->term_id ?? 0)); ?>"
data-orderby="<?php echo esc_attr($active_orderby); ?>"
data-page="<?php echo esc_attr((string) $paged); ?>"
data-max-pages="<?php echo esc_attr((string) $max_pages); ?>"
data-paging="<?php echo esc_attr($paging); ?>"
data-ias="<?php echo $ias_s ? '1' : '0'; ?>"
data-ias-max="<?php echo esc_attr((string) $ias_max); ?>"
data-style="<?php echo esc_attr($style); ?>">
<div class="aksrt-product-archive container">
<header class="aksrt-product-archive__header">
<div class="aksrt-product-archive__eyebrow"><?php esc_html_e('商品标签', 'aksrt'); ?></div>
<h1 class="aksrt-product-archive__title">
<i class="fas fa-tag"></i>
<?php echo esc_html($term_name); ?>
</h1>
<p class="aksrt-product-archive__count"><?php printf(esc_html__('共 %d 件商品', 'aksrt'), $total); ?></p>
<h1 class="aksrt-product-archive__title"><?php echo esc_html($term_name); ?></h1>
<?php if ($term_desc) : ?>
<p class="aksrt-product-archive__desc"><?php echo esc_html($term_desc); ?></p>
<?php endif; ?>
<p class="aksrt-product-archive__count" data-aksrt-archive-count><?php printf(esc_html__('共 %d 件商品', 'aksrt'), $total); ?></p>
</header>
<nav class="aksrt-product-archive__toolbar" aria-label="<?php esc_attr_e('商品排序', 'aksrt'); ?>">
<?php foreach ($order_options as $key => $label) :
$url = add_query_arg(['shop_orderby' => $key]);
?>
<a class="aksrt-product-archive__sort<?php echo $active_orderby === $key ? ' is-active' : ''; ?>"
href="<?php echo esc_url($url); ?>"
data-aksrt-shop-orderby="<?php echo esc_attr($key); ?>">
<?php echo esc_html($label); ?>
</a>
<?php endforeach; ?>
</nav>
<?php if (!empty($products)) : ?>
<div class="aksrt-product-archive__grid" id="aksrt-product-grid">
<?php foreach ($products as $product) : ?>
<div class="aksrt-product-archive__grid aksrt-product-archive__grid--<?php echo esc_attr($style); ?>" id="aksrt-product-grid" data-aksrt-product-grid>
<?php foreach ($products as $product) :
$sales = (int) ($product['sales'] ?? 0);
$mode = (string) ($sales_cfg['show'] ?? 'show');
$min_sales = max(0, (int) ($sales_cfg['show_min'] ?? 0));
$show_sales = ($mode === 'show' && $sales > 0) || ($mode === 'threshold' && $sales >= $min_sales);
?>
<article class="aksrt-product-card">
<a href="<?php echo esc_url($product['permalink']); ?>" class="aksrt-product-card__link">
<?php if ($product['image']) : ?>
<a href="<?php echo esc_url((string) ($product['permalink'] ?? '#')); ?>" class="aksrt-product-card__link">
<?php if (!empty($product['image'])) : ?>
<div class="aksrt-product-card__image">
<img src="<?php echo esc_url($product['image']); ?>" alt="<?php echo esc_attr($product['title']); ?>"<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('other') : ' loading="lazy"'; ?>>
<img src="<?php echo esc_url((string) $product['image']); ?>" alt="<?php echo esc_attr((string) ($product['title'] ?? '')); ?>" loading="lazy">
</div>
<?php else : ?>
<div class="aksrt-product-card__image aksrt-product-card__image--placeholder">
<i class="fas fa-image"></i>
</div>
<div class="aksrt-product-card__image aksrt-product-card__image--placeholder"><i class="fas fa-image"></i></div>
<?php endif; ?>
<div class="aksrt-product-card__body">
<h3 class="aksrt-product-card__title"><?php echo esc_html($product['title']); ?></h3>
<?php if ($product['excerpt']) : ?>
<p class="aksrt-product-card__excerpt"><?php echo esc_html(wp_trim_words($product['excerpt'], 15)); ?></p>
<h3 class="aksrt-product-card__title"><?php echo esc_html((string) ($product['title'] ?? '')); ?></h3>
<?php if (!empty($product['excerpt'])) : ?>
<p class="aksrt-product-card__excerpt"><?php echo esc_html(wp_trim_words((string) $product['excerpt'], 15)); ?></p>
<?php endif; ?>
<div class="aksrt-product-card__footer">
<span class="aksrt-product-card__price">¥<?php echo esc_html(number_format($product['price'], 2)); ?></span>
<?php if ($product['sales'] > 0) : ?>
<span class="aksrt-product-card__sales"><?php printf(esc_html__('已售 %d', 'aksrt'), $product['sales']); ?></span>
<span class="aksrt-product-card__price">¥<?php echo esc_html(number_format((float) ($product['price'] ?? 0), 2)); ?></span>
<?php if ($show_sales) : ?>
<span class="aksrt-product-card__sales"><?php printf(esc_html__('已售 %d', 'aksrt'), $sales); ?></span>
<?php endif; ?>
</div>
</div>
@@ -69,26 +112,33 @@ $term_name = $term->name ?? '';
</div>
<?php if ($max_pages > 1) : ?>
<nav class="aksrt-product-archive__pagination" aria-label="<?php esc_attr_e('商品分页', 'aksrt'); ?>">
<?php
echo paginate_links([
'total' => $max_pages,
'current' => $paged,
'prev_text' => '<i class="fas fa-chevron-left"></i>',
'next_text' => '<i class="fas fa-chevron-right"></i>',
]);
?>
</nav>
<?php if ($paging === 'ajax') : ?>
<div class="aksrt-product-archive__load-more">
<button type="button" class="aksrt-load-more-btn" data-aksrt-shop-load-more><?php esc_html_e('加载更多', 'aksrt'); ?></button>
</div>
<?php else : ?>
<nav class="aksrt-product-archive__pagination" aria-label="<?php esc_attr_e('商品分页', 'aksrt'); ?>">
<?php
echo paginate_links([
'total' => $max_pages,
'current' => $paged,
'prev_text' => '<i class="fas fa-chevron-left"></i>',
'next_text' => '<i class="fas fa-chevron-right"></i>',
'add_args' => $active_orderby ? ['shop_orderby' => $active_orderby] : [],
]);
?>
</nav>
<?php endif; ?>
<?php endif; ?>
<?php else : ?>
<div class="aksrt-product-archive__empty">
<i class="fas fa-box-open"></i>
<p><?php esc_html_e('该标签下暂无商品', 'aksrt'); ?></p>
<p><?php esc_html_e('内容空空如也', 'aksrt'); ?></p>
</div>
<?php endif; ?>
</div>
</main>
<?php
wp_enqueue_script('aksrt-product-archive', get_template_directory_uri() . '/assets/js/product-archive.js', [], AKSRT_VERSION, true);
wp_enqueue_script('aksrt-product-archive', get_template_directory_uri() . '/assets/js/product-archive.js', ['aksrt-script'], AKSRT_VERSION, true);
get_footer();