File tree Expand file tree Collapse file tree 4 files changed +43
-6
lines changed
tests/BigCommerce/Api/Catalog Expand file tree Collapse file tree 4 files changed +43
-6
lines changed Original file line number Diff line number Diff line change 3
3
- Implement the [ Cart API] ( https://developer.bigcommerce.com/api-reference/store-management/carts/cart/createacart ) .
4
4
- Implement the [ Cart Items API] ( https://developer.bigcommerce.com/api-reference/store-management/carts/cart-items/addcartlineitem )
5
5
- Implement the [ Cart Redirect URLS API] ( https://developer.bigcommerce.com/api-reference/store-management/carts/cart-redirect-urls/createcartredirecturl )
6
+ - Allow the use of [ parameters in ProductsApi::Get] ( https://developer.bigcommerce.com/api-reference/store-management/catalog/products/getproductbyid ) .
7
+
8
+ Here's an example using PHP 8:
9
+
10
+ ``` php
11
+ $product = $api->catalog()->product(123)->get(include_fields: ['description', 'sku'])->getProduct();
12
+ ```
13
+
14
+ ### Bug Fix
15
+
16
+ Fix issue with ProductVariant::sku_id not being nullable #47 (thanks @Yorgv )
17
+
18
+
Original file line number Diff line number Diff line change @@ -24,13 +24,30 @@ class ProductsApi extends ResourceWithBatchUpdateApi
24
24
public const FILTER_SKU_IS = 'sku ' ;
25
25
26
26
public const FILTER_INCLUDE_FIELDS = 'include_fields ' ;
27
+ public const FILTER_EXCLUDE_FIELDS = 'exclude_fields ' ;
27
28
28
29
public const FILTER_INCLUDE = 'include ' ;
29
30
public const INCLUDE_MODIFIERS = 'modifiers ' ;
30
31
31
- public function get (): ProductResponse
32
- {
33
- return new ProductResponse ($ this ->getResource ());
32
+ public function get (
33
+ ?string $ include = null ,
34
+ ?array $ include_fields = null ,
35
+ ?array $ exclude_fields = null
36
+ ): ProductResponse {
37
+ $ params = [];
38
+
39
+ if (!is_null ($ include )) {
40
+ $ params [self ::FILTER_INCLUDE ] = $ include ;
41
+ }
42
+ if (!is_null ($ include_fields )) {
43
+ $ params [self ::FILTER_INCLUDE_FIELDS ] = implode (', ' , $ include_fields );
44
+ ;
45
+ }
46
+ if (!is_null ($ exclude_fields )) {
47
+ $ params [self ::FILTER_EXCLUDE_FIELDS ] = implode (', ' , $ exclude_fields );
48
+ }
49
+
50
+ return new ProductResponse ($ this ->getResource ($ params ));
34
51
}
35
52
36
53
public function getAll (array $ filters = [], int $ page = 1 , int $ limit = 250 ): ProductsResponse
Original file line number Diff line number Diff line change 3
3
namespace BigCommerce \ApiV3 \Api \Generic ;
4
4
5
5
use BigCommerce \ApiV3 \Client ;
6
+ use GuzzleHttp \RequestOptions ;
6
7
use Psr \Http \Message \ResponseInterface ;
7
8
8
9
trait GetResource
9
10
{
10
11
abstract public function singleResourceUrl (): string ;
11
12
abstract public function getClient (): Client ;
12
13
13
- protected function getResource (): ResponseInterface
14
+ protected function getResource (array $ queryParams = [] ): ResponseInterface
14
15
{
15
- return $ this ->getClient ()->getRestClient ()->get ($ this ->singleResourceUrl ());
16
+ return $ this ->getClient ()->getRestClient ()->get (
17
+ $ this ->singleResourceUrl (),
18
+ [
19
+ RequestOptions::QUERY => $ queryParams ,
20
+ ]
21
+ );
16
22
}
17
23
}
Original file line number Diff line number Diff line change @@ -30,8 +30,9 @@ public function testCanGetProducts(): void
30
30
public function testCanGetProduct (): void
31
31
{
32
32
$ this ->setReturnData ('catalog__products__174__get.json ' );
33
- $ productResponse = $ this ->getApi ()->catalog ()->product (174 )->get ();
33
+ $ productResponse = $ this ->getApi ()->catalog ()->product (174 )->get (null , [ ' weight ' , ' width ' ] );
34
34
$ this ->assertEquals (174 , $ productResponse ->getProduct ()->id );
35
+ $ this ->assertEquals ('include_fields=weight%2Cwidth ' , $ this ->getLastRequest ()->getUri ()->getQuery ());
35
36
}
36
37
37
38
public function testCanGetAllPagesForProducts (): void
You can’t perform that action at this time.
0 commit comments