Skip to content

Commit eb7f4d8

Browse files
committed
Updated Structure and added 'v3' for Cart and Catalog/brands.
1 parent 43a81a7 commit eb7f4d8

14 files changed

Lines changed: 814 additions & 50 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
vendor
2-
composer.lock
2+
/composer.lock
33
*.sh
44
script/*
55

@@ -10,3 +10,4 @@ script/*
1010
.env
1111
/.php_cs
1212
/.php_cs.cache
13+
/test.php

README.md

Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,315 @@ into the scope with the following namespace declaration:
5656
use Bigcommerce\Api\Client as Bigcommerce;
5757
~~~
5858

59+
V3 Update - *NEW
60+
---------
61+
This update is on the development with `Backward Compatibility` and can be easily customised on future version releases. Feel free to add more features and create issues.
62+
63+
`configureBasicAuth` is Completely removed now you can only configure using `auth_token, client_id and store_hash`
64+
65+
Now you can set the version on Configuration and can be overridden anywhere in the code.
66+
~~~php
67+
Bigcommerce::configure(array(
68+
'client_id' => 'xxxxxxxxxxxxxxxxxxxxxx',
69+
'auth_token' => 'xxxxxxxxxxxxxxxxxxxxxxx',
70+
'store_hash' => 'xxxxxxxxx',
71+
'version' => 'v3' //optional By Default set as 'v2'
72+
));
73+
74+
//If you don't want to set version by default, you can always set it in the method.
75+
76+
$brands = Bigcommerce::getBrands([],"v3");
77+
78+
foreach($brands as $brand){
79+
echo $brand->name."\n";
80+
}
81+
~~~
82+
As of now, Only `Carts, Wishlists and Catlalog\brands support 'v3'` other APIs are still in development will be added here once it is completed, Meanwhile `You can still use 'v2' features without any issues`.
83+
84+
Set 'v3' by default if you're only using 'v3' APIs
85+
86+
'v3' methods has `$version` parameter which can be used if you didn't set version 'v3' as default version.
87+
88+
##Carts(V3)
89+
90+
you can do almost all the functions in cart.
91+
92+
**Get Cart by Cart Id**: `getCart($id, $version = null);`
93+
* $id = String Cart Id
94+
* $version = (Optional) String "v2", "v3", ..
95+
~~~php
96+
Bigcommerce::configure(array(
97+
'client_id' => 'xxxxxxxxxxxxxxxxxxxxxx',
98+
'auth_token' => 'xxxxxxxxxxxxxxxxxxxxxxx',
99+
'store_hash' => 'xxxxxxxxx',
100+
'version' => 'v3'
101+
));
102+
$cart = Bigcommerce::getCart();
103+
104+
echo $cart->id;
105+
106+
//for this documentation, I'll use the above example
107+
//$version variable available for only methods that use 'v3', you can use older functions as it was without '$version' variable
108+
109+
110+
//or
111+
112+
Bigcommerce::configure(array(
113+
'client_id' => 'xxxxxxxxxxxxxxxxxxxxxx',
114+
'auth_token' => 'xxxxxxxxxxxxxxxxxxxxxxx',
115+
'store_hash' => 'xxxxxxxxx'
116+
));
117+
118+
$cart = Bigcommerce::getCart("v3");
119+
120+
echo $cart->id;
121+
~~~
122+
**Create Cart**: `createCart($object, $version = null);`
123+
* $object = Array | Object
124+
* $version = (Optional) String "v2", "v3", ..
125+
~~~php
126+
$cart = array(
127+
"customer_id" => 1,
128+
"line_items" => array(
129+
array(
130+
"quantity" => 1,
131+
"product_id" => 1,
132+
"variant_id" => 2
133+
)
134+
)
135+
);
136+
137+
Bigcommerce::createCart($cart); //or Bigcommerce::createCart($cart,"v3");
138+
139+
//or
140+
141+
$cart = new Bigcommerce\Api\Resources\Cart();
142+
$cart->customer_id = 1;
143+
$cart->line_items = array(
144+
array(
145+
"quantity" => 1,
146+
"product_id" => 1,
147+
"variant_id" => 2
148+
)
149+
);
150+
$cart->create(); // CartObject->create($version = 'v3'); $version (Optional)
151+
~~~
152+
**Update Cart**: `updateCartCustomerId($cart_id, $customer_id, $version = null);`
153+
154+
Note: Only `Customer Id` can be updated by update cart api
155+
* $cart_id = String Cart Id
156+
* $customer_id = Int Customer Id
157+
* $version = (Optional) String "v2", "v3", ..
158+
~~~php
159+
Bigcommerce::updateCartCustomerId("xxxxxxxxx",1);
160+
161+
//or
162+
163+
$cart = Bigcommerce::getCart("xxxxxxxxxxx");
164+
$cart->update(41) // CartObject->update($customer_id, $version = 'v3'); $version (Optional)
165+
~~~
166+
**Delete Cart**: `deleteCart($cart_id, $version = null);`
167+
* $cart_id = String Cart Id
168+
~~~php
169+
Bigcommerce::deleteCart("xxxxxxxxx",1);
170+
171+
//or
172+
173+
$cart = Bigcommerce::getCart("xxxxxxxxxxx");
174+
$cart->delete() // CartObject->delete($version = 'v3'); $version (Optional)
175+
~~~
176+
177+
**Add Cart Items**: `createCartLineItems($id, $object, $filter = array(), $version = null);`
178+
* $id = String Cart Id
179+
* $object = Array|Object
180+
* $filter = (Optional) Array Example ['include'=>'redirect_urls']
181+
~~~php
182+
$items = array(
183+
"line_items" => array(
184+
array(
185+
"quantity" => 1,
186+
"product_id" => 1,
187+
"variant_id" => 2
188+
),
189+
array(
190+
"quantity" => 1,
191+
"product_id" => 2,
192+
"variant_id" => 3
193+
)
194+
)
195+
);
196+
197+
Bigcommerce::createCartLineItems("xxxxxxxxx",$items);
198+
199+
//or
200+
201+
$cart = Bigcommerce::getCart("xxxxxxxxxxx");
202+
$cart->addItems($items) // CartObject->addItems($items, $filter = array(), $version = 'v3'); $filter, $version (Optional)
203+
~~~
204+
205+
**Update Cart Item**: `updateCartLineItem($cart_id, $line_item_id, $object, $filter = array(), $version = null);`
206+
* $cart_id = String Cart Id
207+
* $line_item_id = String Line Item Id
208+
* $object = Array|Object
209+
* $filter = (Optional) Array Example ['include'=>'redirect_urls']
210+
~~~php
211+
$item = array(
212+
"line_items" => array(
213+
"quantity" => 1,
214+
"product_id" => 1,
215+
"variant_id" => 2
216+
)
217+
);
218+
219+
Bigcommerce::updateCartLineItem("xxxxxxxxx","xxxxxxxxx",$item);
220+
~~~
221+
222+
**Delete Cart Item**: `deleteCartLineItem($cart_id, $line_item_id, $version = null);`
223+
* $cart_id = String Cart Id
224+
* $line_item_id = String Line Item Id
225+
~~~php
226+
Bigcommerce::deleteCartLineItem("xxxxxxxxx","xxxxxxxxx");
227+
~~~
228+
229+
##Brands (V2 and V3)
230+
you can use both 'v2' and 'v3' in Brands and I'm trying to do the same for all new versions.
231+
232+
**Get All Brands**: `getBrands($filter = array(), $version = null);`
233+
* $filter = Array filter options refer Bigcommerce documentation for more.
234+
* $version = (Optional) String "v2", "v3", ..
235+
~~~php
236+
Bigcommerce::configure(array(
237+
'client_id' => 'xxxxxxxxxxxxxxxxxxxxxx',
238+
'auth_token' => 'xxxxxxxxxxxxxxxxxxxxxxx',
239+
'store_hash' => 'xxxxxxxxx'
240+
));
241+
// By default version will be 'v2'
242+
// API url will be https://api.bigcommerce.com/stores/{store_hash}/v2/brands
243+
$brands = Bigcommerce::getBrands();
244+
245+
//or
246+
247+
Bigcommerce::configure(array(
248+
'client_id' => 'xxxxxxxxxxxxxxxxxxxxxx',
249+
'auth_token' => 'xxxxxxxxxxxxxxxxxxxxxxx',
250+
'store_hash' => 'xxxxxxxxx',
251+
'version' => 'v3' \\ Optional
252+
));
253+
254+
// API url will be https://api.bigcommerce.com/stores/{store_hash}/v3/catalog/brands
255+
$brands = Bigcommerce::getBrands([],"v3");
256+
~~~
257+
**Get Brand by Brand Id:** `getBrand($id, $version = null);`
258+
* $id = Int Brand Id.
259+
* $version = (Optional) String "v2", "v3", ..
260+
~~~php
261+
$brand = Bigcommerce::getBrand(1);
262+
//or
263+
$brand = Bigcommerce::getBrand(1,"v3");
264+
265+
echo $brand->name;
266+
~~~
267+
**Create Brand:** `createBrand($object, $version = null);`
268+
* $object = Array|Object API Payload.
269+
* $version = (Optional) String "v2", "v3", ..
270+
~~~php
271+
$brand = array(
272+
"name" => "test"
273+
);
274+
$brand = Bigcommerce::createBrand($brand,'v3');
275+
//or
276+
$brand = new Bigcommerce\Api\Resources\Brand();
277+
$brand->name = "test";
278+
$brand->create(); // BrandObject->create($version = null); $version (Optional)
279+
~~~
280+
**Update Brand:** `createBrand($id, $object, $version = null);`
281+
* $id = Int Brand Id.
282+
* $object = Array|Object
283+
* $version = (Optional) String "v2", "v3", ..
284+
~~~php
285+
$brand = array(
286+
"name" => "test"
287+
);
288+
$brand = Bigcommerce::updateBrand(1, $brand, 'v3');
289+
//or
290+
$brand = Bigcommerce::getBrand(1);
291+
$brand->name = "test";
292+
$brand->update(); // BrandObject->update($version = null); $version (Optional)
293+
~~~
294+
**Delete Brand:** `deleteBrand($id, $version = null);`
295+
* $id = Int Brand Id.
296+
* $version = (Optional) String "v2", "v3", ..
297+
~~~php
298+
Bigcommerce::deleteBrand(1);
299+
//or
300+
$brand = Bigcommerce::getBrand(1);
301+
$brand->delete(); // BrandObject->delete($version = null); $version (Optional)
302+
~~~
303+
**Delete All Brand:** `deleteAllBrands($version = null);`
304+
* $version = (Optional) String "v2", "v3", ..
305+
~~~php
306+
Bigcommerce::deleteAllBrands();
307+
~~~
308+
**Get All Brand Meta Fields (Only on 'v3'):** `getBrandMetafields($id, $filter = array(), $version = null);`
309+
* $id = Int Brand Id
310+
* $filter = (Optional) Array|Object
311+
* $version = (Optional) String "v2", "v3", ..
312+
~~~php
313+
Bigcommerce::getBrandMetafields(1, array(), 'v3');
314+
~~~
315+
**Get Brand Meta Field by Id (Only on 'v3'):** `getBrandMetafield($brand_id, $metafield_id, $filter = array(), $version = null);`
316+
* $brand_id = Int Brand Id
317+
* $metafield_id = Int Brand Meta Field Id
318+
* $filter = (Optional) Array|Object
319+
* $version = (Optional) String "v2", "v3", ..
320+
~~~php
321+
Bigcommerce::getBrandMetafield(1, 1, array(), 'v3');
322+
~~~
323+
**Create Brand Meta Field (Only on 'v3'):** `createBrandMetafield($id, $object, $version = null);`
324+
* $id = Int Brand Id
325+
* $object = Array|Object
326+
* $version = (Optional) String "v2", "v3", ..
327+
~~~php
328+
$metaField = array(
329+
"permission_set" => "app_only",
330+
"namespace" => "App Namespace",
331+
"key" => "location_id",
332+
"value" => "Shelf 3, Bin 5",
333+
);
334+
335+
Bigcommerce::createBrandMetafield(1, $metaField, 'v3');
336+
~~~
337+
338+
**Update Brand Meta Field (Only on 'v3'):** `updateBrandMetafield($brand_id, $metafield_id, $object, $version = null);`
339+
* $brand_id = Int Brand Id
340+
* $metafield_id = Int Brand Meta Field Id
341+
* $object = Array|Object
342+
* $version = (Optional) String "v2", "v3", ..
343+
~~~php
344+
$metaField = array(
345+
"permission_set" => "app_only",
346+
"namespace" => "App Namespace",
347+
"key" => "location_id",
348+
"value" => "Shelf 3",
349+
);
350+
351+
Bigcommerce::updateBrandMetafield(1, 1, $metaField, 'v3');
352+
~~~
353+
354+
**Delete Brand Meta Field (Only on 'v3'):** `updateBrandMetafield($brand_id, $metafield_id, $version = null);`
355+
* $brand_id = Int Brand Id
356+
* $metafield_id = Int Brand Meta Field Id
357+
* $version = (Optional) String "v2", "v3", ..
358+
~~~php
359+
Bigcommerce::deleteBrandMetafield(1, 1, 'v3');
360+
~~~
361+
362+
That's all for now. I'll update for other APIs Continuously. **Feel free to Pull and Merge for other APIs**
363+
364+
I'll publish this repo on composer for easy Installation
365+
366+
**You can use all the features and Methods Below**
367+
59368
Configuration
60369
-------------
61370

@@ -90,6 +399,7 @@ Bigcommerce::configure(array(
90399
~~~
91400

92401
### Basic Auth (deprecated)
402+
**Update - Totally Removed**
93403
~~~php
94404
Bigcommerce::configure(array(
95405
'store_url' => 'https://store.mybigcommerce.com',

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "bigcommerce/api",
2+
"name": "naveenrajbu/bigcommerce-api-php-v3",
33
"type": "library",
44
"description": "Enables PHP applications to communicate with the Bigcommerce API.",
55
"keywords": [
@@ -15,6 +15,11 @@
1515
{
1616
"name": "Bigcommerce",
1717
"homepage": "http://www.bigcommerce.com"
18+
},
19+
{
20+
"name": "Naveen Raj",
21+
"homepage": "https://github.com/naveenrajbu/",
22+
"email": "nvenrj@gmail.com"
1823
}
1924
],
2025
"require": {
@@ -29,7 +34,7 @@
2934
},
3035
"autoload": {
3136
"psr-0": {
32-
"Bigcommerce": "src/"
37+
"Bigcommerce\\Api": "src/"
3338
}
3439
},
3540
"autoload-dev": {

0 commit comments

Comments
 (0)