171 lines
11 KiB
PHP
171 lines
11 KiB
PHP
<?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>
|
|
<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(); ?>
|