Refactor admin cl interface and handle product access with groups
This commit is contained in:
7
backend/app/plugins/wiaas/assets/css/wiaas-admin-cl.css
Normal file
7
backend/app/plugins/wiaas/assets/css/wiaas-admin-cl.css
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#posts-filter .tablenav .actions {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#menu-posts-product .wp-submenu li:last-child {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
jQuery(document).ready(function ($) {
|
||||||
|
|
||||||
|
$('#tabs').each(function() {
|
||||||
|
var disabled = $( this ).data('disabled') || '';
|
||||||
|
|
||||||
|
$( this ).tabs({
|
||||||
|
disabled: [ disabled ]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#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: $('#wiaas_create_cl_customer_extras_nonce').val(),
|
||||||
|
customer_id: customer_id,
|
||||||
|
package_id: $('#wiaas_cl_package_id').val()
|
||||||
|
}).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'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
<?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);
|
|
||||||
@@ -20,6 +20,20 @@ class Wiaas_Admin_CL_Packages {
|
|||||||
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||||
|
|
||||||
add_action( 'admin_menu', array(__CLASS__, 'add_cl_packages_menu') );
|
add_action( 'admin_menu', array(__CLASS__, 'add_cl_packages_menu') );
|
||||||
|
|
||||||
|
add_action( 'admin_head', array( __CLASS__, 'menu_highlight' ) );
|
||||||
|
|
||||||
|
add_filter( 'manage_product_posts_columns', array( __CLASS__, 'define_list_table_products_columns' ), 999 );
|
||||||
|
|
||||||
|
add_filter( 'bulk_actions-edit-product', array( __CLASS__, 'define_list_table_products_bulk_actions' ), 999 );
|
||||||
|
|
||||||
|
add_filter( 'views_edit-product', array( __CLASS__, 'define_list_table_products_views' ), 999 );
|
||||||
|
|
||||||
|
add_filter( 'post_row_actions', array( __CLASS__, 'define_list_table_products_row_actions' ), 999, 2 );
|
||||||
|
|
||||||
|
add_filter( 'list_table_primary_column', array( __CLASS__, 'define_list_table_products_primary_column' ), 999, 2 );
|
||||||
|
|
||||||
|
add_action( 'manage_product_posts_custom_column', array( __CLASS__, 'render_list_table_products_columns' ), 10, 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function enqueue_scripts() {
|
public static function enqueue_scripts() {
|
||||||
@@ -29,38 +43,33 @@ class Wiaas_Admin_CL_Packages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function add_cl_packages_menu() {
|
public static function add_cl_packages_menu() {
|
||||||
add_menu_page(
|
|
||||||
__( 'Products', 'wiaas' ),
|
|
||||||
__( 'Products', 'wiaas' ),
|
|
||||||
'manage_wiaas_cl_products',
|
|
||||||
'wiaas-cl-packages',
|
|
||||||
array(__CLASS__, 'output_list'),
|
|
||||||
null,
|
|
||||||
'55.5' );
|
|
||||||
|
|
||||||
add_submenu_page(
|
add_submenu_page(
|
||||||
null,
|
'edit.php?post_type=product',
|
||||||
__( 'Products', 'wiaas' ),
|
__( 'Products', 'wiaas' ),
|
||||||
null,
|
null,
|
||||||
'manage_wiaas_cl_products',
|
'manage_wiaas_cl_products',
|
||||||
'wiaas-cl-product',
|
'wiaas-cl-package',
|
||||||
array(__CLASS__, 'output_package')
|
array(__CLASS__, 'output_package')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function output_list() {
|
public static function menu_highlight() {
|
||||||
|
global $parent_file;
|
||||||
|
|
||||||
$packages_list = new Wiaas_Admin_CL_Packages_List();
|
$screen = get_current_screen();
|
||||||
|
|
||||||
$packages_list->prepare_items();
|
if ($screen->id === 'admin_page_wiaas-cl-product') {
|
||||||
|
|
||||||
require 'views/html-admin-cl-packages-page.php';
|
error_log('set parent');
|
||||||
|
|
||||||
|
$parent_file = 'edit.php?post_type=product';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function output_package() {
|
public static function output_package() {
|
||||||
wp_enqueue_script( 'jquery-ui-tabs' );
|
wp_enqueue_script( 'jquery-ui-tabs' );
|
||||||
|
|
||||||
$package_id = absint( $_GET['id'] );
|
$package_id = absint( $_GET['cl_package_id'] );
|
||||||
|
|
||||||
$package = wc_get_product($package_id);
|
$package = wc_get_product($package_id);
|
||||||
|
|
||||||
@@ -126,6 +135,87 @@ class Wiaas_Admin_CL_Packages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @section Customize display of list table products for commercial lead
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define columns for commercial lead view
|
||||||
|
* @param array $columns
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function define_list_table_products_columns($columns) {
|
||||||
|
$cl_columns = array();
|
||||||
|
|
||||||
|
$cl_columns['thumb'] = $columns['thumb'];
|
||||||
|
$cl_columns['wiaas_cl_name'] = $columns['name'];
|
||||||
|
$cl_columns['taxonomy-package_type'] = __('Type', 'wiaas');
|
||||||
|
$cl_columns['taxonomy-package_status'] = __('Status', 'wiaas');
|
||||||
|
$cl_columns['taxonomy-product_country'] = $columns['taxonomy-product_country'];
|
||||||
|
$cl_columns['date'] = $columns['date'];
|
||||||
|
|
||||||
|
return $cl_columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hide list table products bulk actions for commercial lead view
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function define_list_table_products_bulk_actions() {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hide list table products views for commercial lead view
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function define_list_table_products_views() {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show only ID in table products views for commercial lead view
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function define_list_table_products_row_actions($actions, $post) {
|
||||||
|
if ($post->post_type === 'product') {
|
||||||
|
return array( 'id' => sprintf( __( 'ID: %d', 'woocommerce' ), $post->ID ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $actions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define custom primary column in list table products for commercial lead view
|
||||||
|
*
|
||||||
|
* @param $default
|
||||||
|
* @param $screen_id
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function define_list_table_products_primary_column($default, $screen_id) {
|
||||||
|
if ( 'edit-product' === $screen_id ) {
|
||||||
|
return 'wiaas_cl_name';
|
||||||
|
}
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function render_list_table_products_columns($column, $post_id) {
|
||||||
|
if ($column === 'wiaas_cl_name') {
|
||||||
|
|
||||||
|
$package = wc_get_product($post_id);
|
||||||
|
|
||||||
|
$edit_link = admin_url( 'edit.php?post_type=product&page=wiaas-cl-package&cl_package_id=' . absint( $package->get_id() ) );
|
||||||
|
|
||||||
|
echo '<strong><a class="row-title" href="' . esc_url( $edit_link ) . '">' . esc_html( $package->get_title() ) . '</a></strong>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// PRIVATE HANDLERS
|
// PRIVATE HANDLERS
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
<?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>
|
|
||||||
@@ -78,72 +78,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script>
|
<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>
|
</script>
|
||||||
|
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
@@ -233,15 +168,15 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="tabs">
|
<div id="tabs" data-disabled="<?php echo $has_default_cl_extras ? '' : '1' ; ?>">
|
||||||
<ul id="tabs-navigation">
|
<ul id="tabs-navigation">
|
||||||
<li><a href="#tabs-1"><?php esc_html_e('Default prices', 'wiaas') ?></a> | </li>
|
<li><a href="#tabs-1"><?php esc_html_e('Default prices', 'wiaas') ?></a> | </li>
|
||||||
<li><a href="#tabs-2"><?php esc_html_e('Customer specific prices', 'wiaas') ?></a></li>
|
<li><a href="#tabs-2"><?php esc_html_e('Customer specific prices', 'wiaas') ?></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<form id="wiaas_package_extras" action="" method="post">
|
<form id="wiaas_package_extras" action="" method="post">
|
||||||
<input type="hidden" name="page" value="wiaas-cl-product"/>
|
<input type="hidden" name="page" value="wiaas-cl-package"/>
|
||||||
<input type="hidden" name="id" value="<?php echo esc_attr($package->get_id()) ?>"/>
|
<input type="hidden" id="wiaas_cl_package_id" name="cl_package_id" value="<?php echo esc_attr($package->get_id()) ?>"/>
|
||||||
|
|
||||||
<div id="tabs-1">
|
<div id="tabs-1">
|
||||||
|
|
||||||
@@ -273,6 +208,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
|
<?php wp_nonce_field( 'wiaas_create_cl_customer_extras', 'wiaas_create_cl_customer_extras_nonce' ); ?>
|
||||||
<button id="wiaas_add_cl_customer_extras" class="button">Add</button>
|
<button id="wiaas_add_cl_customer_extras" class="button">Add</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,33 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
class Wiaas_Admin_CL {
|
class Wiaas_Admin_CL {
|
||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-packages.php';
|
|
||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-packages-list.php';
|
add_action('init', array(__CLASS__, 'init_admin_cl'));
|
||||||
|
}
|
||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/admin-cl/wiaas-admin-cl-packages-ajax.php';
|
public static function init_admin_cl() {
|
||||||
|
|
||||||
|
$user = wp_get_current_user();
|
||||||
|
|
||||||
|
$role = $user->roles[0];
|
||||||
|
|
||||||
|
if ($role === 'commercial_lead') {
|
||||||
|
|
||||||
|
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-packages.php';
|
||||||
|
|
||||||
|
require_once dirname( __FILE__ ) . '/admin-cl/wiaas-admin-cl-packages-ajax.php';
|
||||||
|
|
||||||
|
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function enqueue_scripts() {
|
||||||
|
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||||
|
|
||||||
|
wp_enqueue_script( 'wiaas_admin_cl_packages', $plugin_url . '/assets/js/wiaas-admin-cl-packages.js' );
|
||||||
|
|
||||||
|
wp_enqueue_style( 'wiaas_admin_cl', $plugin_url . '/assets/css/wiaas-admin-cl.css' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Access_Management {
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
|
||||||
|
add_action( 'save_post', array( __CLASS__, 'maybe_handle_product_access' ), 999, 2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatize access control for product and packages
|
||||||
|
*
|
||||||
|
* @param int $post_id
|
||||||
|
* @param WP_Post $post
|
||||||
|
*/
|
||||||
|
public static function maybe_handle_product_access($post_id, $post) {
|
||||||
|
|
||||||
|
// $post_id and $post are required
|
||||||
|
if ( empty( $post_id ) || empty( $post ) || $post->post_type !== 'product') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$product = wc_get_product($post_id);
|
||||||
|
|
||||||
|
$admin_access_group = Groups_Group::read_by_name('admin');
|
||||||
|
|
||||||
|
$access_group_ids = array();
|
||||||
|
|
||||||
|
if ($admin_access_group) {
|
||||||
|
$access_group_ids[] = $admin_access_group->group_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// allow commercial lead to see published bundle products
|
||||||
|
$cl_access_group = Groups_Group::read_by_name('commercial_lead');
|
||||||
|
|
||||||
|
if ($product->get_type() === 'bundle' &&
|
||||||
|
$product->get_status() === 'publish' &&
|
||||||
|
$cl_access_group) {
|
||||||
|
$access_group_ids[] = $cl_access_group->group_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
Groups_Post_Access::update(
|
||||||
|
array(
|
||||||
|
'post_id' => $product->get_id(),
|
||||||
|
'groups_read' => $access_group_ids
|
||||||
|
) );
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Wiaas_Access_Management::init();
|
||||||
@@ -17,8 +17,10 @@ class Wiaas_DB_Update {
|
|||||||
'201810121644700' => 'wiaas_db_update_add_user_organization_ui_fields',
|
'201810121644700' => 'wiaas_db_update_add_user_organization_ui_fields',
|
||||||
'201810171645700' => 'wiaas_db_update_create_default_roles',
|
'201810171645700' => 'wiaas_db_update_create_default_roles',
|
||||||
'201810171745700' => 'wiaas_db_import_aam_role_settings',
|
'201810171745700' => 'wiaas_db_import_aam_role_settings',
|
||||||
'201810171845700' => 'wiaas_db_update_update_commercial_lead_capabilities',
|
'201810173045700' => 'wiaas_db_update_update_commercial_lead_capabilities',
|
||||||
'201810171945700' => 'wiaas_db_update_update_supplier_capabilities'
|
'201810173145700' => 'wiaas_db_update_update_supplier_capabilities',
|
||||||
|
'201810173245700' => 'wiaas_db_update_update_admin_capabilities',
|
||||||
|
'201810173345700' => 'wiaas_create_role_access_groups'
|
||||||
);
|
);
|
||||||
|
|
||||||
public static function execute() {
|
public static function execute() {
|
||||||
|
|||||||
@@ -5,6 +5,30 @@ class Wiaas_Product {
|
|||||||
public static function init() {
|
public static function init() {
|
||||||
require_once dirname( __FILE__ ) . '/product/class-wiaas-product-category.php';
|
require_once dirname( __FILE__ ) . '/product/class-wiaas-product-category.php';
|
||||||
require_once dirname( __FILE__ ) . '/product/class-wiaas-product-supplier.php';
|
require_once dirname( __FILE__ ) . '/product/class-wiaas-product-supplier.php';
|
||||||
|
|
||||||
|
add_filter('woocommerce_register_post_type_product', array(__CLASS__, 'define_product_capabilities'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define capabilities for editing products so we can easily control read/edit/create access for them
|
||||||
|
*
|
||||||
|
* @param $args
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function define_product_capabilities($args) {
|
||||||
|
|
||||||
|
$args['capabilities'] = array(
|
||||||
|
'edit_post' => 'edit_product',
|
||||||
|
'read_post' => 'read_product',
|
||||||
|
'delete_post' => 'delete_product',
|
||||||
|
'edit_posts' => 'edit_products',
|
||||||
|
'edit_others_posts' => 'edit_others_products',
|
||||||
|
'publish_posts' => 'publish_products',
|
||||||
|
'read_private_posts' => 'read_private_products',
|
||||||
|
'create_posts' => 'create_products', // use `create_products` instead of default `edit_products`
|
||||||
|
);
|
||||||
|
return $args;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -141,6 +141,9 @@ function wiaas_db_update_update_commercial_lead_capabilities() {
|
|||||||
wp_roles()->add_cap( 'commercial_lead', 'view_admin_dashboard' );
|
wp_roles()->add_cap( 'commercial_lead', 'view_admin_dashboard' );
|
||||||
wp_roles()->add_cap( 'commercial_lead', 'read' );
|
wp_roles()->add_cap( 'commercial_lead', 'read' );
|
||||||
wp_roles()->add_cap( 'commercial_lead', 'upload_files' );
|
wp_roles()->add_cap( 'commercial_lead', 'upload_files' );
|
||||||
|
|
||||||
|
wp_roles()->add_cap( 'commercial_lead', 'edit_products' );
|
||||||
|
wp_roles()->add_cap( 'commercial_lead', 'edit_others_products' );
|
||||||
}
|
}
|
||||||
|
|
||||||
function wiaas_db_update_update_supplier_capabilities() {
|
function wiaas_db_update_update_supplier_capabilities() {
|
||||||
@@ -148,3 +151,26 @@ function wiaas_db_update_update_supplier_capabilities() {
|
|||||||
wp_roles()->add_cap( 'supplier', 'view_admin_dashboard' );
|
wp_roles()->add_cap( 'supplier', 'view_admin_dashboard' );
|
||||||
wp_roles()->add_cap( 'supplier', 'read' );
|
wp_roles()->add_cap( 'supplier', 'read' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wiaas_db_update_update_admin_capabilities() {
|
||||||
|
wp_roles()->add_cap( 'administrator', 'create_products' );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function wiaas_create_role_access_groups() {
|
||||||
|
Groups_Group::create(array(
|
||||||
|
'name' => 'admin',
|
||||||
|
));
|
||||||
|
|
||||||
|
Groups_Group::create(array(
|
||||||
|
'name' => 'commercial_lead',
|
||||||
|
));
|
||||||
|
|
||||||
|
Groups_Group::create(array(
|
||||||
|
'name' => 'supplier',
|
||||||
|
));
|
||||||
|
|
||||||
|
Groups_Group::create(array(
|
||||||
|
'name' => 'customer',
|
||||||
|
));
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ if (is_admin()) {
|
|||||||
include_once WIAAS_DIR . '/includes/class-wiaas-admin.php';
|
include_once WIAAS_DIR . '/includes/class-wiaas-admin.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
include_once WIAAS_DIR . '/includes/class-wiaas-access-management.php';
|
||||||
|
|
||||||
include_once WIAAS_DIR . '/includes/class-wiaas-delivery-process.php';
|
include_once WIAAS_DIR . '/includes/class-wiaas-delivery-process.php';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user