| @@ 97-113 (lines=17) @@ | ||
| 94 | * @param WP_REST_Request $request |
|
| 95 | * @return WP_Error|WP_REST_Response |
|
| 96 | */ |
|
| 97 | public function get_items( $request ) { |
|
| 98 | $settings = $this->get_group_settings( $request['group'] ); |
|
| 99 | ||
| 100 | if ( is_wp_error( $settings ) ) { |
|
| 101 | return $settings; |
|
| 102 | } |
|
| 103 | ||
| 104 | $data = array(); |
|
| 105 | ||
| 106 | foreach ( $settings as $setting_obj ) { |
|
| 107 | $setting = $this->prepare_item_for_response( $setting_obj, $request ); |
|
| 108 | $setting = $this->prepare_response_for_collection( $setting ); |
|
| 109 | $data[] = $setting; |
|
| 110 | } |
|
| 111 | ||
| 112 | return rest_ensure_response( $data ); |
|
| 113 | } |
|
| 114 | ||
| 115 | /** |
|
| 116 | * Get all settings in a group. |
|
| @@ 51-68 (lines=18) @@ | ||
| 48 | * @param WP_REST_Request $request |
|
| 49 | * @return WP_REST_Response|WP_Error |
|
| 50 | */ |
|
| 51 | public function get_items( $request ) { |
|
| 52 | $zone = $this->get_zone( $request['id'] ); |
|
| 53 | ||
| 54 | if ( is_wp_error( $zone ) ) { |
|
| 55 | return $zone; |
|
| 56 | } |
|
| 57 | ||
| 58 | $locations = $zone->get_zone_locations(); |
|
| 59 | $data = array(); |
|
| 60 | ||
| 61 | foreach ( $locations as $location_obj ) { |
|
| 62 | $location = $this->prepare_item_for_response( $location_obj, $request ); |
|
| 63 | $location = $this->prepare_response_for_collection( $location ); |
|
| 64 | $data[] = $location; |
|
| 65 | } |
|
| 66 | ||
| 67 | return rest_ensure_response( $data ); |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * Update all Shipping Zone Locations. |
|
| @@ 87-103 (lines=17) @@ | ||
| 84 | * @param WP_REST_Request $request |
|
| 85 | * @return WP_REST_Response|WP_Error |
|
| 86 | */ |
|
| 87 | public function get_items( $request ) { |
|
| 88 | $zone = $this->get_zone( $request['zone_id'] ); |
|
| 89 | ||
| 90 | if ( is_wp_error( $zone ) ) { |
|
| 91 | return $zone; |
|
| 92 | } |
|
| 93 | ||
| 94 | $methods = $zone->get_shipping_methods(); |
|
| 95 | $data = array(); |
|
| 96 | ||
| 97 | foreach ( $methods as $method_obj ) { |
|
| 98 | $method = $this->prepare_item_for_response( $method_obj, $request ); |
|
| 99 | $data[] = $method; |
|
| 100 | } |
|
| 101 | ||
| 102 | return rest_ensure_response( $data ); |
|
| 103 | } |
|
| 104 | ||
| 105 | /** |
|
| 106 | * Prepare the Shipping Zone Method for the REST response. |
|