PHP Class WC_REST_Orders_Controller

Inheritance: extends WC_REST_Posts_Controller
Show file Open project: woocommerce/woocommerce Class Usage Examples

Protected Properties

Property Type Description
$namespace string Endpoint namespace.
$post_type string Post type.
$request array Stores the request.
$rest_base string Route base.

Public Methods

Method Description
__construct ( ) Initialize orders actions.
create_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response Create a single item.
get_collection_params ( ) : array Get the query params for collections.
get_item_schema ( ) : array Get the Order's schema, conforming to JSON Schema.
prepare_item_for_response ( WP_Post $post, WP_REST_Request $request ) : WP_REST_Response Prepare a single order output for response.
query_args ( array $args, WP_REST_Request $request ) : array Query args.
register_routes ( ) Register the routes for orders.
update_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response Update a single order.

Protected Methods

Method Description
create_base_order ( array $data ) : WC_Order Create base WC Order object.
create_order ( WP_REST_Request $request ) : integer | WP_Error Create order.
filter_writable_props ( array $schema ) : boolean Only reutrn writeable props from schema.
get_order_item_data ( WC_Order_item $item ) : array Expands an order item to get its data.
get_order_statuses ( ) : array Get order statuses without prefixes.
get_product_id ( array $posted ) : integer Gets the product ID from the SKU or posted ID.
item_is_null ( array $item ) : boolean Helper method to check if the resource ID associated with the provided item is null.
maybe_set_item_prop ( WC_Order_Item $item, string $prop, array $posted ) Maybe set an item prop if the value was posted.
maybe_set_item_props ( WC_Order_Item $item, string[] $props, array $posted ) Maybe set item props if the values were posted.
prepare_coupon_lines ( array $posted, string $action ) Create or update an order coupon.
prepare_fee_lines ( array $posted, string $action ) Create or update an order fee.
prepare_item_for_database ( WP_REST_Request $request ) : WP_Error | WC_Order Prepare a single order for create.
prepare_line_items ( array $posted, string $action = 'create' ) Create or update a line item.
prepare_links ( WC_Order $order, WP_REST_Request $request ) : array Prepare links for the request.
prepare_shipping_lines ( $posted, string $action ) Create or update an order shipping method.
set_item ( WC_Order $order, string $item_type, array $posted ) Wrapper method to create/update order items.
update_address ( WC_Order $order, array $posted, string $type = 'billing' ) Update address.
update_order ( WP_REST_Request $request ) : integer | WP_Error Update order.

Method Details

__construct() public method

Initialize orders actions.
public __construct ( )

create_base_order() protected method

Create base WC Order object.
Deprecation: 2.7.0
protected create_base_order ( array $data ) : WC_Order
$data array
return WC_Order

create_item() public method

Create a single item.
public create_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response
$request WP_REST_Request Full details about the request.
return WP_Error | WP_REST_Response

create_order() protected method

Create order.
protected create_order ( WP_REST_Request $request ) : integer | WP_Error
$request WP_REST_Request Full details about the request.
return integer | WP_Error

filter_writable_props() protected method

Only reutrn writeable props from schema.
protected filter_writable_props ( array $schema ) : boolean
$schema array
return boolean

get_collection_params() public method

Get the query params for collections.
public get_collection_params ( ) : array
return array

get_item_schema() public method

Get the Order's schema, conforming to JSON Schema.
public get_item_schema ( ) : array
return array

get_order_item_data() protected method

Expands an order item to get its data.
protected get_order_item_data ( WC_Order_item $item ) : array
$item WC_Order_item
return array

get_order_statuses() protected method

Get order statuses without prefixes.
protected get_order_statuses ( ) : array
return array

get_product_id() protected method

Gets the product ID from the SKU or posted ID.
protected get_product_id ( array $posted ) : integer
$posted array Request data
return integer

item_is_null() protected method

Items can be deleted by setting the resource ID to null.
protected item_is_null ( array $item ) : boolean
$item array Item provided in the request body.
return boolean True if the item resource ID is null, false otherwise.

maybe_set_item_prop() protected method

Maybe set an item prop if the value was posted.
protected maybe_set_item_prop ( WC_Order_Item $item, string $prop, array $posted )
$item WC_Order_Item
$prop string
$posted array Request data.

maybe_set_item_props() protected method

Maybe set item props if the values were posted.
protected maybe_set_item_props ( WC_Order_Item $item, string[] $props, array $posted )
$item WC_Order_Item
$props string[]
$posted array Request data.

prepare_coupon_lines() protected method

Create or update an order coupon.
protected prepare_coupon_lines ( array $posted, string $action )
$posted array Item data.
$action string 'create' to add coupon or 'update' to update it.

prepare_fee_lines() protected method

Create or update an order fee.
protected prepare_fee_lines ( array $posted, string $action )
$posted array Item data.
$action string 'create' to add fee or 'update' to update it.

prepare_item_for_database() protected method

Prepare a single order for create.
protected prepare_item_for_database ( WP_REST_Request $request ) : WP_Error | WC_Order
$request WP_REST_Request Request object.
return WP_Error | WC_Order $data Object.

prepare_item_for_response() public method

Prepare a single order output for response.
public prepare_item_for_response ( WP_Post $post, WP_REST_Request $request ) : WP_REST_Response
$post WP_Post Post object.
$request WP_REST_Request Request object.
return WP_REST_Response $data

prepare_line_items() protected method

Create or update a line item.
protected prepare_line_items ( array $posted, string $action = 'create' )
$posted array Line item data.
$action string 'create' to add line item or 'update' to update it.

prepare_shipping_lines() protected method

Create or update an order shipping method.
protected prepare_shipping_lines ( $posted, string $action )
$posted $shipping Item data.
$action string 'create' to add shipping or 'update' to update it.

query_args() public method

Query args.
public query_args ( array $args, WP_REST_Request $request ) : array
$args array
$request WP_REST_Request
return array

register_routes() public method

Register the routes for orders.
public register_routes ( )

set_item() protected method

When updating, the item ID provided is checked to ensure it is associated with the order.
protected set_item ( WC_Order $order, string $item_type, array $posted )
$order WC_Order order
$item_type string
$posted array item provided in the request body

update_address() protected method

Update address.
protected update_address ( WC_Order $order, array $posted, string $type = 'billing' )
$order WC_Order
$posted array
$type string

update_item() public method

Update a single order.
public update_item ( WP_REST_Request $request ) : WP_Error | WP_REST_Response
$request WP_REST_Request Full details about the request.
return WP_Error | WP_REST_Response

update_order() protected method

Update order.
protected update_order ( WP_REST_Request $request ) : integer | WP_Error
$request WP_REST_Request Full details about the request.
return integer | WP_Error

Property Details

$namespace protected property

Endpoint namespace.
protected string $namespace
return string

$post_type protected property

Post type.
protected string $post_type
return string

$request protected property

Stores the request.
protected array $request
return array

$rest_base protected property

Route base.
protected string $rest_base
return string