Files
old-new-wiaas/backend/app/plugins/wiaas/includes/admin/template/class-wiaas-template-admin-ajax.php
2018-09-18 13:28:54 +02:00

83 lines
2.4 KiB
PHP

<?php
// Exit if accessed directly.
if (!defined('ABSPATH')) {
exit;
}
class Wiaas_Template_Admin_Ajax {
/**
* Hook in.
*/
public static function init() {
// Ajax add bundled product.
add_action('wp_ajax_wiaas_add_template_product', array(__CLASS__, 'ajax_add_wiaas_template_product'));
// Ajax add bundled product.
add_action('wp_ajax_wiaas_select_template', array(__CLASS__, 'ajax_handle_template_selection'));
add_action('wp_ajax_wiaas_product_type_change', array(__CLASS__, 'toggle_template_selection_on_type_change'));
}
public static function ajax_handle_template_selection() {
$selected_template_id = intval($_POST['selected_template']);
$response = array(
'markup' => '',
'message' => ''
);
$template_products = Wiaas_Admin_Template_Selection::show_template_products($selected_template_id);
if (!empty($template_products)) {
ob_start();
Wiaas_Admin_Template_Selection::render_template_products($template_products['hardware']);
Wiaas_Admin_Template_Selection::render_template_products($template_products['service']);
Wiaas_Admin_Template_Selection::render_template_products($template_products['installation']);
Wiaas_Admin_Template_Selection::render_template_products($template_products['software']);
$response['markup'] = ob_get_clean();
}
wp_send_json($response);
}
/**
* Handles adding products to template via ajax.
*/
public static function ajax_add_wiaas_template_product() {
// check_ajax_referer( 'wc_bundles_add_bundled_product', 'security' );
$loop = intval($_POST['id']);
$product_id = intval($_POST['product_id']);
$options = $_POST['options'];
$product = wc_get_product($product_id);
$title = $product->get_title();
$response = array(
'markup' => '',
'message' => ''
);
if ($product) {
ob_start();
include('views/html-wiaas-template-product.php');
$response['markup'] = ob_get_clean();
} else {
$response['message'] = __('The selected product is invalid.', 'woocommerce-product-bundles');
}
wp_send_json($response);
}
}
Wiaas_Template_Admin_Ajax::init();