Pricing_Controller::get_items( WP_REST_Request $request )
Summary
Retrieves a collection of products.
Parameters
- $request
-
(WP_REST_Request) (Required) Full details about the request.
Return
(WP_REST_Response|WP_Error) Response object on success, or WP_Error object on failure.
Source
File: src/BigCommerce/Rest/Pricing_Controller.php
public function get_items( $request ) { $customer = new Customer( get_current_user_id() ); /** * Filter the customer group ID passed to the BigCommerce API. * Null to use the default guest group. 0 to use unmodified catalog pricing. * * @param int|null The customer group ID */ $customer_group = apply_filters( 'bigcommerce/pricing/customer_group_id', $customer->get_group_id() ); $currency_code = get_option( Currency::CURRENCY_CODE, 'USD' ); $args = [ 'items' => $this->filter_empty_options( $request->get_param( 'items' ) ?: [] ), 'channel_id' => $this->get_channel_id(), 'currency_code' => $currency_code, 'customer_group_id' => $customer_group, ]; /** * Filters pricing request arguments. * * @param array $args Arguments. * @param \WP_REST_Request $request Full details about the request. */ $args = apply_filters( 'bigcommerce/pricing/request_args', $args, $request ); try { $pricing_request = new PricingRequest( $args ); $pricing_response = $this->pricing_api->getPrices( $pricing_request ); // convert items from objects to JSON $items = array_map( [ $this, 'format_prices' ], $pricing_response->getData() ); $response = [ 'items' => $items, ]; return rest_ensure_response( $response ); } catch ( \Exception $e ) { return new \WP_Error( 'gateway_error', $e->getMessage(), [ 'exception' => $e ] ); } }