Files
wordpress-theme-aksrt/templates/pages/page-product-edit.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

213 lines
14 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Template Name: AKSRT - Product Edit
* Template Post Type: page
*
* @package AKSRT
*/
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;
}
$product_id = (int) ($_GET['product_id'] ?? 0);
$edit_view = function_exists('aksrt_get_product_edit_page_view')
? aksrt_get_product_edit_page_view(get_current_user_id(), $product_id)
: ['allowed' => false, 'is_edit' => false, 'product' => [], 'taxonomy' => ['categories' => [], 'tags' => []], 'shipping_modes' => [], 'status_options' => []];
$product = (array) ($edit_view['product'] ?? []);
?>
<main id="main-content" class="site-main content-shell" tabindex="-1">
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
<div
class="aksrt-product-editor container"
data-aksrt-product-editor
data-product-id="<?php echo esc_attr((string) ($product['id'] ?? 0)); ?>"
data-is-edit="<?php echo !empty($edit_view['is_edit']) ? '1' : '0'; ?>"
>
<?php if (empty($edit_view['allowed'])) : ?>
<div class="aksrt-product-editor__empty">
<i class="fas fa-lock" aria-hidden="true"></i>
<p><?php esc_html_e('你没有权限编辑该商品。', 'aksrt'); ?></p>
</div>
<?php else : ?>
<div class="aksrt-product-editor__header">
<div>
<h1 class="aksrt-product-editor__title">
<?php echo !empty($edit_view['is_edit']) ? esc_html__('编辑商品', 'aksrt') : esc_html__('发布商品', 'aksrt'); ?>
</h1>
<p class="aksrt-product-editor__subtitle"><?php esc_html_e('管理主图、图集、分类标签、发货方式、运费和售后说明。', 'aksrt'); ?></p>
</div>
</div>
<form class="aksrt-product-editor__layout" data-aksrt-product-form>
<section class="aksrt-product-editor__main">
<div class="aksrt-product-editor__panel">
<h2><?php esc_html_e('基础信息', 'aksrt'); ?></h2>
<label class="aksrt-product-editor__field">
<span><?php esc_html_e('商品名称', 'aksrt'); ?></span>
<input type="text" name="title" class="aksrt-product-editor__input" value="<?php echo esc_attr((string) ($product['title'] ?? '')); ?>" required>
</label>
<div class="aksrt-product-editor__columns">
<label class="aksrt-product-editor__field">
<span><?php esc_html_e('价格', 'aksrt'); ?></span>
<input type="number" name="price" class="aksrt-product-editor__input" min="0" step="0.01" value="<?php echo esc_attr((string) ($product['price'] ?? 0)); ?>" required>
</label>
<label class="aksrt-product-editor__field">
<span><?php esc_html_e('库存', 'aksrt'); ?></span>
<input type="number" name="stock" class="aksrt-product-editor__input" min="0" step="1" value="<?php echo esc_attr((string) ($product['stock'] ?? 0)); ?>" required>
</label>
</div>
<label class="aksrt-product-editor__field">
<span><?php esc_html_e('商品简介', 'aksrt'); ?></span>
<textarea name="excerpt" class="aksrt-product-editor__textarea" rows="4"><?php echo esc_textarea((string) ($product['excerpt'] ?? '')); ?></textarea>
</label>
<label class="aksrt-product-editor__field">
<span><?php esc_html_e('商品详情', 'aksrt'); ?></span>
<textarea name="content" class="aksrt-product-editor__textarea" rows="10"><?php echo esc_textarea((string) ($product['content'] ?? '')); ?></textarea>
</label>
</div>
<div class="aksrt-product-editor__panel">
<h2><?php esc_html_e('商品素材', 'aksrt'); ?></h2>
<label class="aksrt-product-editor__field">
<span><?php esc_html_e('主图 URL', 'aksrt'); ?></span>
<input type="url" name="image" class="aksrt-product-editor__input" value="<?php echo esc_attr((string) ($product['image'] ?? '')); ?>" placeholder="https://">
</label>
<label class="aksrt-product-editor__field">
<span><?php esc_html_e('图集 URL(每行一个)', 'aksrt'); ?></span>
<textarea name="gallery" class="aksrt-product-editor__textarea" rows="5"><?php echo esc_textarea(implode("\n", (array) ($product['gallery'] ?? []))); ?></textarea>
</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">
<span><?php esc_html_e('发货方式', 'aksrt'); ?></span>
<select name="shipping_mode" class="aksrt-product-editor__input">
<?php foreach ((array) ($edit_view['shipping_modes'] ?? []) as $mode) : ?>
<option value="<?php echo esc_attr((string) ($mode['value'] ?? '')); ?>" <?php selected((string) ($product['shipping_mode'] ?? ''), (string) ($mode['value'] ?? '')); ?>>
<?php echo esc_html((string) ($mode['label'] ?? '')); ?>
</option>
<?php endforeach; ?>
</select>
</label>
<label class="aksrt-product-editor__field">
<span><?php esc_html_e('额外运费', 'aksrt'); ?></span>
<input type="number" name="shipping_fee" class="aksrt-product-editor__input" min="0" step="0.01" value="<?php echo esc_attr((string) ($product['shipping_fee'] ?? 0)); ?>">
</label>
</div>
<label class="aksrt-product-editor__field">
<span><?php esc_html_e('售后说明', 'aksrt'); ?></span>
<textarea name="after_sale_policy" class="aksrt-product-editor__textarea" rows="4"><?php echo esc_textarea((string) ($product['after_sale_policy'] ?? '')); ?></textarea>
</label>
<label class="aksrt-product-editor__checkbox">
<input type="checkbox" name="support_refund" value="1" <?php checked(!empty($product['support_refund'])); ?>>
<span><?php esc_html_e('支持退款/售后入口', 'aksrt'); ?></span>
</label>
</div>
</section>
<aside class="aksrt-product-editor__sidebar">
<div class="aksrt-product-editor__panel">
<h2><?php esc_html_e('发布设置', 'aksrt'); ?></h2>
<label class="aksrt-product-editor__field">
<span><?php esc_html_e('状态', 'aksrt'); ?></span>
<select name="status" class="aksrt-product-editor__input">
<?php foreach ((array) ($edit_view['status_options'] ?? []) as $status_option) : ?>
<option value="<?php echo esc_attr((string) ($status_option['value'] ?? 'draft')); ?>" <?php selected((string) ($product['status'] ?? 'draft'), (string) ($status_option['value'] ?? 'draft')); ?>>
<?php echo esc_html((string) ($status_option['label'] ?? '')); ?>
</option>
<?php endforeach; ?>
</select>
</label>
<label class="aksrt-product-editor__field">
<span><?php esc_html_e('分类(按住 Ctrl 可多选)', 'aksrt'); ?></span>
<select name="categories[]" class="aksrt-product-editor__input" multiple size="6">
<?php foreach ((array) (($edit_view['taxonomy']['categories'] ?? [])) as $category) : ?>
<option value="<?php echo esc_attr((string) ($category['id'] ?? 0)); ?>" <?php echo in_array((int) ($category['id'] ?? 0), (array) ($product['categories'] ?? []), true) ? 'selected' : ''; ?>>
<?php echo esc_html((string) ($category['name'] ?? '')); ?>
</option>
<?php endforeach; ?>
</select>
</label>
<label class="aksrt-product-editor__field">
<span><?php esc_html_e('标签(英文逗号分隔)', 'aksrt'); ?></span>
<input type="text" name="tags" class="aksrt-product-editor__input" value="<?php echo esc_attr(implode(', ', (array) ($product['tags'] ?? []))); ?>">
</label>
</div>
<div class="aksrt-product-editor__panel">
<h2><?php esc_html_e('动作', 'aksrt'); ?></h2>
<div class="aksrt-product-editor__actions">
<button type="submit" class="btn-primary btn-lg"><?php echo !empty($edit_view['is_edit']) ? esc_html__('保存修改', 'aksrt') : esc_html__('发布商品', 'aksrt'); ?></button>
<a href="<?php echo esc_url(function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url() : home_url('/')); ?>" class="btn-ghost btn-lg"><?php esc_html_e('返回中心', 'aksrt'); ?></a>
</div>
<p class="aksrt-product-editor__hint" data-aksrt-product-editor-message><?php esc_html_e('保存后会回到用户中心,商品信息供订单页和商品详情页复用。', 'aksrt'); ?></p>
</div>
</aside>
</form>
<?php endif; ?>
</div>
</main>
<?php get_footer(); ?>