reseller to customer
This commit is contained in:
@@ -31,12 +31,20 @@ class Wiaas_Cart_API {
|
||||
'package_id' => array(
|
||||
'description' => __( 'Wiaas package ID.', 'wiaas' ),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
'sanitize_callback' => 'absint',
|
||||
),
|
||||
'cl_id' => array(
|
||||
'description' => __( 'Commercial lead ID.', 'wiaas' ),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
'sanitize_callback' => 'absint',
|
||||
),
|
||||
'price_id' => array(
|
||||
'description' => __( 'Selected price ID for Wiaas package.', 'wiaas' ),
|
||||
'type' => 'string',
|
||||
'enum' => array_keys(Wiaas_Package_Pricing::get_available_pay_types()),
|
||||
'required' => true,
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
),
|
||||
'options_ids' => array(
|
||||
@@ -225,6 +233,7 @@ class Wiaas_Cart_API {
|
||||
$success = Wiaas_Cart::add_package_to_cart(
|
||||
$request['package_id'],
|
||||
$request['price_id'],
|
||||
$request['cl_id'],
|
||||
$request['addons_ids'],
|
||||
$request['options_ids']
|
||||
);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* TODO: Refactor this class so it reflects the fact that customer is an organization
|
||||
* TODO: Format should be `customer/(?P<organization_id>\d+)/user/(?P<id>\d+)
|
||||
*
|
||||
* Class Wiaas_REST_Customer_API
|
||||
*/
|
||||
|
||||
class Wiaas_REST_Customer_API {
|
||||
/**
|
||||
* Endpoint namespace.
|
||||
@@ -9,13 +16,19 @@ class Wiaas_REST_Customer_API {
|
||||
private static $namespace = 'wiaas';
|
||||
|
||||
public function __construct() {
|
||||
|
||||
include_once dirname( __FILE__ ) . '/../user/class-wiaas-customer.php';
|
||||
include_once dirname( __FILE__ ) . '/helper/class-rest-helper-functions.php';
|
||||
}
|
||||
|
||||
|
||||
public static function register_routes() {
|
||||
|
||||
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/shops', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array(__CLASS__, 'get_customer_shops'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/profile-addresses', array(
|
||||
'methods' => 'PUT',
|
||||
'callback' => array(__CLASS__, 'update_customer_profile_addresses'),
|
||||
@@ -54,6 +67,23 @@ class Wiaas_REST_Customer_API {
|
||||
|
||||
}
|
||||
|
||||
public static function get_customer_shops() {
|
||||
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
|
||||
$customer_shops = Wiaas_Shop_Data_Store::get_customer_shops($customer_id);
|
||||
|
||||
$customer_shops = array_map(function($customer_shop) {
|
||||
return array(
|
||||
'id' => $customer_shop['owner_id'],
|
||||
'type' => $customer_shop['order_type'],
|
||||
'name' => wiaas_get_organization_name($customer_shop['owner_id'])
|
||||
);
|
||||
}, $customer_shops);
|
||||
|
||||
return rest_ensure_response($customer_shops);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function update_customer_profile_addresses(WP_REST_Request $request){
|
||||
|
||||
Reference in New Issue
Block a user