Files
wordpress-theme-aksrt/templates/shop/product-cat.php
T
kate522 f3db6c89cc 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.
2026-07-12 10:38:02 +08:00

145 lines
7.3 KiB
PHP

<?php
/**
* 商品分类归档模板
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
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 ? (int) $term->term_id : 0,
'paged' => $paged,
'orderby' => $orderby,
]) : ['products' => [], 'term' => null, 'total' => 0, 'max_pages' => 0, 'orderby' => 'date', 'paging' => 'number'];
$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(); } ?>
<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); ?>">
<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" 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 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((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((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>
<?php endif; ?>
<div class="aksrt-product-card__body">
<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((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>
</a>
</article>
<?php endforeach; ?>
</div>
<?php if ($max_pages > 1) : ?>
<?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>
</div>
<?php endif; ?>
</div>
</main>
<?php
wp_enqueue_script('aksrt-product-archive', get_template_directory_uri() . '/assets/js/product-archive.js', ['aksrt-script'], AKSRT_VERSION, true);
get_footer();