Skip to content

Commit 8ed28a3

Browse files
authored
Merge pull request #6 from aligent/feature/complete-products-api
Feature/complete products api
2 parents 7a21034 + e38556d commit 8ed28a3

33 files changed

+982
-5
lines changed

README.md

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# BigCommerce V3 Api Library
22

3+
![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/aligent/bigcommerce-api-client/dev-main)
4+
![Latest Release](https://img.shields.io/github/v/release/aligent/bigcommerce-v3-api-php-client?sort=semver)
5+
36
## Introduction
47
This is an (very) early development version of an easy-to-use API client for BigCommerce.
58

@@ -39,14 +42,66 @@ $products = $productsResponse->getProducts();
3942

4043
Running tests: `composer run-script test`
4144

45+
4246
## Coverage
4347

44-
Catalog API
48+
### Store Management
49+
50+
#### Customers
51+
52+
- ☑️ Customers
53+
- ☐ Addresses
54+
- ☐ Attributes
55+
- ☐ Attribute Values
56+
- ☐ Form Field Values
57+
- ☐ Consent
58+
59+
#### Orders (V3)
60+
61+
- ☐ Transactions
62+
- ☐ Order Refunds
63+
64+
#### Payment Methods
65+
66+
- ☐ Payment Access Token
67+
- ☐ Payment Methods
68+
69+
#### Scripts
70+
71+
- ☐ Scripts
72+
73+
#### Subscribers
74+
75+
- ☐ Subscribers
76+
77+
#### Themes
78+
79+
- ☐ Themes
80+
- ☐ Theme Actions
81+
- ☐ Theme Jobs
82+
83+
#### Widgets
84+
85+
- ☐ Regions
86+
- ☐ Widget Template
87+
- ☐ Widget
88+
- ☐ Placement
89+
90+
### Catalog
91+
92+
#### Catalog API
93+
94+
- ☑️ Brands
95+
- ☑️ Category
96+
- ☑️ Product
97+
- ☑️ Summary
98+
- ☐ Variants
99+
100+
#### Price Lists
45101

46-
- Brands
47-
- Category
48-
- Product (partial)
49-
- Summary
102+
- ☐ Price Lists
103+
- ☐ Assignments
104+
- ☐ Records
50105

51106
## Still To Do
52107

src/BigCommerce/Catalog/Products/ModifiersApi.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace BigCommerce\ApiV3\Catalog\Products;
44

55
use BigCommerce\ApiV3\Api\ResourceApi;
6+
use BigCommerce\ApiV3\Catalog\Products\ProductModifier\ProductModifierImagesApi;
67
use BigCommerce\ApiV3\Catalog\Products\ProductModifier\ProductModifierValuesApi;
78
use BigCommerce\ApiV3\ResourceModels\Catalog\Product\ProductModifier;
89
use BigCommerce\ApiV3\ResponseModels\Product\ModifierResponse;
@@ -62,4 +63,11 @@ public function value(int $valueId): ProductModifierValuesApi
6263
$api->setProductId($this->getParentResourceId());
6364
return $api;
6465
}
66+
67+
public function image(int $imageId): ProductModifierImagesApi
68+
{
69+
$api = new ProductModifierImagesApi($this->getClient(), $imageId, $this->getResourceId());
70+
$api->setProductId($this->getParentResourceId());
71+
return $api;
72+
}
6573
}

src/BigCommerce/Catalog/Products/OptionsApi.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace BigCommerce\ApiV3\Catalog\Products;
44

