Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Add Product endpoint to ExtendSchema (#6122)
Browse files Browse the repository at this point in the history
* Added ProductSchema Identifier

* Updated get_extended_schema & get_item_response

* Test for extensions field on products

* Updated endpoint extend Readme
  • Loading branch information
MrJnrman authored Apr 11, 2022
1 parent 7268e7b commit 9ab7951
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/extensibility/available-endpoints-to-extend.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ The items endpoint, which is also available on `wc/store/cart` inside the `items

- `CartItemSchema::IDENTIFIER`

## `wc/store/products`

The main products endpoint is extensible via ExtendSchema. The data is available via the `extensions` key for each `product` in the response array.

### Passed Parameters:

- `data_callback`: `$product`.
- `schema_callback` none.

### Key:

- `ProductSchema::IDENTIFIER`

<!-- FEEDBACK -->
---

Expand Down
2 changes: 2 additions & 0 deletions src/StoreApi/Schemas/ExtendSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Automattic\WooCommerce\StoreApi\Schemas\V1\CartItemSchema;
use Automattic\WooCommerce\StoreApi\Schemas\V1\CartSchema;
use Automattic\WooCommerce\StoreApi\Schemas\V1\CheckoutSchema;
use Automattic\WooCommerce\StoreApi\Schemas\V1\ProductSchema;
use Automattic\WooCommerce\StoreApi\Formatters;

/**
Expand All @@ -26,6 +27,7 @@ final class ExtendSchema {
CartItemSchema::IDENTIFIER,
CartSchema::IDENTIFIER,
CheckoutSchema::IDENTIFIER,
ProductSchema::IDENTIFIER,
];

/**
Expand Down
3 changes: 3 additions & 0 deletions src/StoreApi/Schemas/V1/ProductSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ public function get_properties() {
],
],
],
self::EXTENDING_KEY => $this->get_extended_schema( self::IDENTIFIER ),
];
}

Expand Down Expand Up @@ -479,6 +480,8 @@ public function get_item_response( $product ) {
],
( new QuantityLimits() )->get_add_to_cart_limits( $product )
),
self::EXTENDING_KEY => $this->get_extended_data( self::IDENTIFIER, $product ),

];
}

Expand Down
1 change: 1 addition & 0 deletions tests/php/StoreApi/Routes/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function test_get_items() {
$this->assertArrayHasKey( 'is_purchasable', $data[0] );
$this->assertArrayHasKey( 'is_in_stock', $data[0] );
$this->assertArrayHasKey( 'add_to_cart', $data[0] );
$this->assertArrayHasKey( 'extensions', $data[0] );
}

/**
Expand Down

0 comments on commit 9ab7951

Please sign in to comment.