Add descriptive comments
This commit is contained in:
@@ -1,6 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Wiaas_Admin_CL_Shop {
|
/**
|
||||||
|
* Class Wiaas_Admin_CL_Customers
|
||||||
|
*/
|
||||||
|
class Wiaas_Admin_CL_Customers {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays table list of customers that are linked to commercial lead
|
||||||
|
*
|
||||||
|
* Enables commercial lead to update default order type for his shop
|
||||||
|
*
|
||||||
|
* Enables commercial lead to update order type for specific shop customer
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
|
|
||||||
@@ -66,4 +78,4 @@ class Wiaas_Admin_CL_Shop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Wiaas_Admin_CL_Shop::init();
|
Wiaas_Admin_CL_Customers::init();
|
||||||
|
|||||||
@@ -1,7 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Wiaas_Admin_CL_Orders
|
||||||
|
*/
|
||||||
class Wiaas_Admin_CL_Orders {
|
class Wiaas_Admin_CL_Orders {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays list of orders from commercial lead owned shop
|
||||||
|
*
|
||||||
|
* Enables quick preview of each order
|
||||||
|
*
|
||||||
|
* This list of orders is achieved with customization of default order list for `shop_order` post
|
||||||
|
* by using hooks and filters to allow only data that commercial lead should be able to see
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
|
|
||||||
add_filter( 'bulk_actions-edit-shop_order', array( __CLASS__, 'remove_bulk_actions_for_list_table_orders' ), 999 );
|
add_filter( 'bulk_actions-edit-shop_order', array( __CLASS__, 'remove_bulk_actions_for_list_table_orders' ), 999 );
|
||||||
@@ -15,27 +28,35 @@ class Wiaas_Admin_CL_Orders {
|
|||||||
add_filter( 'manage_edit-shop_order_sortable_columns', array( __CLASS__, 'define_sortable_columns_for_list_table_orders' ) );
|
add_filter( 'manage_edit-shop_order_sortable_columns', array( __CLASS__, 'define_sortable_columns_for_list_table_orders' ) );
|
||||||
|
|
||||||
add_action('manage_shop_order_posts_custom_column', array(__CLASS__, 'render_columns_for_list_table_orders'), 999, 2);
|
add_action('manage_shop_order_posts_custom_column', array(__CLASS__, 'render_columns_for_list_table_orders'), 999, 2);
|
||||||
|
|
||||||
//add_filter('wc_order_types', array(__CLASS__, ''), 999, 32);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function hide_order_customers_search( $order_types, $for ) {
|
|
||||||
|
|
||||||
if ($for === 'order-meta-boxes') {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $order_types;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all bulk actions for commercial lead
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public static function remove_bulk_actions_for_list_table_orders() {
|
public static function remove_bulk_actions_for_list_table_orders() {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove actions from shop order preview modal so only data info is visible
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public static function remove_actions_from_order_preview() {
|
public static function remove_actions_from_order_preview() {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show only packages on order preview
|
||||||
|
*
|
||||||
|
* @param $order_items
|
||||||
|
* @param $order
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public static function filter_order_items_for_order_preview($order_items, $order) {
|
public static function filter_order_items_for_order_preview($order_items, $order) {
|
||||||
|
|
||||||
$items = array();
|
$items = array();
|
||||||
@@ -49,6 +70,13 @@ class Wiaas_Admin_CL_Orders {
|
|||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override default table columns so only commercial lead specific columns are visible
|
||||||
|
*
|
||||||
|
* @param $columns
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public static function columns_for_list_table_orders($columns) {
|
public static function columns_for_list_table_orders($columns) {
|
||||||
$show_columns = array();
|
$show_columns = array();
|
||||||
$show_columns['cb'] = $columns['cb'];
|
$show_columns['cb'] = $columns['cb'];
|
||||||
@@ -61,6 +89,12 @@ class Wiaas_Admin_CL_Orders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Append commercial lead columns to table sortable columns
|
||||||
|
*
|
||||||
|
* @param $sortable_columns
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public static function define_sortable_columns_for_list_table_orders($sortable_columns) {
|
public static function define_sortable_columns_for_list_table_orders($sortable_columns) {
|
||||||
|
|
||||||
$sortable_columns['_wiaas_order_number'] = 'ID';
|
$sortable_columns['_wiaas_order_number'] = 'ID';
|
||||||
@@ -68,6 +102,12 @@ class Wiaas_Admin_CL_Orders {
|
|||||||
return $sortable_columns;
|
return $sortable_columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render commercial lead specific columns
|
||||||
|
*
|
||||||
|
* @param $column
|
||||||
|
* @param $order_id
|
||||||
|
*/
|
||||||
public static function render_columns_for_list_table_orders($column, $order_id) {
|
public static function render_columns_for_list_table_orders($column, $order_id) {
|
||||||
|
|
||||||
if ($column === '_wiaas_order_number') {
|
if ($column === '_wiaas_order_number') {
|
||||||
|
|||||||
@@ -1,10 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Wiaas_Access_Management
|
||||||
|
*/
|
||||||
class Wiaas_Access_Management {
|
class Wiaas_Access_Management {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles organization and role based access management to wiaas objects (orders, products)
|
||||||
|
*
|
||||||
|
* Using Groups Access for achieve this
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
|
|
||||||
add_action( 'save_post', array( __CLASS__, 'maybe_handle_product_access' ), 999, 2 );
|
add_action( 'save_post', array( __CLASS__, 'maybe_handle_product_access' ), 999, 2 );
|
||||||
|
|
||||||
|
add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' ));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,6 +56,25 @@ class Wiaas_Access_Management {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assignees order to corresponding user organization when order is created.
|
||||||
|
*
|
||||||
|
* @param int $order_id
|
||||||
|
*/
|
||||||
|
public static function assign_order_to_organization($order_id) {
|
||||||
|
// assign order to customer organization
|
||||||
|
$customer_id = wiaas_get_current_user_organization_id();
|
||||||
|
Wiaas_User_Organization::assign_post_to_organization($order_id, $customer_id);
|
||||||
|
$order = wc_get_order($order_id);
|
||||||
|
|
||||||
|
// assign order to commercial lead organization
|
||||||
|
$commercial_lead_id = absint($order->get_meta('_wiaas_commercial_lead_id', true));
|
||||||
|
if ($commercial_lead_id) {
|
||||||
|
Wiaas_User_Organization::assign_post_to_organization($order_id, $commercial_lead_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Wiaas_Access_Management::init();
|
Wiaas_Access_Management::init();
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ class Wiaas_Order {
|
|||||||
|
|
||||||
add_filter('woocommerce_register_post_type_shop_order', array(__CLASS__, 'manage_order_settings'));
|
add_filter('woocommerce_register_post_type_shop_order', array(__CLASS__, 'manage_order_settings'));
|
||||||
|
|
||||||
add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' ));
|
|
||||||
|
|
||||||
add_filter('woocommerce_rest_check_permissions', array( __CLASS__, 'check_order_access'), 10, 4);
|
add_filter('woocommerce_rest_check_permissions', array( __CLASS__, 'check_order_access'), 10, 4);
|
||||||
|
|
||||||
add_filter('woocommerce_rest_prepare_shop_order_object', array(__CLASS__, 'transform_rest_order'), 999, 3);
|
add_filter('woocommerce_rest_prepare_shop_order_object', array(__CLASS__, 'transform_rest_order'), 999, 3);
|
||||||
@@ -70,25 +68,6 @@ class Wiaas_Order {
|
|||||||
return $comment_data;
|
return $comment_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Assignees order to corresponding user organization when order is created.
|
|
||||||
*
|
|
||||||
* @param $order_id
|
|
||||||
*/
|
|
||||||
public static function assign_order_to_organization($order_id) {
|
|
||||||
// assign order to customer organization
|
|
||||||
$customer_id = wiaas_get_current_user_organization_id();
|
|
||||||
Wiaas_User_Organization::assign_post_to_organization($order_id, $customer_id);
|
|
||||||
$order = wc_get_order($order_id);
|
|
||||||
|
|
||||||
// assign order to commercial lead organization
|
|
||||||
$commercial_lead_id = absint($order->get_meta('_wiaas_commercial_lead_id', true));
|
|
||||||
if ($commercial_lead_id) {
|
|
||||||
Wiaas_User_Organization::assign_post_to_organization($order_id, $commercial_lead_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if current user has access to requested order/{orderId} via woocommerce REST API.
|
* Checks if current user has access to requested order/{orderId} via woocommerce REST API.
|
||||||
* Endpoint `/orders` is filtered correctly by groups, but endpoint `/orders/{orderId}` will return order even if
|
* Endpoint `/orders` is filtered correctly by groups, but endpoint `/orders/{orderId}` will return order even if
|
||||||
|
|||||||
Reference in New Issue
Block a user