Handle commercial lead prices
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WP_List_Table' ) ) {
|
||||
include_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
||||
}
|
||||
|
||||
class Wiaas_Admin_CL_Packages_List extends WP_List_Table {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct( array(
|
||||
'singular' => 'Package',
|
||||
'plural' => 'Packages',
|
||||
'ajax' => false,
|
||||
) );
|
||||
|
||||
return true;
|
||||
}
|
||||
public function column_default( $item, $column_name ) {
|
||||
switch ( $column_name ) {
|
||||
case 'thumb':
|
||||
return '<a href="' . admin_url( 'admin.php?page=wiaas-cl-product&id=' . absint( $item->get_id() ) ) . '">' .
|
||||
$item->get_image( 'thumbnail' ) .
|
||||
'</a>';
|
||||
case 'name':
|
||||
return '<strong><a href="' . admin_url( 'admin.php?page=wiaas-cl-product&id=' . absint( $item->get_id() ) ) . '">' .
|
||||
esc_attr( $item->get_name() ) .
|
||||
'</a></strong>' .
|
||||
'<div><span style="color: #999;">ID: '. $item->get_id() . '</span></div>';
|
||||
case 'country':
|
||||
$country = Wiaas_Countries::get_package_country($item);
|
||||
if (! empty($country)) {
|
||||
return '<span>'. $country['name'] . '</span>';
|
||||
}
|
||||
return '';
|
||||
case 'type':
|
||||
$type = Wiaas_Package_Type::get_package_type($item->get_id());
|
||||
return '<span>'. $type . '</span>';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function prepare_items() {
|
||||
$columns = $this->get_columns();
|
||||
$sortable = $this->get_sortable_columns();
|
||||
$this->_column_headers = array( $columns, $sortable );
|
||||
|
||||
$items_per_page = 10;
|
||||
|
||||
$current_page = $this->get_pagenum();
|
||||
|
||||
$query_args = array(
|
||||
'status' => 'publish',
|
||||
'type' => 'bundle',
|
||||
'tag' => array(),
|
||||
'limit' => $items_per_page,
|
||||
'page' => $current_page,
|
||||
'paginate' => true
|
||||
);
|
||||
|
||||
if (!empty($_REQUEST['s'])) {
|
||||
$query_args['s'] = sanitize_text_field($_REQUEST['s']);
|
||||
}
|
||||
|
||||
$results = wc_get_products($query_args);
|
||||
|
||||
$this->items = $results->products;
|
||||
|
||||
$this->set_pagination_args( array(
|
||||
'total_items' => $results->total,
|
||||
'per_page' => $items_per_page,
|
||||
) );
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function get_views() {
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
public function get_columns() {
|
||||
$columns = array(
|
||||
'thumb' => __( '', 'wiaas' ),
|
||||
'name' => __( 'Name', 'wiaas' ),
|
||||
'country' => __( 'Sell in', 'wiaas' ),
|
||||
'type' => __( 'Type', 'wiaas' ),
|
||||
);
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
public function get_primary_column_name() {
|
||||
return 'product_name';
|
||||
}
|
||||
|
||||
public function get_sortable_columns() {
|
||||
$sort = array(
|
||||
'product_name' => array( 'product_name', true ),
|
||||
);
|
||||
|
||||
return $sort;
|
||||
}
|
||||
|
||||
public function no_items() {
|
||||
_e( 'No packages found.', 'wiaas' );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function wiaas_handle_custom_query_var($query, $query_vars) {
|
||||
if ( ! empty( $query_vars['catalogue'] ) ) {
|
||||
|
||||
$query['meta_query'][] = array(
|
||||
'key' => '_wiaas_catalogue_'.$query_vars['catalogue'],
|
||||
'value' => 'yes',
|
||||
);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
add_filter('woocommerce_product_data_store_cpt_get_products_query', 'wiaas_handle_custom_query_var', 10, 2);
|
||||
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class Wiaas_Admin_CM_Packages
|
||||
*
|
||||
*/
|
||||
class Wiaas_Admin_CL_Packages {
|
||||
|
||||
/**
|
||||
* Handles output of Commercial Lead packages page in admin panel.
|
||||
*
|
||||
* Shows list of packages available for sale and packages sold by current commercial lead.
|
||||
* Enables adding package to commercial lead catalogue and setting package specific prices
|
||||
* for current commercial lead.
|
||||
*
|
||||
*/
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||
|
||||
add_action( 'admin_menu', array(__CLASS__, 'add_cl_packages_menu') );
|
||||
}
|
||||
|
||||
public static function enqueue_scripts() {
|
||||
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||
|
||||
wp_enqueue_style( 'wiaas_admin_menu', $plugin_url . '/assets/css/menu.css' );
|
||||
}
|
||||
|
||||
public static function add_cl_packages_menu() {
|
||||
add_menu_page(
|
||||
__( 'Products', 'wiaas' ),
|
||||
__( 'Products', 'wiaas' ),
|
||||
'wiaas_manage_cl_products',
|
||||
'wiaas-cl-packages',
|
||||
array(__CLASS__, 'output_list'),
|
||||
null,
|
||||
'55.5' );
|
||||
|
||||
add_submenu_page(
|
||||
null,
|
||||
__( 'Products', 'wiaas' ),
|
||||
null,
|
||||
'wiaas_manage_cl_products',
|
||||
'wiaas-cl-product',
|
||||
array(__CLASS__, 'output_package')
|
||||
);
|
||||
}
|
||||
|
||||
public static function output_list() {
|
||||
|
||||
$packages_list = new Wiaas_Admin_CL_Packages_List();
|
||||
|
||||
$packages_list->prepare_items();
|
||||
|
||||
require 'views/html-admin-cl-packages-page.php';
|
||||
}
|
||||
|
||||
public static function output_package() {
|
||||
wp_enqueue_script( 'jquery-ui-tabs' );
|
||||
|
||||
$package_id = absint( $_GET['id'] );
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
|
||||
if (!$package) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! empty($_POST['wiaas_save_cl_extras_nonce']) && ! empty($_POST['cl_extras'])) {
|
||||
if (wp_verify_nonce($_POST['wiaas_save_cl_extras_nonce'], 'wiaas_save_cl_extras')) {
|
||||
self::_handle_cl_extras_update($package_id);
|
||||
}
|
||||
}
|
||||
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
|
||||
$bundled_items_per_category = array();
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
$category = Wiaas_Product_Category::get_category($bundled_item->product);
|
||||
if (isset($category)) {
|
||||
if ($category ==='hardware' || $category === 'software') {
|
||||
$category = 'products';
|
||||
}
|
||||
$bundled_items_per_category[$category] ?: array();
|
||||
$bundled_items_per_category[$category][] = $bundled_item;
|
||||
}
|
||||
}
|
||||
|
||||
$configured_prices = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
|
||||
$cl_id = wiaas_get_current_user_organization_id();
|
||||
|
||||
$cl_extras = Wiaas_Package_CL_Pricing::get_extras($cl_id, $package_id);
|
||||
|
||||
$has_default_cl_extras = ! empty($cl_extras);
|
||||
|
||||
// default values for catalogue package
|
||||
if (! $has_default_cl_extras) {
|
||||
$cl_extras = array();
|
||||
|
||||
foreach ($configured_prices as $type => $configured_price) {
|
||||
$cl_extras[$type.'_default'] = array(
|
||||
'visible' => true,
|
||||
'fixed' => 0,
|
||||
'services' => 0,
|
||||
'recurrent' => 0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$package_cl_extra_types = array_keys($cl_extras);
|
||||
|
||||
$customer_ids_with_extras = array();
|
||||
foreach ($package_cl_extra_types as $package_cl_extra_type) {
|
||||
$customer_id_with_extras = explode('_customer_', $package_cl_extra_type)[1];
|
||||
|
||||
if (isset($customer_id_with_extras) && ($customer_id_with_extras = absint($customer_id_with_extras)) > 0) {
|
||||
$customer_ids_with_extras[] = $customer_id_with_extras;
|
||||
}
|
||||
}
|
||||
$customer_ids_with_extras = array_unique($customer_ids_with_extras);
|
||||
|
||||
require 'views/html-cl-package-details.php';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// PRIVATE HANDLERS
|
||||
|
||||
private static function _handle_cl_extras_update($package_id) {
|
||||
$cl_extras = wp_unslash($_POST['cl_extras']);
|
||||
|
||||
$pay_types = array_keys(Wiaas_Package_Pricing::get_available_pay_types());
|
||||
|
||||
$posted_cl_extras = array();
|
||||
|
||||
foreach ($cl_extras as $cl_extra) {
|
||||
|
||||
$customer_id = isset($cl_extra['customer']) ? absint($cl_extra['customer']) : 0;
|
||||
$type = sanitize_key($cl_extra['type']);
|
||||
|
||||
$fixed_extra = isset($cl_extra['fixed']) ? floatval($cl_extra['fixed']) : 0;
|
||||
$services_extra = isset($cl_extra['services']) ? floatval($cl_extra['services']) : 0;
|
||||
$recurrent_extra = isset($cl_extra['recurrent']) ? floatval($cl_extra['recurrent']) : 0;
|
||||
|
||||
$extra_type = $customer_id > 0 ? $type.'_customer_'.$customer_id : $type.'_default';
|
||||
|
||||
if (in_array($type, $pay_types)) {
|
||||
$posted_cl_extras[$extra_type] = array(
|
||||
'type' => $type,
|
||||
'visible' => $cl_extra['visible'] === 'on',
|
||||
'fixed' => $fixed_extra,
|
||||
'services' => $services_extra,
|
||||
'recurrent' => $recurrent_extra,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Package_CL_Pricing::set_extras(
|
||||
wiaas_get_current_user_organization_id(),
|
||||
$package_id,
|
||||
$posted_cl_extras
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_CL_Packages::init();
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<style>
|
||||
table.wp-list-table .column-thumb {
|
||||
width: 52px;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
table.wp-list-table td.column-thumb img {
|
||||
margin: 0;
|
||||
width: auto;
|
||||
height: auto;
|
||||
max-width: 40px;
|
||||
max-height: 40px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<div class="wrap">
|
||||
<h2><?php esc_html_e( 'Products', 'wiaas' ); ?>
|
||||
<?php
|
||||
if ( ! empty( $_REQUEST['s'] ) ) {
|
||||
echo '<span class="subtitle">' . esc_html__( 'Search results for', 'wiaas' ) . ' "' . sanitize_text_field( $_REQUEST['s'] ) . '"</span>';
|
||||
}
|
||||
?>
|
||||
</h2>
|
||||
|
||||
<ul class="subsubsub"><?php $packages_list->views(); ?></ul>
|
||||
|
||||
<form id="wiaas_products" action="" method="get">
|
||||
<input type="hidden" name="page" value="wiaas-cl-packages" />
|
||||
<?php $packages_list->search_box( __( 'Search Products', 'wiaas' ), 'wiaas_packages_search_id' ); ?>
|
||||
<?php $packages_list->display(); ?>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<style>
|
||||
#tabs-navigation {
|
||||
height: 30px;
|
||||
}
|
||||
#tabs-navigation > li {
|
||||
float: left;
|
||||
line-height: 30px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#tabs-navigation > li.ui-state-active > a {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#tabs-navigation > li.ui-state-disabled > a {
|
||||
color: #ccc;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
#tabs-navigation > li > a {
|
||||
text-decoration: none;
|
||||
padding: .5em;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices > thead {
|
||||
background: #f2f2f2;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices > thead td {
|
||||
vertical-align: middle;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices > thead i {
|
||||
position: absolute;
|
||||
vertical-align: top;
|
||||
right: -8px;
|
||||
top: -8px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
||||
.wiaas-configured-prices > tbody > tr > td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices > tbody > tr > td:first-child {
|
||||
max-width: 100px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices > tbody > tr > td:nth-child(2) label {
|
||||
float: left;;
|
||||
width: 70px;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices input[type='text'] {
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
#managed_36 > td:nth-child(2) > div:last-child {
|
||||
position: relative;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
#managed_36 > td:nth-child(2) > div:last-child > span {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 70px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
jQuery(document).ready(function ($) {
|
||||
$( "#tabs" ).tabs({
|
||||
disabled: <?php echo $has_default_cl_extras ? '[ ]' : '[ 1 ]' ; ?>
|
||||
});
|
||||
|
||||
$('#wiaas_add_cl_customer_extras').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var customer_id = $('#wiaas_cl_customers').val();
|
||||
|
||||
if (!customer_id || customer_id === '0') {
|
||||
return;
|
||||
}
|
||||
|
||||
$.post(window.ajaxurl, {
|
||||
action: 'wiaas_create_cl_customer_extras',
|
||||
_ajax_nonce: '<?php echo wp_create_nonce('wiaas_create_cl_customer_extras') ?>',
|
||||
customer_id: customer_id,
|
||||
package_id: <?php echo esc_attr($package->get_id()) ?>
|
||||
}).done( function (result) {
|
||||
$('#tabs-2').append(result);
|
||||
|
||||
$('#wiaas_cl_customer_' + customer_id).prop( 'disabled', true );
|
||||
});
|
||||
|
||||
$('#wiaas_cl_customers').val('0');
|
||||
});
|
||||
|
||||
$('#wiaas_package_extras').delegate('.wiaas_remove_cl_extras', 'click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var customer_id = $( this ).data('customer_id');
|
||||
|
||||
$('#extras_customer_' + customer_id).remove();
|
||||
|
||||
$('#wiaas_cl_customer_' + customer_id).prop( 'disabled', false );
|
||||
|
||||
$('#wiaas_cl_customers').val('0');
|
||||
});
|
||||
|
||||
$('#wiaas_package_extras').delegate('.wiaas-cl-extra-input', 'change', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var val = parseFloat($( this ).val());
|
||||
var target = '#' + $( this).data('target');
|
||||
|
||||
if (isNaN(val)) {
|
||||
|
||||
$(target).val('Invalid!');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var type = $( this).data('type');
|
||||
|
||||
if (type === 'fixed') {
|
||||
$(target).text( $(target).data('base') + val);
|
||||
}
|
||||
|
||||
if (type === 'recurrent' || type === 'services') {
|
||||
$(target).data(type, val);
|
||||
|
||||
$(target).text( $(target).data('base') + $(target).data('recurrent') + $(target).data('services'));
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="wrap">
|
||||
<div id="poststuff">
|
||||
<div id="post-body" class="metabox-holder columns-2">
|
||||
<div id="postbox-container-1" class="postbox-container">
|
||||
<div class="postbox">
|
||||
<div class="inside">
|
||||
<div class="panel-wrap">
|
||||
<div class="panel">
|
||||
<div>
|
||||
<?php
|
||||
foreach ($bundled_items_per_category as $category => $category_bundled_items) {
|
||||
echo sprintf(
|
||||
'<strong style="text-transform: uppercase;" class="text-uppercase">%s (%s)</strong>',
|
||||
esc_attr( $category ),
|
||||
esc_attr(count($category_bundled_items)) );
|
||||
foreach ($category_bundled_items as $bundled_item) {
|
||||
$title = $bundled_item->product->get_title();
|
||||
echo sprintf( '<p>%s x %s</p>', esc_attr($bundled_item->get_quantity('max')), esc_attr( $title ) );
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="postbox-container-2" class="postbox-container">
|
||||
|
||||
<div class="postbox">
|
||||
<div class="inside">
|
||||
<div class="panel-wrap">
|
||||
<div class="panel">
|
||||
<h1 style="padding: 0;"><?php echo $package->get_name(); ?></h1>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if (! empty($package->get_short_description())) {
|
||||
?>
|
||||
<div class="postbox">
|
||||
<?php wp_editor( $package->get_short_description(), 'content', array(
|
||||
'_content_editor_dfw' => $_content_editor_dfw,
|
||||
'drag_drop_upload' => false,
|
||||
'media_buttons' => false,
|
||||
'quicktags' => false,
|
||||
'tabfocus_elements' => 'content-html',
|
||||
'tinymce' => array(
|
||||
'resize' => false,
|
||||
'wp_autoresize_on' => true,
|
||||
'add_unload_trigger' => false,
|
||||
'wp_keep_scroll_position' => ! $is_IE,
|
||||
'readonly'=> true,
|
||||
'toolbar' => false,
|
||||
),
|
||||
) ); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="postbox">
|
||||
<div class="inside">
|
||||
<div class="panel-wrap">
|
||||
<div class="panel">
|
||||
|
||||
<div class="wrap">
|
||||
<div>
|
||||
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
|
||||
<strong><?php esc_html_e('EPR') ?></strong>
|
||||
<span><?php esc_html_e('= Extra package recurrent commission') ?></span>
|
||||
</div>
|
||||
<div>
|
||||
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
|
||||
<strong><?php esc_html_e('ESR') ?></strong>
|
||||
<span><?php esc_html_e('= Extra services and support recurrent commission') ?></span>
|
||||
</div>
|
||||
<div>
|
||||
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
|
||||
<strong><?php esc_html_e('Extra commission') ?></strong>
|
||||
<span><?php esc_html_e('= EPR + ESR') ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="tabs">
|
||||
<ul id="tabs-navigation">
|
||||
<li><a href="#tabs-1">Default prices</a> | </li>
|
||||
<li><a href="#tabs-2">Customer specific prices</a></li>
|
||||
</ul>
|
||||
|
||||
<form id="wiaas_package_extras" action="" method="post">
|
||||
<input type="hidden" name="page" value="wiaas-cl-product"/>
|
||||
<input type="hidden" name="id" value="<?php echo esc_attr($package->get_id()) ?>"/>
|
||||
|
||||
<div id="tabs-1">
|
||||
|
||||
<?php require 'html-cl-package-prices.php'; ?>
|
||||
|
||||
</div>
|
||||
<div id="tabs-2">
|
||||
|
||||
<div class="form-group">
|
||||
<select id="wiaas_cl_customers" class="form-control">
|
||||
<option selected value="0" disabled> Select customer ...</option>
|
||||
<?php
|
||||
$customers = wiaas_get_customers();
|
||||
foreach ($customers as $id => $name) {
|
||||
?>
|
||||
<option
|
||||
<?php disabled(in_array($id, $customer_ids_with_extras), true, true) ?>
|
||||
id="wiaas_cl_customer_<?php esc_attr_e($id, 'wiaas') ?>"
|
||||
value="<?php esc_attr_e($id, 'wiaas') ?>"
|
||||
>
|
||||
<?php esc_html_e($name, 'wiaas') ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<button id="wiaas_add_cl_customer_extras" class="button">Add</button>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
// Render customer specific prices if any
|
||||
foreach ($customer_ids_with_extras as $customer_id) {
|
||||
require 'html-cl-package-prices.php';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php wp_nonce_field( 'wiaas_save_cl_extras', 'wiaas_save_cl_extras_nonce' ); ?>
|
||||
<?php submit_button( __( 'Save', 'wiaas' ), 'primary', 'submit' ); ?>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<br class="clear" />
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$id = isset($customer_id) ? 'extras_customer_'.$customer_id : 'extras_default';
|
||||
|
||||
?>
|
||||
|
||||
<table id="<?php esc_attr_e($id, 'wiaas') ?>" style="margin-top: 20px;" class="widefat wiaas-configured-prices">
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<td>
|
||||
<?php
|
||||
if (isset($customer_id)) {
|
||||
echo '<h4>'. esc_html(wiaas_get_organization_name($customer_id)). '</h4>';
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<td>Minimal sell price</td>
|
||||
<td>Extra commision</td>
|
||||
<td>Default price</td>
|
||||
<td>Visible?
|
||||
<?php
|
||||
if (isset($customer_id)) {
|
||||
?>
|
||||
<i
|
||||
data-customer_id="<?php esc_attr_e($customer_id, 'wiaas') ?>"
|
||||
class="dashicons dashicons-dismiss wiaas_remove_cl_extras"
|
||||
></i>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($configured_prices as $type => $configured_price) {
|
||||
|
||||
$extra_type = isset($customer_id) ? $type.'_customer_'.$customer_id : $type.'_default';
|
||||
|
||||
?>
|
||||
<input
|
||||
type="hidden"
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][type]"
|
||||
value="<?php esc_attr_e($type, 'wiaas')?>"
|
||||
>
|
||||
|
||||
<?php
|
||||
if (isset($customer_id)) {
|
||||
?>
|
||||
<input
|
||||
type="hidden"
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][customer]"
|
||||
value="<?php esc_attr_e($customer_id, 'wiaas')?>"
|
||||
>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<tr id="<?php esc_attr_e($extra_type, 'wias')?>">
|
||||
<td>
|
||||
<strong><?php esc_html_e($configured_price['payment_type']) ?></strong>
|
||||
</td>
|
||||
<td class="form-group">
|
||||
<div class="form-control">
|
||||
<label>Fixed:</label>
|
||||
<input type="text" value="<?php esc_attr_e($configured_price['minimal_fixed_price'], 'wiaas') ?>" readonly>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<label>Monthly:</label>
|
||||
<input type="text" value="<?php esc_attr_e($configured_price['minimal_recurrent_price'], 'wiaas') ?>" readonly>
|
||||
<?php
|
||||
if($configured_price['package_pay_period'] > 0) {
|
||||
echo sprintf( '<span>(%s for services)</span>', esc_attr( $configured_price['minimal_services_price'] ) );
|
||||
}
|
||||
?>
|
||||
|
||||
</div>
|
||||
</td>
|
||||
<td class="form-group">
|
||||
<div class="form-control">
|
||||
<label>+</label>
|
||||
<input
|
||||
class="wiaas-cl-extra-input"
|
||||
data-target="wiaas_cl_fixed_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
|
||||
data-type="fixed"
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][fixed]"
|
||||
value="<?php esc_attr_e($cl_extras[$extra_type]['fixed'], 'wiaas') ?>"
|
||||
type="text"
|
||||
>
|
||||
</div>
|
||||
<?php
|
||||
if($configured_price['package_pay_period'] > 0) {
|
||||
?>
|
||||
<div class="form-control">
|
||||
<label>+</label>
|
||||
<input
|
||||
class="wiaas-cl-extra-input"
|
||||
data-target="wiaas_cl_recurrent_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
|
||||
data-type="recurrent"
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][recurrent]"
|
||||
value="<?php esc_attr_e($cl_extras[$extra_type]['recurrent'], 'wiaas') ?>"
|
||||
type="text"
|
||||
>
|
||||
<label>(EPR)</label>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<div class="form-control">
|
||||
<label>+</label>
|
||||
<input
|
||||
class="wiaas-cl-extra-input"
|
||||
data-target="wiaas_cl_monthly_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
|
||||
data-type="services"
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][services]"
|
||||
value="<?php esc_attr_e($cl_extras[$extra_type]['services'], 'wiaas') ?>"
|
||||
type="text"
|
||||
>
|
||||
<label>(ESR)</label>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div> =
|
||||
<strong
|
||||
id="wiaas_cl_fixed_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
|
||||
data-base="<?php esc_attr_e($configured_price['minimal_fixed_price'], 'wiaas') ?>"
|
||||
>
|
||||
<?php esc_html_e($configured_price['minimal_fixed_price'] + $cl_extras[$extra_type]['fixed'], 'wiaas') ?>
|
||||
</strong>
|
||||
</div>
|
||||
<div> =
|
||||
<strong
|
||||
id="wiaas_cl_monthly_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
|
||||
data-base="<?php esc_attr_e($configured_price['minimal_recurrent_price'], 'wiaas') ?>"
|
||||
data-recurrent="<?php esc_attr_e($cl_extras[$extra_type]['recurrent'], 'wiaas') ?>"
|
||||
data-services="<?php esc_attr_e($cl_extras[$extra_type]['services'], 'wiaas') ?>"
|
||||
>
|
||||
<?php
|
||||
esc_html_e($configured_price['minimal_recurrent_price'] +
|
||||
$cl_extras[$extra_type]['recurrent'] +
|
||||
$cl_extras[$extra_type]['services'], 'wiaas')
|
||||
?>
|
||||
</div>
|
||||
</td>
|
||||
<td class="form-group">
|
||||
<input
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][visible]"
|
||||
<?php checked($cl_extras[$extra_type]['visible'], true, true) ?>
|
||||
type="checkbox"
|
||||
>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
add_action('wp_ajax_wiaas_create_cl_customer_extras', 'wiaas_ajax_create_cl_customer_extras');
|
||||
|
||||
function wiaas_ajax_create_cl_customer_extras() {
|
||||
check_ajax_referer('wiaas_create_cl_customer_extras');
|
||||
|
||||
$customer_id = absint($_POST['customer_id']);
|
||||
$package_id = absint($_POST['package_id']);
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
|
||||
$configured_prices = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
|
||||
$cl_extras = array();
|
||||
|
||||
foreach ($configured_prices as $type => $configured_price) {
|
||||
$cl_extras[$type.'_customer_'.$customer_id] = array(
|
||||
'type' => $type,
|
||||
'visible' => true,
|
||||
'fixed' => 0,
|
||||
'services' => 0,
|
||||
'recurrent' => 0
|
||||
);
|
||||
}
|
||||
|
||||
require_once 'views/html-cl-package-prices.php';
|
||||
|
||||
die();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user