@@ 161-177 (lines=17) @@ | ||
158 | * @param bool $creating If is creating a new object. |
|
159 | * @return WC_Data|WP_Error |
|
160 | */ |
|
161 | protected function save_object( $request, $creating = false ) { |
|
162 | try { |
|
163 | $object = $this->prepare_object_for_database( $request, $creating ); |
|
164 | ||
165 | if ( is_wp_error( $object ) ) { |
|
166 | return $object; |
|
167 | } |
|
168 | ||
169 | $object->save(); |
|
170 | ||
171 | return $this->get_object( $object->get_id() ); |
|
172 | } catch ( WC_Data_Exception $e ) { |
|
173 | return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() ); |
|
174 | } catch ( WC_REST_Exception $e ) { |
|
175 | return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
176 | } |
|
177 | } |
|
178 | ||
179 | /** |
|
180 | * Create a single item. |
@@ 386-401 (lines=16) @@ | ||
383 | * @param WP_REST_Request $request Full details about the request. |
|
384 | * @return WP_Error|int |
|
385 | */ |
|
386 | protected function save_coupon( $request ) { |
|
387 | try { |
|
388 | $coupon = $this->prepare_item_for_database( $request ); |
|
389 | ||
390 | if ( is_wp_error( $coupon ) ) { |
|
391 | return $coupon; |
|
392 | } |
|
393 | ||
394 | $coupon->save(); |
|
395 | return $coupon->get_id(); |
|
396 | } catch ( WC_Data_Exception $e ) { |
|
397 | return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() ); |
|
398 | } catch ( WC_REST_Exception $e ) { |
|
399 | return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
400 | } |
|
401 | } |
|
402 | ||
403 | /** |
|
404 | * Get the Coupon's schema, conforming to JSON Schema. |
@@ 327-341 (lines=15) @@ | ||
324 | * @param bool $creating If is creating a new object. |
|
325 | * @return WC_Data|WP_Error |
|
326 | */ |
|
327 | protected function save_object( $request, $creating = false ) { |
|
328 | try { |
|
329 | $object = $this->prepare_object_for_database( $request, $creating ); |
|
330 | ||
331 | if ( is_wp_error( $object ) ) { |
|
332 | return $object; |
|
333 | } |
|
334 | ||
335 | return $this->get_object( $object->get_id() ); |
|
336 | } catch ( WC_Data_Exception $e ) { |
|
337 | return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() ); |
|
338 | } catch ( WC_REST_Exception $e ) { |
|
339 | return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
340 | } |
|
341 | } |
|
342 | ||
343 | /** |
|
344 | * Get the Order's schema, conforming to JSON Schema. |