Implement shop search and refactor

This commit is contained in:
Almira Krdzic
2018-10-17 00:36:19 +02:00
parent afab22a30b
commit 8769606a4b
24 changed files with 379 additions and 182 deletions

View File

@@ -19,6 +19,8 @@ class Wiaas_Order {
require_once dirname( __FILE__ ) . '/order/class-wiaas-order-project.php';
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);
@@ -30,6 +32,35 @@ class Wiaas_Order {
add_filter('woocommerce_new_order_note_data', array( __CLASS__, 'update_new_order_comment_date'), 10, 3);
}
/**
* Update `shop_order` post type settings before creation to enable better order management for wiaas
*
* @param array $args
*
* @return array
*/
public static function manage_order_settings($args) {
// show orders in backend menu
$args['show_in_menu'] = true;
//set icon
$args['menu_icon'] = 'dashicons-clipboard';
// set capabilities
$args['capabilities'] = array(
'edit_post' => 'edit_shop_order',
'read_post' => 'read_shop_order',
'delete_post' => 'delete_shop_order',
'edit_posts' => 'edit_shop_orders',
'edit_others_posts' => 'edit_others_shop_orders',
'publish_posts' => 'publish_shop_orders',
'read_private_posts' => 'read_private_shop_orders',
'create_posts' => 'create_shop_orders', // use `create_shop_orders` instead of `edit_shop_orders`
);
return $args;
}
public static function update_new_order_comment_date($comment_data, $order_data) {
$user = wp_get_current_user();
@@ -45,11 +76,17 @@ class Wiaas_Order {
* @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();
$commercial_lead_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);
}
}
/**