55
use BigCommerce\ApiV3\Api\ResourceApi;
6+
use BigCommerce\ApiV3\Catalog\Products\ProductOption\ProductOptionValuesApi;
67
use BigCommerce\ApiV3\ResourceModels\Catalog\Product\ProductOption;
78
use BigCommerce\ApiV3\ResponseModels\Product\OptionResponse;
89
use BigCommerce\ApiV3\ResponseModels\OptionsResponse;
@@ -47,4 +48,18 @@ protected function multipleResourcesEndpoint(): string
4748
{
4849
return self::OPTIONS_ENDPOINT;
4950
}
51+
52+
public function values(): ProductOptionValuesApi
53+
{
54+
$api = new ProductOptionValuesApi($this->getClient(), null, $this->getResourceId());
55+
$api->setProductId($this->getParentResourceId());
56+
return $api;
57+
}
58+
59+
public function value(int $valueId): ProductOptionValuesApi
60+
{
61+
$api = new ProductOptionValuesApi($this->getClient(), $valueId, $this->getResourceId());
62+
$api->setProductId($this->getParentResourceId());
63+
return $api;
64+
}
5065
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace BigCommerce\ApiV3\Catalog\Products\ProductModifier;
4+
5+
use BigCommerce\ApiV3\Api\ResourceImageApi;
6+
7+
class ProductModifierImagesApi extends ResourceImageApi
8+
{
9+
private int $productId;
10+
11+
private const PRODUCT_MODIFIER_IMAGE_ENDPOINT = 'catalog/products/%s/modifiers/{modifier_id}/values/%s/image';
12+
13+
public function setProductId(int $productId): void
14+
{
15+
$this->productId = $productId;
16+
}
17+
18+
public function getProductId(): int
19+
{
20+
return $this->productId;
21+
}
22+
23+
protected function singleResourceEndpoint(): string
24+
{
25+
return self::PRODUCT_MODIFIER_IMAGE_ENDPOINT;
26+
}
27+
28+
protected function singleResourceUrl(): string
29+
{
30+
return sprintf(
31+
$this->singleResourceEndpoint(),
32+
$this->getProductId(),
33+
$this->getParentResourceId() ?? $this->getResourceId(),
34+
$this->getResourceId()
35+
);
36+
}
37+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace BigCommerce\ApiV3\Catalog\Products\ProductOption;
4+
5+
use BigCommerce\ApiV3\Api\ResourceApi;
6+
use BigCommerce\ApiV3\ResponseModels\Product\ProductOptionValueResponse;
7+
use BigCommerce\ApiV3\ResponseModels\Product\ProductOptionValuesResponse;
8+
9+
class ProductOptionValuesApi extends ResourceApi
10+
{
11+
private int $productId;
12+
13+
public const RESOURCE_NAME = 'values';
14+
public const VALUES_ENDPOINT = 'catalog/products/%d/options/%d/values';
15+
public const VALUE_ENDPOINT = 'catalog/products/%d/options/%d/values/%d';
16+
17+
public function setProductId(int $productId): void
18+
{
19+
$this->productId = $productId;
20+
}
21+
22+
public function getProductId(): int
23+
{
24+
return $this->productId;
25+
}
26+
27+
protected function singleResourceEndpoint(): string
28+
{
29+
return self::VALUE_ENDPOINT;
30+
}
31+
32+
protected function singleResourceUrl(): string
33+
{
34+
return sprintf(
35+
$this->singleResourceEndpoint(),
36+
$this->getProductId(),
37+
$this->getParentResourceId() ?? $this->getResourceId(),
38+
$this->getResourceId()
39+
);
40+
}
41+
42+
protected function multipleResourcesEndpoint(): string
43+
{
44+
return self::VALUES_ENDPOINT;
45+
}
46+
47+
protected function multipleResourceUrl(): string
48+
{
49+
return sprintf(
50+
$this->multipleResourcesEndpoint(),
51+
$this->getProductId(),
52+
$this->getParentResourceId()
53+
);
54+
}
55+
56+
protected function resourceName(): string
57+
{
58+
return self::RESOURCE_NAME;
59+
}
60+
61+
public function get(): ProductOptionValueResponse
62+
{
63+
return new ProductOptionValueResponse($this->getResource());
64+
}
65+
66+
public function getAll(array $filters = [], int $page = 1, int $limit = 250): ProductOptionValuesResponse
67+
{
68+
return new ProductOptionValuesResponse($this->getAllResources($filters, $page, $limit));
69+
}
70+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace BigCommerce\ApiV3\Catalog\Products;
4+
5+
use BigCommerce\ApiV3\Api\ResourceApi;
6+
use BigCommerce\ApiV3\ResponseModels\PaginatedResponse;
7+
use BigCommerce\ApiV3\ResponseModels\Product\ProductReviewResponse;
8+
use BigCommerce\ApiV3\ResponseModels\Product\ProductReviewsResponse;
9+
use BigCommerce\ApiV3\ResponseModels\SingleResourceResponse;
10+
11+
class ProductReviewsApi extends ResourceApi
12+
{
13+
public const RESOURCE_NAME = 'reviews';
14+
public const REVIEW_ENDPOINT = 'catalog/products/%s/reviews/%s';
15+
public const REVIEWS_ENDPOINT = 'catalog/products/%s/reviews';
16+
17+
protected function singleResourceEndpoint(): string
18+
{
19+
return self::REVIEW_ENDPOINT;
20+
}
21+
22+
protected function multipleResourcesEndpoint(): string
23+
{
24+
return self::REVIEWS_ENDPOINT;
25+
}
26+
27+
protected function resourceName(): string
28+
{
29+
return self::RESOURCE_NAME;
30+
}
31+
32+
public function get(): ProductReviewResponse
33+
{
34+
return new ProductReviewResponse($this->getResource());
35+
}
36+
37+
public function getAll(array $filters = [], int $page = 1, int $limit = 250): ProductReviewsResponse
38+
{
39+
return new ProductReviewsResponse($this->getAllResources($filters, $page, $limit));
40+
}
41+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace BigCommerce\ApiV3\Catalog\Products\ProductVariant;
4+
5+
use BigCommerce\ApiV3\Api\ResourceApi;
6+
use BigCommerce\ApiV3\ResponseModels\Product\ProductVariantMetafieldResponse;
7+
use BigCommerce\ApiV3\ResponseModels\Product\ProductVariantMetafieldsResponse;
8+
9+
class ProductVariantMetafieldsApi extends ResourceApi
10+
{
11+
private int $productId;
12+
13+
private const RESOURCE_NAME = 'metafields';
14+
private const METAFIELD_ENDPOINT = 'catalog/product/%d/variants/%d/metafields/%d';
15+
private const METAFIELDS_ENDPOINT = 'catalog/product/%d/variants/%d/metafields';
16+
17+
public function getProductId(): int
18+
{
19+
return $this->productId;
20+
}
21+
22+
public function setProductId(int $productId): void
23+
{
24+
$this->productId = $productId;
25+
}
26+
27+
protected function singleResourceEndpoint(): string
28+
{
29+
return self::METAFIELD_ENDPOINT;
30+
}
31+
32+
protected function singleResourceUrl(): string
33+
{
34+
return sprintf(
35+
$this->singleResourceEndpoint(),
36+
$this->getProductId(),
37+
$this->getParentResourceId() ?? $this->getResourceId(),
38+
$this->getResourceId()
39+
);
40+
}
41+
42+
protected function multipleResourcesEndpoint(): string
43+
{
44+
return self::METAFIELDS_ENDPOINT;
45+
}
46+
47+
protected function multipleResourceUrl(): string
48+
{
49+
return sprintf(
50+
$this->multipleResourcesEndpoint(),
51+
$this->getProductId(),
52+
$this->getParentResourceId()
53+
);
54+
}
55+
56+
protected function resourceName(): string
57+
{
58+
return self::RESOURCE_NAME;
59+
}
60+
61+
public function get(): ProductVariantMetafieldResponse
62+
{
63+
return new ProductVariantMetafieldResponse($this->getResource());
64+
}
65+
66+
public function getAll(array $filters = [], int $page = 1, int $limit = 250): ProductVariantMetafieldsResponse
67+
{
68+
return new ProductVariantMetafieldsResponse($this->getAllResources($filters, $page, $limit));
69+
}
70+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace BigCommerce\ApiV3\Catalog\Products;
4+
5+
use BigCommerce\ApiV3\Api\ResourceApi;
6+
use BigCommerce\ApiV3\ResponseModels\Product\ProductVideoResponse;
7+
use BigCommerce\ApiV3\ResponseModels\Product\ProductVideosResponse;
8+
9+
class ProductVideosApi extends ResourceApi
10+
{
11+
public const RESOURCE_NAME = 'videos';
12+
public const VIDEO_ENDPOINT = 'catalog/products/%d/videos/%s';
13+
public const VIDEOS_ENDPOINT = 'catalog/products/%d/videos';
14+
15+
protected function singleResourceEndpoint(): string
16+
{
17+
return self::VIDEO_ENDPOINT;
18+
}
19+
20+
protected function multipleResourcesEndpoint(): string
21+
{
22+
return self::VIDEOS_ENDPOINT;
23+
}
24+
25+
protected function resourceName(): string
26+
{
27+
return self::RESOURCE_NAME;
28+
}
29+
30+
public function get(): ProductVideoResponse
31+
{
32+
return new ProductVideoResponse($this->getResource());
33+
}
34+
35+
public function getAll(array $filters = [], int $page = 1, int $limit = 250): ProductVideosResponse
36+
{
37+
return new ProductVideosResponse($this->getAllResources($filters, $page, $limit));
38+
}
39+
}

0 commit comments

Comments
 (0)