| 1 |
<?php |
| 2 |
/** |
| 3 |
* Product_Brands_Controller. |
| 4 |
* |
| 5 |
* @package WCPOS\WooCommercePOS |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WCPOS\WooCommercePOS\API\V1; |
| 9 |
|
| 10 |
\defined( 'ABSPATH' ) || die; |
| 11 |
|
| 12 |
if ( ! class_exists( 'WC_REST_Product_Brands_Controller' ) ) { |
| 13 |
return; |
| 14 |
} |
| 15 |
|
| 16 |
use WC_REST_Product_Brands_Controller; |
| 17 |
use WP_REST_Request; |
| 18 |
use WP_REST_Response; |
| 19 |
|
| 20 |
/** |
| 21 |
* Product Brands controller class. |
| 22 |
* |
| 23 |
* @NOTE: methods not prefixed with wcpos_ will override WC_REST_Product_Brands_Controller methods |
| 24 |
*/ |
| 25 |
class Product_Brands_Controller extends WC_REST_Product_Brands_Controller { |
| 26 |
use Traits\Term_Controller; |
| 27 |
use Traits\Uuid_Handler; |
| 28 |
use Traits\WCPOS_REST_API; |
| 29 |
|
| 30 |
/** |
| 31 |
* Taxonomy served by this controller; also builds both WC hook names. |
| 32 |
*/ |
| 33 |
protected const WCPOS_TAXONOMY = 'product_brand'; |
| 34 |
|
| 35 |
/** |
| 36 |
* Method registered on woocommerce_rest_prepare_product_brand. |
| 37 |
*/ |
| 38 |
protected const WCPOS_RESPONSE_FILTER = 'wcpos_product_brands_response'; |
| 39 |
|
| 40 |
/** |
| 41 |
* Method registered on woocommerce_rest_product_brand_query. |
| 42 |
*/ |
| 43 |
protected const WCPOS_QUERY_FILTER = 'wcpos_product_brand_query'; |
| 44 |
|
| 45 |
/** |
| 46 |
* Collection label used in bulk-ID fast-path error messages. |
| 47 |
*/ |
| 48 |
protected const WCPOS_ID_ERROR_LABEL = 'product brand'; |
| 49 |
|
| 50 |
/** |
| 51 |
* Endpoint namespace. |
| 52 |
* |
| 53 |
* @var string |
| 54 |
*/ |
| 55 |
protected $namespace = 'wcpos/v1'; |
| 56 |
|
| 57 |
/** |
| 58 |
* Filter the brand response. |
| 59 |
* |
| 60 |
* Kept as a named method because third-party code detaches it by this exact |
| 61 |
* callback tuple; the behaviour lives in Traits\Term_Controller. |
| 62 |
* |
| 63 |
* @param WP_REST_Response $response The response object. |
| 64 |
* @param object $item The original term object. |
| 65 |
* @param WP_REST_Request $request Request object. |
| 66 |
* |
| 67 |
* @return WP_REST_Response $response The response object. |
| 68 |
*/ |
| 69 |
public function wcpos_product_brands_response( WP_REST_Response $response, object $item, WP_REST_Request $request ): WP_REST_Response { |
| 70 |
return $this->wcpos_term_response( $response, $item ); |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Filter the brand query. |
| 75 |
* |
| 76 |
* Kept as a named method because third-party code detaches it by this exact |
| 77 |
* callback tuple; the behaviour lives in Traits\Term_Controller. |
| 78 |
* |
| 79 |
* @param array $args Query arguments. |
| 80 |
* @param WP_REST_Request $request Request object. |
| 81 |
* |
| 82 |
* @return array |
| 83 |
*/ |
| 84 |
public function wcpos_product_brand_query( array $args, WP_REST_Request $request ): array { |
| 85 |
return $this->wcpos_term_query( $args ); |
| 86 |
} |
| 87 |
} |
| 88 |
|