reseller to customer

This commit is contained in:
Almira Krdzic
2018-10-16 06:45:28 +02:00
parent b7ac53d195
commit afab22a30b
37 changed files with 852 additions and 152 deletions

View File

@@ -2,34 +2,32 @@
class Wiaas_Package_API {
private static $namespace = 'wiaas';
public static function init() {
add_filter('woocommerce_rest_product_object_query', array(__CLASS__, 'filter_packages'), 10, 2);
add_filter('rest_dispatch_request', array(__CLASS__, 'validate_package_search_request'), 10, 4);
}
public static function register_routes() {
// TODO: Handle this when assigment of customer to commercial lead is done
register_rest_route( self::$namespace, '/commercial-leads', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array(__CLASS__, 'get_customer_commercial_leads'),
'permission_callback' => 'is_user_logged_in'
) );
// do nothing
}
// TODO: Handle this when assigment of customer to commercial lead is done
public static function get_customer_commercial_leads() {
$commercial_leads = array();
public static function validate_package_search_request($null, $request, $route, $handler) {
foreach (wiaas_get_commercial_leads() as $id => $name) {
$commercial_leads[] = array(
'id' => $id,
'name' => $name
);
}
if (strpos($route, '/wc/v2/products') !== false) {
return rest_ensure_response($commercial_leads);
if (empty($request['cl_id']) || ! absint($request['cl_id'])) {
return new WP_Error(
'missing_commercial_lead',
'Commercial lead is missing',
array ( 'status' => 400 )
);
}
}
return null;
}
/**