Skip to content

Commit 23b2bce

Browse files
authored
Merge pull request #59 from aligent/feature/improve-documentation
Feature/improve documentation
2 parents 04e2405 + ca0ee85 commit 23b2bce

File tree

504 files changed

+144748
-59
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

504 files changed

+144748
-59
lines changed

README.md

Lines changed: 87 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# BigCommerce V3 Api Library
22

3-
![Latest Release](https://img.shields.io/github/v/release/aligent/bigcommerce-v3-api-php-client?sort=semver)
4-
![Packagist Latest](https://img.shields.io/packagist/v/aligent/bigcommerce-api-client)
3+
[![Latest Release](https://img.shields.io/github/v/release/aligent/bigcommerce-v3-api-php-client?sort=semver)](https://github.com/aligent/bigcommerce-v3-api-php-client/releases)
4+
[![Packagist Latest](https://img.shields.io/packagist/v/aligent/bigcommerce-api-client)](https://packagist.org/packages/aligent/bigcommerce-api-client)
55
![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/aligent/bigcommerce-api-client/dev-main)
6-
![Packagist PHP Version Support](https://img.shields.io/github/license/aligent/bigcommerce-v3-api-php-client)
7-
![Packagist PHP Version Support](https://img.shields.io/github/workflow/status/aligent/bigcommerce-v3-api-php-client/Validate%20PHP%20dependancies%20and%20test)
8-
6+
[![License](https://img.shields.io/github/license/aligent/bigcommerce-v3-api-php-client)](https://github.com/aligent/bigcommerce-v3-api-php-client/blob/main/LICENSE.md)
7+
[![Build Status](https://img.shields.io/github/workflow/status/aligent/bigcommerce-v3-api-php-client/Validate%20PHP%20dependancies%20and%20test)](https://github.com/aligent/bigcommerce-v3-api-php-client/actions/workflows/php.yml)
98

109
## Introduction
1110

12-
This is an easy-to-use API client for BigCommerce.
11+
This is an easy-to-use API client for [BigCommerce](https://developer.bigcommerce.com/api-reference).
1312

1413
## Installation
1514

16-
Install via _composer_: `composer require aligent/bigcommerce-api-client`.
15+
Install [aligent/bigcommerce-api-client ](https://packagist.org/packages/aligent/bigcommerce-api-client)
16+
from packagist using [composer](https://getcomposer.org/): `composer require aligent/bigcommerce-api-client`.
1717

18-
## Usage
18+
## Usage Examples
1919

2020
Trivial example of updating a product name:
2121

@@ -75,68 +75,105 @@ try {
7575
}
7676
```
7777

78-
## Development
78+
### API Design
79+
80+
There are three components to the library:
81+
82+
- [BigCommerce/Api](./src/BigCommerce/Api) - which represent the API endpoints and tries to mimic the layout of the
83+
documentation.
84+
85+
- [BigCommerce/ResourceModels](./src/BigCommerce/ResourceModels) - which represent the resources that are sent to and
86+
received from the API, for example a `Product` or an `Order`.
87+
88+
- [BigCommerce/ResponseModels](./src/BigCommerce/ResponseModels) - which represent the responses from the BigCommerce
89+
API.
90+
91+
For additional documentation, see the [code documentation](https://aligent.github.io/bigcommerce-v3-api-php-client/).
92+
93+
#### API Classes
94+
95+
To interact with the API, always start with the [BigCommerce\ApiV3\Client](./src/BigCommerce/Client.php) class. All APIs
96+
can be accessed in two ways: with and without an ID.
97+
98+
If you are querying about a specific resource instance (e.g. Product 5), then you would use singular endpoint (
99+
`->catalog()->product(5)`), otherwise you would use the plural endpoint (i.e. `->catalog()->products()`).
100+
101+
For example, suppose we want to find all the metafields for a brand with and id of `123`. Our query is for a _specific_
102+
brand, but any metafield, so the call would look like:
103+
104+
```php
105+
$api = new BigCommerce\ApiV3\Client($_ENV['hash'], $_ENV['CLIENT_ID'], $_ENV['ACCESS_TOKEN']);
106+
107+
$metafieldsResponse = $api->catalog()->brand(123)->metafields()->getAll();
108+
$metafields = $metafieldsResponse->getMetafields();
109+
```
79110

80-
Running tests: `composer run-script test`
111+
Suppose we now want to delete metafield `456` on brand `123`. Now our query is for a _specific_ brand and a _specific_
112+
metafield.
81113

114+
```php
115+
$api = new BigCommerce\ApiV3\Client($_ENV['hash'], $_ENV['CLIENT_ID'], $_ENV['ACCESS_TOKEN']);
82116

83-
## Coverage
117+
$api->catalog()->brand(123)->metafield(456)->delete();
118+
```
84119

85-
### Store Management
120+
#### Resource Model Classes
86121

87-
#### Customers
122+
The resource models represent the resources we provided to the API and the responses we receive.
88123

89-
- ☑️ Customers
90-
- ☑️ Addresses
91-
- ☑️ Attributes
92-
- ☑️ Attribute Values
93-
- ☑️ Form Field Values
94-
- ☑️ Consent
124+
To create a new resource, simply instantiate a new object of the correct resource model and then send it to the create
125+
endpoint. For example, if we want to create a new brand:
95126

96-
#### Orders (V3)
127+
```php
128+
$api = new BigCommerce\ApiV3\Client($_ENV['hash'], $_ENV['CLIENT_ID'], $_ENV['ACCESS_TOKEN']);
97129

98-
- ☑️ Order Metafields
99-
- ☑️ Transactions
100-
- ☑️ Order Refunds
130+
$brand = new BigCommerce\ApiV3\ResourceModels\Catalog\Brand\Brand();
131+
$brand->name = "My Brand";
132+
$brand->meta_description = "My wonderful brand";
101133

102-
#### Payment Methods
134+
$api->catalog()->brands()->create($brand);
135+
```
103136

104-
- ☑️ Payment Access Token
105-
- ☑️ Payment Methods
137+
#### Response Model Classes
106138

107-
#### Scripts
139+
Responses from the API all use similar response classes for consistency. There are two types generally: singular responses,
140+
and plural responses. Singular responses will have a single method in the format `get<resource>()`,
141+
for example (`ProductResponse::getProduct()`). Plural responses will have two methods, a `getPagination()`
142+
and `get<resources>()` (e.g. `ProductsResponse::getProducts()`).
108143

109-
- ☑️ Scripts
144+
Note that the API request is sent when the action is called and the response
145+
is returned.
110146

111-
#### Subscribers
147+
```php
148+
$api = new BigCommerce\ApiV3\Client($_ENV['hash'], $_ENV['CLIENT_ID'], $_ENV['ACCESS_TOKEN']);
112149

113-
- ☑️ Subscribers
150+
// Singular Responses
151+
$category = $api->catalog()->category(456)->get()->getCategory();
152+
$brand = $api->catalog()->brand(123)->get()->getBrand();
114153

115-
#### Themes
154+
// Plural Responses
155+
$categoryResponse = $api->catalog()->categories()->getAll(limit: 10);
156+
$totalCategories = $categoryResponse->getPagination()->total;
157+
$categories = $categoryResponse->getCategories();
116158

117-
- ☑️ Themes
118-
- ☑️ Theme Actions
119-
- ☑️ Theme Jobs
159+
$brands = $api->catalog()->brands()->getAll()->getBrands();
160+
```
120161

121-
#### Widgets
162+
## Development
122163

123-
- ☑️ Regions
124-
- ☑️ Widget Template
125-
- ☑️ Widget
126-
- ☑️ Placement
164+
- Running tests: `composer run-script test`
165+
- Checking PHP style rules: `composer run-scruot check-style`
166+
- Auto fix code style rules: `composer run-script fix-style`
127167

128-
### Catalog
168+
### Writing Tests
129169

130-
#### Catalog API
170+
All tests are located in the _tests_ folder in the namespace `BigCommerce\Tests`. The namespace should match the class
171+
being tested after this, e.g. `BigCommerce\Tests\Api\Carts` for testing `BigCommerce\ApiV3\Api\Carts\CartsApi`.
131172

132-
- ☑️ Brands
133-
- ☑️ Category
134-
- ☑️ Product
135-
- ☑️ Summary
136-
- ☑️ Variants
173+
Responses can be mocked using the `BigCommerceApiTest::setReturnData()` function then you can inspect the request that
174+
was made with `BigCommerceApiTest::getLastRequest()`. Response JSON files are stored in _tests/BigCommerce/responses_.
137175

138-
#### Price Lists
176+
## Full Documentation
139177

140-
- ☑️ Price Lists
141-
- ☑️ Assignments
142-
- ☑️ Records
178+
If you would like to have full class documentation, run
179+
`docker run --rm -v /path/to/vendor/aligent/bigcommerce-api:/data phpdoc/phpdoc:3 run -d /data/src -t /data/docs --defaultpackagename BigCommerce --visibility public`

docs/_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
theme: jekyll-theme-cayman

0 commit comments

Comments
 (0)