first commit
This commit is contained in:
parent
29c27dae04
commit
011e688593
|
|
@ -1,28 +0,0 @@
|
|||
jQuery(function ($) {
|
||||
$("#import_api").on("click", function () {
|
||||
$.post(
|
||||
ajaxurl,
|
||||
{
|
||||
action: "wpi_import_api",
|
||||
url: $("#api_url").val(),
|
||||
},
|
||||
alert
|
||||
);
|
||||
});
|
||||
|
||||
$("#import_csv").on("click", function () {
|
||||
const file = $("#csv_file")[0].files[0];
|
||||
const form = new FormData();
|
||||
form.append("action", "wpi_import_csv");
|
||||
form.append("file", file);
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
type: "POST",
|
||||
data: form,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: alert,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
<?php
|
||||
|
||||
class WPI_Admin_Page
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
add_action('admin_menu', [$this, 'menu']);
|
||||
add_action('wp_ajax_wpi_import_api', [$this, 'import_api']);
|
||||
add_action('wp_ajax_wpi_import_csv', [$this, 'import_csv']);
|
||||
}
|
||||
|
||||
public function menu()
|
||||
{
|
||||
add_menu_page(
|
||||
'Product Importer',
|
||||
'Product Importer',
|
||||
'manage_woocommerce',
|
||||
'wpi-importer',
|
||||
[$this, 'render']
|
||||
);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
?>
|
||||
<h1>Woo Product Importer</h1>
|
||||
|
||||
<h2>Import from API</h2>
|
||||
<input type="text" id="api_url" placeholder="API URL">
|
||||
<button id="import_api">Import API</button>
|
||||
|
||||
<h2>Import from CSV</h2>
|
||||
<input type="file" id="csv_file">
|
||||
<button id="import_csv">Import CSV</button>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function import_api()
|
||||
{
|
||||
$url = sanitize_text_field($_POST['url']);
|
||||
$importer = new WPI_API_Importer();
|
||||
$result = $importer->import($url);
|
||||
wp_send_json_success($result);
|
||||
}
|
||||
|
||||
public function import_csv()
|
||||
{
|
||||
if (empty($_FILES['file'])) {
|
||||
wp_send_json_error('No file');
|
||||
}
|
||||
$importer = new WPI_CSV_Importer();
|
||||
$result = $importer->import($_FILES['file']['tmp_name']);
|
||||
wp_send_json_success($result);
|
||||
}
|
||||
}
|
||||
|
|
@ -36,7 +36,6 @@ require_once WPI_PATH . 'includes/helpers/class-category-helper.php';
|
|||
require_once WPI_PATH . 'includes/class-api-importer.php';
|
||||
require_once WPI_PATH . 'includes/class-cron.php';
|
||||
require_once WPI_PATH . 'includes/class-logger.php';
|
||||
require_once WPI_PATH . 'includes/class-admin-page.php';
|
||||
require_once WPI_PATH . 'includes/class-product-map.php';
|
||||
require_once WPI_PATH . 'includes/class-product-validator.php';
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue