feat(shop): 商品详情/归档壳层 1:1 同家族卡片与内容流
商品详情接入 content-wrap 主站详情壳;相关推荐与分类/标签/用户主页商品统一 product-card;卖家入口对齐用户主页 product tab。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c4310488b2
commit
28e4e19a3c
6 files changed
+152
-113
No files matched your search
@@ -37,12 +37,15 @@ $author_id = (int) get_post_field('post_author', $product_id);
|
||||
$author = $author_id > 0 ? get_userdata($author_id) : null;
|
||||
?>
|
||||
|
||||
<main id="main-content" class="site-main content-shell" tabindex="-1">
|
||||
<main id="main-content" class="site-main content-shell content-shell--stream content-shell--product" tabindex="-1">
|
||||
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
|
||||
|
||||
<?php if (!empty($product)) : ?>
|
||||
<div class="content-wrap container">
|
||||
<div class="content-layout content-layout--no-sidebar">
|
||||
<div class="content-layout__primary">
|
||||
<div
|
||||
class="aksrt-product-page container"
|
||||
class="aksrt-product-page"
|
||||
data-aksrt-product-page
|
||||
data-product-id="<?php echo esc_attr((string) $product_id); ?>"
|
||||
data-options='<?php echo esc_attr(wp_json_encode($options, JSON_UNESCAPED_UNICODE)); ?>'
|
||||
@@ -236,12 +239,16 @@ $author = $author_id > 0 ? get_userdata($author_id) : null;
|
||||
</div>
|
||||
|
||||
<!-- Merchant info -->
|
||||
<?php if ($author) : ?>
|
||||
<?php if ($author) :
|
||||
$store_url = function_exists('aksrt_get_user_home_url')
|
||||
? add_query_arg('tab', 'product', aksrt_get_user_home_url($author_id))
|
||||
: get_author_posts_url($author_id);
|
||||
?>
|
||||
<div class="aksrt-product-page__merchant">
|
||||
<img src="<?php echo esc_url(function_exists('aksrt_get_avatar_url') ? aksrt_get_avatar_url($author_id) : get_avatar_url($author_id)); ?>" alt="" class="aksrt-product-page__merchant-avatar">
|
||||
<div>
|
||||
<strong><?php echo esc_html($author->display_name); ?></strong>
|
||||
<a href="<?php echo esc_url(get_author_posts_url($author_id)); ?>?tab=products" class="aksrt-product-page__merchant-link"><?php esc_html_e('进入店铺', 'aksrt'); ?></a>
|
||||
<a href="<?php echo esc_url($store_url); ?>" class="aksrt-product-page__merchant-link"><?php esc_html_e('进入店铺', 'aksrt'); ?></a>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
@@ -312,33 +319,44 @@ $author = $author_id > 0 ? get_userdata($author_id) : null;
|
||||
|
||||
<!-- Related products -->
|
||||
<?php
|
||||
$related_query = new WP_Query([
|
||||
'post_type' => 'aksrt_product',
|
||||
'posts_per_page' => 6,
|
||||
'post_status' => 'publish',
|
||||
'post__not_in' => [$product_id],
|
||||
'tax_query' => !empty($product['categories']) ? [[
|
||||
'taxonomy' => 'aksrt_product_cat',
|
||||
'field' => 'term_id',
|
||||
'terms' => wp_list_pluck($product['categories'], 'term_id'),
|
||||
]] : [],
|
||||
'orderby' => 'rand',
|
||||
]);
|
||||
$related_items = [];
|
||||
if ($shop && method_exists($shop, 'build_product_card_view')) {
|
||||
$related_q = new WP_Query([
|
||||
'post_type' => 'aksrt_product',
|
||||
'posts_per_page' => 6,
|
||||
'post_status' => 'publish',
|
||||
'post__not_in' => [$product_id],
|
||||
'ignore_sticky_posts' => true,
|
||||
'no_found_rows' => true,
|
||||
'update_post_meta_cache' => false,
|
||||
'update_post_term_cache' => false,
|
||||
'tax_query' => !empty($product['categories']) ? [[
|
||||
'taxonomy' => 'aksrt_product_cat',
|
||||
'field' => 'term_id',
|
||||
'terms' => wp_list_pluck($product['categories'], 'term_id'),
|
||||
]] : [],
|
||||
'orderby' => 'rand',
|
||||
]);
|
||||
while ($related_q->have_posts()) {
|
||||
$related_q->the_post();
|
||||
$card = $shop->build_product_card_view((int) get_the_ID());
|
||||
if (!empty($card['id'])) {
|
||||
$related_items[] = $card;
|
||||
}
|
||||
}
|
||||
wp_reset_postdata();
|
||||
}
|
||||
?>
|
||||
<?php if ($related_query->have_posts()) : ?>
|
||||
<?php if (!empty($related_items)) : ?>
|
||||
<section class="aksrt-product-page__related">
|
||||
<h2><?php esc_html_e('相关推荐', 'aksrt'); ?></h2>
|
||||
<div class="aksrt-product-page__related-grid">
|
||||
<?php while ($related_query->have_posts()) : $related_query->the_post(); ?>
|
||||
<a href="<?php echo esc_url(get_permalink()); ?>" class="aksrt-product-page__related-card">
|
||||
<?php $thumb = $shop ? $shop->resolve_main_image(get_the_ID()) : get_the_post_thumbnail_url(get_the_ID(), 'medium'); ?>
|
||||
<?php if ($thumb) : ?>
|
||||
<img src="<?php echo esc_url($thumb); ?>" alt="<?php the_title_attribute(); ?>" loading="lazy">
|
||||
<?php endif; ?>
|
||||
<h3><?php the_title(); ?></h3>
|
||||
<strong>¥<?php echo esc_html(number_format((float) get_post_meta(get_the_ID(), '_aksrt_price', true), 2)); ?></strong>
|
||||
</a>
|
||||
<?php endwhile; wp_reset_postdata(); ?>
|
||||
<h2 class="aksrt-product-page__related-title"><?php esc_html_e('相关推荐', 'aksrt'); ?></h2>
|
||||
<div class="aksrt-product-archive__grid aksrt-product-archive__grid--default aksrt-product-page__related-grid">
|
||||
<?php foreach ($related_items as $related_product) :
|
||||
get_template_part('templates/parts/shop/product', 'card', [
|
||||
'product' => $related_product,
|
||||
'show_sales' => ((int) ($related_product['sales'] ?? 0) > 0),
|
||||
]);
|
||||
endforeach; ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
@@ -397,6 +415,11 @@ $author = $author_id > 0 ? get_userdata($author_id) : null;
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
</div><!-- .aksrt-product-page -->
|
||||
</div><!-- .content-layout__primary -->
|
||||
</div><!-- .content-layout -->
|
||||
</div><!-- .content-wrap -->
|
||||
|
||||
<!-- Mobile purchase tabbar -->
|
||||
<div class="aksrt-product-page__mobile-bar" data-aksrt-mobile-purchase>
|
||||
<button type="button" class="aksrt-product-page__mobile-btn" data-aksrt-toggle-fav="<?php echo esc_attr((string) $product_id); ?>">
|
||||
|
||||
Reference in new issue
Block a user