Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance/product category rest api #2510

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/REST/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private function get_rest_api_class_map() {
DOKAN_DIR . '/includes/REST/VendorDashboardController.php' => '\WeDevs\Dokan\REST\VendorDashboardController',
DOKAN_DIR . '/includes/REST/ProductBlockController.php' => '\WeDevs\Dokan\REST\ProductBlockController',
DOKAN_DIR . '/includes/REST/CommissionControllerV1.php' => '\WeDevs\Dokan\REST\CommissionControllerV1',
DOKAN_DIR . '/includes/REST/ProductCategoriesVendorController.php' => '\WeDevs\Dokan\REST\ProductCategoriesVendorController',
DOKAN_DIR . '/includes/REST/VendorProductCategoriesController.php' => '\WeDevs\Dokan\REST\VendorProductCategoriesController',
)
);
}
Expand Down
247 changes: 0 additions & 247 deletions includes/REST/ProductCategoriesVendorController.php

This file was deleted.

106 changes: 106 additions & 0 deletions includes/REST/VendorProductCategoriesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

namespace WeDevs\Dokan\REST;

use WP_Error;
use WP_REST_Request;
use WP_REST_Response;
use WC_REST_Product_Categories_Controller;
use WP_REST_Server;

class VendorProductCategoriesController extends WC_REST_Product_Categories_Controller {
/**
* Endpoint namespace.
*
* @var string
*/
protected $namespace = 'dokan/v1';

/**
* Register the routes for terms.
*/
public function register_routes() {
register_rest_route(
$this->namespace,
'/' . $this->rest_base,
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'args' => $this->get_collection_params(),
),
'schema' => array( $this, 'get_public_item_schema' ),
)
);

register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<id>[\d]+)',
array(
'args' => array(
'id' => array(
'description' => __( 'Unique identifier for the resource.', 'dokan-lite' ),
'type' => 'integer',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
'permission_callback' => array( $this, 'get_item_permissions_check' ),
'args' => array(
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
),
),
'schema' => array( $this, 'get_public_item_schema' ),
)
);
}
/**
* Check if a given request has access to read items.
*
* Override the get_items_permissions_check method
* @return boolean
*/
public function get_items_permissions_check( $request ): bool {
return current_user_can( 'dokandar' );
}

/**
* Check if a given request has access to read a single item.
*
* Override the get_item_permissions_check method
* @return boolean
*/

public function get_item_permissions_check( $request ): bool {
return current_user_can( 'dokandar' );
}
/**
* Get all product categories.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_items( $request ) {
$request = apply_filters( 'dokan_rest_product_categories_query', $request );

// Get categories using parent method
return parent::get_items( $request );
}

/**
* Get a single product category.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|WP_REST_Response
*/

public function get_item( $request ) {
$request = apply_filters( 'dokan_rest_product_category_query', $request );

// Get category using parent method
return parent::get_item( $request );
}

}
Loading