Returns all response headers grouped by their header key. This preserves all response headers.
43 | */
44 | private array $responseHeadersList = [];
45 |
46 | /**
47 | * The status line of the response.
48 | * @var string
49 | */
50 | private $responseStatusLine;
51 |
52 | /**
53 | * @var string response body
54 | */
55 | private $responseBody;
56 |
57 | /**
58 | * @var boolean
59 | */
60 | private $failOnError = false;
61 |
62 | /**
63 | * Manually follow location redirects. Used if CURLOPT_FOLLOWLOCATION
64 | * is unavailable due to open_basedir restriction.
65 | * @var boolean
66 | */
67 | private $followLocation = false;
68 |
69 | /**
70 | * Maximum number of redirects to try.
71 | * @var int
72 | */
73 | private $maxRedirects = 20;
74 |
75 | /**
76 | * Number of redirects followed in a loop.
77 | * @var int
78 | */
79 | private $redirectsFollowed = 0;
80 |
81 | /**
82 | * Deal with failed requests if failOnError is not set.
83 | * @var string|false
84 | */
85 | private $lastError = false;
86 |
87 | /**
88 | * Determines whether the response body should be returned as a raw string.
89 | * @var bool
90 | */
91 | private $rawResponse = false;
92 |
93 | /**
94 | * Determines the default content type to use with requests and responses.
95 | * @var string
96 | */
97 | private $contentType;
98 |
99 | /**
100 | * Initializes the connection object.
101 | */
102 | public function __construct()
103 | {
104 | if (!defined('STDIN')) {
105 | define('STDIN', fopen('php://stdin', 'r'));
106 | }
107 | $this->curl = curl_init();
108 | curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, [$this, 'parseHeader']);
109 | curl_setopt($this->curl, CURLOPT_WRITEFUNCTION, [$this, 'parseBody']);
110 | curl_setopt($this->curl, CURLOPT_USERAGENT, 'PHP CURL - Bigcommerce API Client');
111 |
112 | // Set to a blank string to make cURL include all encodings it can handle (gzip, deflate, identity) in the 'Accept-Encoding' request header and respect the 'Content-Encoding' response header
113 | curl_setopt($this->curl, CURLOPT_ENCODING, '');
114 |
115 | if (!ini_get("open_basedir")) {
116 | curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
117 | } else {
118 | $this->followLocation = true;
119 | }
120 |
121 | $this->setTimeout(60);
122 | }
123 |
124 | /**
125 | * Controls whether requests and responses should be treated
126 | * as XML. Defaults to false (using JSON).
127 | *
128 | * @param bool $option the new state of this feature
129 | * @return void
130 | */
131 | public function useXml($option = true)
132 | {
133 | if ($option) {
134 | $this->contentType = self::MEDIA_TYPE_XML;
135 | $this->rawResponse = true;
136 | } else {
137 | $this->contentType = self::MEDIA_TYPE_JSON;
138 | $this->rawResponse = false;
139 | }
140 | }
141 |
142 | /**
143 | * Controls whether requests or responses should be treated
144 | * as urlencoded form data.
145 | *
146 | * @param bool $option the new state of this feature
147 | * @return void
148 | */
149 | public function useUrlEncoded($option = true)
150 | {
151 | if ($option) {
152 | $this->contentType = self::MEDIA_TYPE_WWW;
153 | }
154 | }
155 |
156 | /**
157 | * Throw an exception if the request encounters an HTTP error condition.
158 | *
159 | * An error condition is considered to be:
160 | *
161 | *
162 | * - 400-499 - Client error
163 | * - 500-599 - Server error
164 | *
165 | *
166 | * Note that this doesn't use the builtin CURL_FAILONERROR option,
167 | * as this fails fast, making the HTTP body and headers inaccessible.
168 | *
169 | * @param bool $option the new state of this feature
170 | * @return void
171 | */
172 | public function failOnError($option = true)
173 | {
174 | $this->failOnError = $option;
175 | }
176 |
177 | /**
178 | * Sets the HTTP basic authentication.
179 | *
180 | * @param string $username
181 | * @param string $password
182 | * @return void
183 | */
184 | public function authenticateBasic($username, $password)
185 | {
186 | curl_setopt($this->curl, CURLOPT_USERPWD, "$username:$password");
187 | }
188 |
189 | /**
190 | * Sets Oauth authentication headers
191 | *
192 | * @param string $clientId
193 | * @param string $authToken
194 | * @return void
195 | */
196 | public function authenticateOauth($clientId, $authToken)
197 | {
198 | $this->addHeader('X-Auth-Client', $clientId);
199 | $this->addHeader('X-Auth-Token', $authToken);
200 | }
201 |
202 | /**
203 | * Set a default timeout for the request. The client will error if the
204 | * request takes longer than this to respond.
205 | *
206 | * @param int $timeout number of seconds to wait on a response
207 | * @return void
208 | */
209 | public function setTimeout($timeout)
210 | {
211 | curl_setopt($this->curl, CURLOPT_TIMEOUT, $timeout);
212 | curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, $timeout);
213 | }
214 |
215 | /**
216 | * Set a proxy server for outgoing requests to tunnel through.
217 | *
218 | * @param string $server
219 | * @param int|bool $port optional port number
220 | * @return void
221 | */
222 | public function useProxy($server, $port = false)
223 | {
224 | curl_setopt($this->curl, CURLOPT_PROXY, $server);
225 |
226 | if ($port) {
227 | curl_setopt($this->curl, CURLOPT_PROXYPORT, $port);
228 | }
229 | }
230 |
231 | /**
232 | * @todo may need to handle CURLOPT_SSL_VERIFYHOST and CURLOPT_CAINFO as well
233 | * @param bool $option Whether to verify the peer's SSL certificate
234 | * @return void
235 | */
236 | public function verifyPeer($option = false)
237 | {
238 | curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, $option);
239 | }
240 |
241 | /**
242 | * Add a custom header to the request.
243 | *
244 | * @param string $header
245 | * @param string $value
246 | * @return void
247 | */
248 | public function addHeader($header, $value)
249 | {
250 | $this->headers[$header] = "$header: $value";
251 | }
252 |
253 | /**
254 | * Remove a header from the request.
255 | *
256 | * @param string $header
257 | * @return void
258 | */
259 | public function removeHeader($header)
260 | {
261 | unset($this->headers[$header]);
262 | }
263 |
264 | /**
265 | * Return the request headers
266 | *
267 | * @return array
268 | */
269 | public function getRequestHeaders()
270 | {
271 | return $this->headers;
272 | }
273 |
274 | /**
275 | * Get the MIME type that should be used for this request.
276 | *
277 | * Defaults to application/json
278 | * @return string
279 | */
280 | private function getContentType()
281 | {
282 | return ($this->contentType) ? $this->contentType : self::MEDIA_TYPE_JSON;
283 | }
284 |
285 | /**
286 | * Clear previously cached request data and prepare for
287 | * making a fresh request.
288 | * @return void
289 | */
290 | private function initializeRequest()
291 | {
292 | $this->responseBody = '';
293 | $this->responseHeaders = [];
294 | $this->responseHeadersList = [];
295 | $this->responseStatusLine = '';
296 | $this->lastError = false;
297 | $this->addHeader('Accept', $this->getContentType());
298 |
299 | curl_setopt($this->curl, CURLOPT_POST, false);
300 | curl_setopt($this->curl, CURLOPT_PUT, false);
301 | curl_setopt($this->curl, CURLOPT_HTTPGET, false);
302 |
303 | curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this->headers);
304 | }
305 |
306 | /**
307 | * Check the response for possible errors and handle the response body returned.
308 | *
309 | * If failOnError is true, a client or server error is raised, otherwise returns false
310 | * on error.
311 | *
312 | * @return mixed
313 | */
314 | private function handleResponse()
315 | {
316 | if (curl_errno($this->curl)) {
317 | throw new NetworkError(curl_error($this->curl), curl_errno($this->curl), $this->responseHeaders);
318 | }
319 |
320 | $body = ($this->rawResponse) ? $this->getBody() : json_decode($this->getBody());
321 |
322 | $status = $this->getStatus();
323 |
324 | if ($status >= 400 && $status <= 499) {
325 | if ($this->failOnError) {
326 | throw new ClientError($body, $status, $this->responseHeaders);
327 | } else {
328 | $this->lastError = $body;
329 | return false;
330 | }
331 | } elseif ($status >= 500 && $status <= 599) {
332 | if ($this->failOnError) {
333 | throw new ServerError($body, $status, $this->responseHeaders);
334 | } else {
335 | $this->lastError = $body;
336 | return false;
337 | }
338 | }
339 |
340 | if ($this->followLocation) {
341 | $this->followRedirectPath();
342 | }
343 |
344 | return $body;
345 | }
346 |
347 | /**
348 | * Return an representation of an error returned by the last request, or false
349 | * if the last request was not an error.
350 | * @return false|string
351 | */
352 | public function getLastError()
353 | {
354 | return $this->lastError;
355 | }
356 |
357 | /**
358 | * Recursively follow redirect until an OK response is received or
359 | * the maximum redirects limit is reached.
360 | *
361 | * Only 301 and 302 redirects are handled. Redirects from POST and PUT requests will
362 | * be converted into GET requests, as per the HTTP spec.
363 | * @return void
364 | */
365 | private function followRedirectPath()
366 | {
367 | $this->redirectsFollowed++;
368 |
369 | if ($this->getStatus() == 301 || $this->getStatus() == 302) {
370 | if ($this->redirectsFollowed < $this->maxRedirects) {
371 | $location = $this->getHeader('Location');
372 | $forwardTo = parse_url($location);
373 |
374 | if (isset($forwardTo['scheme']) && isset($forwardTo['host'])) {
375 | $url = $location;
376 | } else {
377 | $forwardFrom = parse_url(curl_getinfo($this->curl, CURLINFO_EFFECTIVE_URL));
378 | $url = $forwardFrom['scheme'] . '://' . $forwardFrom['host'] . $location;
379 | }
380 |
381 | $this->get($url);
382 | } else {
383 | $errorString = "Too many redirects when trying to follow location.";
384 | throw new NetworkError($errorString, CURLE_TOO_MANY_REDIRECTS, $this->responseHeaders);
385 | }
386 | } else {
387 | $this->redirectsFollowed = 0;
388 | }
389 | }
390 |
391 | /**
392 | * Make an HTTP GET request to the specified endpoint.
393 | *
394 | * @param string $url URL to retrieve
395 | * @param array|bool $query Optional array of query string parameters
396 | *
397 | * @return mixed
398 | */
399 | public function get($url, $query = false)
400 | {
401 | $this->initializeRequest();
402 |
403 | if (is_array($query)) {
404 | $url .= '?' . http_build_query($query);
405 | }
406 |
407 | curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'GET');
408 | curl_setopt($this->curl, CURLOPT_URL, $url);
409 | curl_setopt($this->curl, CURLOPT_POST, false);
410 | curl_setopt($this->curl, CURLOPT_PUT, false);
411 | curl_setopt($this->curl, CURLOPT_HTTPGET, true);
412 | curl_exec($this->curl);
413 |
414 | return $this->handleResponse();
415 | }
416 |
417 | /**
418 | * Make an HTTP POST request to the specified endpoint.
419 | *
420 | * @param string $url URL to which we send the request
421 | * @param mixed $body Data payload (JSON string or raw data)
422 | *
423 | * @return mixed
424 | */
425 | public function post($url, $body)
426 | {
427 | $this->addHeader('Content-Type', $this->getContentType());
428 |
429 | if (!is_string($body)) {
430 | $body = json_encode($body);
431 | }
432 |
433 | $this->initializeRequest();
434 |
435 | curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'POST');
436 | curl_setopt($this->curl, CURLOPT_URL, $url);
437 | curl_setopt($this->curl, CURLOPT_POST, true);
438 | curl_setopt($this->curl, CURLOPT_PUT, false);
439 | curl_setopt($this->curl, CURLOPT_HTTPGET, false);
440 | curl_setopt($this->curl, CURLOPT_POSTFIELDS, $body);
441 | curl_exec($this->curl);
442 |
443 | return $this->handleResponse();
444 | }
445 |
446 | /**
447 | * Make an HTTP HEAD request to the specified endpoint.
448 | *
449 | * @param string $url URL to which we send the request
450 | * @return mixed
451 | */
452 | public function head($url)
453 | {
454 | $this->initializeRequest();
455 |
456 | curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'HEAD');
457 | curl_setopt($this->curl, CURLOPT_URL, $url);
458 | curl_setopt($this->curl, CURLOPT_NOBODY, true);
459 | curl_exec($this->curl);
460 |
461 | return $this->handleResponse();
462 | }
463 |
464 | /**
465 | * Make an HTTP PUT request to the specified endpoint.
466 | *
467 | * Requires a tmpfile() handle to be opened on the system, as the cURL
468 | * API requires it to send data.
469 | *
470 | * @param string $url URL to which we send the request
471 | * @param mixed $body Data payload (JSON string or raw data)
472 | * @return mixed
473 | */
474 | public function put($url, $body)
475 | {
476 | $this->addHeader('Content-Type', $this->getContentType());
477 |
478 | if (!is_string($body)) {
479 | $body = json_encode($body);
480 | }
481 |
482 | $this->initializeRequest();
483 |
484 | $handle = tmpfile();
485 | fwrite($handle, $body);
486 | fseek($handle, 0);
487 | curl_setopt($this->curl, CURLOPT_INFILE, $handle);
488 | curl_setopt($this->curl, CURLOPT_INFILESIZE, strlen($body));
489 |
490 | curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'PUT');
491 | curl_setopt($this->curl, CURLOPT_URL, $url);
492 | curl_setopt($this->curl, CURLOPT_HTTPGET, false);
493 | curl_setopt($this->curl, CURLOPT_POST, false);
494 | curl_setopt($this->curl, CURLOPT_PUT, true);
495 | curl_exec($this->curl);
496 |
497 | fclose($handle);
498 | curl_setopt($this->curl, CURLOPT_INFILE, STDIN);
499 |
500 | return $this->handleResponse();
501 | }
502 |
503 | /**
504 | * Make an HTTP DELETE request to the specified endpoint.
505 | *
506 | * @param string $url URL to which we send the request
507 | * @return mixed
508 | */
509 | public function delete($url)
510 | {
511 | $this->initializeRequest();
512 |
513 | curl_setopt($this->curl, CURLOPT_PUT, false);
514 | curl_setopt($this->curl, CURLOPT_HTTPGET, false);
515 | curl_setopt($this->curl, CURLOPT_POST, false);
516 | curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
517 | curl_setopt($this->curl, CURLOPT_URL, $url);
518 | curl_exec($this->curl);
519 |
520 | return $this->handleResponse();
521 | }
522 |
523 | /**
524 | * Method that appears unused, but is in fact called by curl
525 | *
526 | * @param CurlHandle $curl
527 | * @param string $body
528 | * @return int
529 | */
530 | private function parseBody($curl, $body)
531 | {
532 | $this->responseBody .= $body;
533 | return strlen($body);
534 | }
535 |
536 | /**
537 | * Method that appears unused, but is in fact called by curl
538 | *
539 | * @param CurlHandle $curl
540 | * @param string $headers
541 | * @return int
542 | */
543 | private function parseHeader($curl, $headers)
544 | {
545 | if (!$this->responseStatusLine && strpos($headers, 'HTTP/') === 0) {
546 | $this->responseStatusLine = $headers;
547 | } else {
548 | $parts = explode(': ', $headers);
549 | if (isset($parts[1])) {
550 | $key = strtolower(trim($parts[0]));
551 | $this->responseHeadersList[$key][] = trim($parts[1]);
552 | $this->responseHeaders[$parts[0]] = trim($parts[1]);
553 | }
554 | }
555 | return strlen($headers);
556 | }
557 |
558 | /**
559 | * Access the status code of the response.
560 | *
561 | * @return mixed
562 | */
563 | public function getStatus()
564 | {
565 | return curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
566 | }
567 |
568 | /**
569 | * Access the message string from the status line of the response.
570 | *
571 | * @return string
572 | */
573 | public function getStatusMessage()
574 | {
575 | return $this->responseStatusLine;
576 | }
577 |
578 | /**
579 | * Access the content body of the response
580 | *
581 | * @return string
582 | */
583 | public function getBody()
584 | {
585 | return $this->responseBody;
586 | }
587 |
588 | /**
589 | * Access given header from the response.
590 | *
591 | * @param string $header Header name to retrieve
592 | *
593 | * @return string|void
594 | */
595 | public function getHeader($header)
596 | {
597 | if (array_key_exists($header, $this->responseHeaders)) {
598 | return $this->responseHeaders[$header];
599 | }
600 | // Do case-insensitive search
601 | foreach ($this->responseHeaders as $k => $v) {
602 | if (strtolower($k) == strtolower($header)) {
603 | return $v;
604 | }
605 | }
606 | }
607 |
608 | /**
609 | * Return an associative array of response headers. Will overwrite headers that share the same key.
610 | * @return array
611 | */
612 | public function getHeaders()
613 | {
614 | return $this->responseHeaders;
615 | }
616 |
617 | /**
618 | * Return full list of response headers as an array of strings. Preserves headers with duplicate keys.
619 | * @return array
620 | */
621 | public function getHeadersList()
622 | {
623 | return $this->responseHeadersList;
624 | }
625 |
626 | /**
627 | * Close the cURL resource when the instance is garbage collected
628 | */
629 | public function __destruct()
630 | {
631 | if ($this->curl !== null) {
632 | curl_close($this->curl);
633 | }
634 | }
635 | }
636 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Error.php:
--------------------------------------------------------------------------------
1 | message;
24 | }
25 |
26 | parent::__construct($message, $code);
27 | $this->headers = $headers;
28 | }
29 |
30 | /**
31 | * @return string[]
32 | */
33 | public function getResponseHeaders(): array
34 | {
35 | return $this->headers;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Filter.php:
--------------------------------------------------------------------------------
1 | $filter);
26 | }
27 |
28 | return new self($filter);
29 | }
30 |
31 | public function __construct($filter = array())
32 | {
33 | $this->parameters = ($filter) ? $filter : array();
34 | }
35 |
36 | public function __set($parameter, $value)
37 | {
38 | $this->parameters[$parameter] = $value;
39 | }
40 |
41 | /**
42 | * Converts the filter into a URL querystring that can be
43 | * applied as GET parameters.
44 | *
45 | * @return string
46 | */
47 | public function toQuery()
48 | {
49 | $query = http_build_query($this->parameters);
50 |
51 | return ($query) ? '?' . $query : '';
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/NetworkError.php:
--------------------------------------------------------------------------------
1 |
34 | */
35 | protected $fieldMap = array();
36 |
37 | /**
38 | * @param \stdClass[]|\stdClass|false $object
39 | */
40 | public function __construct($object = false)
41 | {
42 | if (is_array($object)) {
43 | $object = (isset($object[0])) ? $object[0] : false;
44 | }
45 | $this->fields = ($object) ? $object : new \stdClass;
46 | $this->id = ($object && isset($object->id)) ? $object->id : 0;
47 | }
48 |
49 | /**
50 | * @param string $field
51 | * @return null
52 | */
53 | public function __get($field)
54 | {
55 | // first, find the field we should actually be examining
56 | $fieldName = $this->fieldMap[$field] ?? $field;
57 | // then, if a method exists for the specified field and the field we should actually be examining
58 | // has a value, call the method instead
59 | if (method_exists($this, $field) && isset($this->fields->$fieldName)) {
60 | return $this->$field();
61 | }
62 | // otherwise, just return the field directly (or null)
63 | return (isset($this->fields->$field)) ? $this->fields->$field : null;
64 | }
65 |
66 | /**
67 | * @param string $field
68 | * @param mixed $value
69 | * @return void
70 | */
71 | public function __set($field, $value)
72 | {
73 | $this->fields->$field = $value;
74 | }
75 |
76 | /**
77 | * @param string $field
78 | * @return bool
79 | */
80 | public function __isset($field)
81 | {
82 | return (isset($this->fields->$field));
83 | }
84 |
85 | /**
86 | * @return \stdClass
87 | */
88 | public function getCreateFields()
89 | {
90 | $resource = clone $this->fields;
91 |
92 | foreach ($this->ignoreOnCreate as $field) {
93 | unset($resource->$field);
94 | }
95 |
96 | return $resource;
97 | }
98 |
99 | /**
100 | * @return \stdClass
101 | */
102 | public function getUpdateFields()
103 | {
104 | $resource = clone $this->fields;
105 |
106 | foreach ($this->ignoreOnUpdate as $field) {
107 | unset($resource->$field);
108 | }
109 |
110 | foreach ($resource as $field => $value) {
111 | if ($this->isIgnoredField($field, $value)) {
112 | unset($resource->$field);
113 | }
114 | }
115 |
116 | return $resource;
117 | }
118 |
119 | /**
120 | * @param string $field
121 | * @param mixed $value
122 | * @return bool
123 | */
124 | private function isIgnoredField($field, $value)
125 | {
126 | if ($value === null) {
127 | return true;
128 | }
129 |
130 | if ($value === "" && str_contains($field, "date")) {
131 | return true;
132 | }
133 |
134 | if ($value === 0 && in_array($field, $this->ignoreIfZero, true)) {
135 | return true;
136 | }
137 |
138 | return false;
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/Address.php:
--------------------------------------------------------------------------------
1 | getCreateFields());
26 | }
27 |
28 | /**
29 | * @return mixed
30 | */
31 | public function update()
32 | {
33 | return Client::updateBrand($this->id, $this->getUpdateFields());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/Category.php:
--------------------------------------------------------------------------------
1 | getCreateFields());
28 | }
29 |
30 | /**
31 | * @return mixed
32 | */
33 | public function update()
34 | {
35 | return Client::updateCategory($this->id, $this->getUpdateFields());
36 | }
37 |
38 | /**
39 | * @return mixed
40 | */
41 | public function delete()
42 | {
43 | return Client::deleteCategory($this->id);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/Coupon.php:
--------------------------------------------------------------------------------
1 | getCreateFields());
28 | }
29 |
30 | /**
31 | * @return mixed
32 | */
33 | public function update()
34 | {
35 | return Client::updateCoupon($this->id, $this->getUpdateFields());
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/Currency.php:
--------------------------------------------------------------------------------
1 | getCreateFields());
32 | }
33 |
34 | /**
35 | * @return mixed
36 | */
37 | public function update()
38 | {
39 | return Client::updateCurrency($this->id, $this->getUpdateFields());
40 | }
41 |
42 | /**
43 | * @return mixed
44 | */
45 | public function delete()
46 | {
47 | return Client::deleteCurrency($this->id);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/Customer.php:
--------------------------------------------------------------------------------
1 | fields->addresses->resource, 'Address');
26 | }
27 |
28 | /**
29 | * @return mixed
30 | */
31 | public function create()
32 | {
33 | return Client::createCustomer($this->getCreateFields());
34 | }
35 |
36 | /**
37 | * @return mixed
38 | */
39 | public function update()
40 | {
41 | return Client::updateCustomer($this->id, $this->getUpdateFields());
42 | }
43 |
44 | /**
45 | * @return mixed
46 | */
47 | public function delete()
48 | {
49 | return Client::deleteCustomer($this->id);
50 | }
51 |
52 | /**
53 | * @return string
54 | */
55 | public function getLoginToken()
56 | {
57 | return Client::getCustomerLoginToken($this->id);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/DiscountRule.php:
--------------------------------------------------------------------------------
1 | fields->values->resource, 'OptionValue');
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/OptionSet.php:
--------------------------------------------------------------------------------
1 | fields->options->resource, 'OptionSetOption');
26 | }
27 |
28 | /**
29 | * @return mixed
30 | */
31 | public function create()
32 | {
33 | return Client::createResource('/optionsets', $this->getCreateFields());
34 | }
35 |
36 | /**
37 | * @return void
38 | */
39 | public function update()
40 | {
41 | Client::updateResource('/optionsets/' . $this->id, $this->getUpdateFields());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/OptionSetOption.php:
--------------------------------------------------------------------------------
1 | fields->option->resource, 'Option');
29 | }
30 |
31 | /**
32 | * @return mixed
33 | */
34 | public function create()
35 | {
36 | return Client::createResource('/optionsets/options', $this->getCreateFields());
37 | }
38 |
39 | /**
40 | * @return void
41 | */
42 | public function update()
43 | {
44 | Client::updateResource('/optionsets/options/' . $this->id, $this->getUpdateFields());
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/OptionValue.php:
--------------------------------------------------------------------------------
1 | 'option_id'
28 | );
29 |
30 | /**
31 | * @return mixed|Resource|\stdClass|string
32 | */
33 | public function option()
34 | {
35 | return Client::getResource('/options/' . $this->fields->option_id, 'Option');
36 | }
37 |
38 | /**
39 | * @return mixed
40 | */
41 | public function create()
42 | {
43 | return Client::createResource('/options/' . $this->fields->option_id . '/values', $this->getCreateFields());
44 | }
45 |
46 | /**
47 | * @return void
48 | */
49 | public function update()
50 | {
51 | Client::updateResource('/options/' . $this->fields->option_id . '/values/' . $this->id, $this->getUpdateFields());
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/Order.php:
--------------------------------------------------------------------------------
1 | 'id'
13 | );
14 |
15 | /**
16 | * @return array|mixed|string
17 | */
18 | public function shipments()
19 | {
20 | return Client::getCollection('/orders/' . $this->id . '/shipments', 'Shipment');
21 | }
22 |
23 | /**
24 | * @return array|mixed|string
25 | */
26 | public function products()
27 | {
28 | return Client::getCollection($this->fields->products->resource, 'OrderProduct');
29 | }
30 |
31 | /**
32 | * @return array|mixed|string
33 | */
34 | public function shipping_addresses()
35 | {
36 | return Client::getCollection($this->fields->shipping_addresses->resource, 'Address');
37 | }
38 |
39 | /**
40 | * @return array|mixed|string
41 | */
42 | public function coupons()
43 | {
44 | return Client::getCollection($this->fields->coupons->resource, 'Coupon');
45 | }
46 |
47 | /**
48 | * @return void
49 | */
50 | public function update()
51 | {
52 | $order = new \stdClass; // to use stdClass in global namespace use this...
53 | $order->status_id = $this->status_id;
54 | $order->is_deleted = $this->is_deleted;
55 |
56 | Client::updateResource('/orders/' . $this->id, $order);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/OrderCoupons.php:
--------------------------------------------------------------------------------
1 | getCreateFields());
21 | }
22 |
23 | public function update()
24 | {
25 | return Client::updatePage($this->id, $this->getUpdateFields());
26 | }
27 |
28 | public function delete()
29 | {
30 | return Client::deletePage($this->id);
31 | }
32 |
33 | public function getAll()
34 | {
35 | return Client::getPages();
36 | }
37 |
38 | public function get()
39 | {
40 | return Client::getPage($this->id);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/Product.php:
--------------------------------------------------------------------------------
1 | fields->brand->resource, 'Brand');
50 | }
51 |
52 | public function images()
53 | {
54 | return Client::getCollection($this->fields->images->resource, 'ProductImage');
55 | }
56 |
57 | public function skus()
58 | {
59 | return Client::getCollection($this->fields->skus->resource, 'Sku');
60 | }
61 |
62 | public function rules()
63 | {
64 | return Client::getCollection($this->fields->rules->resource, 'Rule');
65 | }
66 |
67 | public function videos()
68 | {
69 | return Client::getCollection($this->fields->videos->resource, 'ProductVideo');
70 | }
71 |
72 | public function custom_fields()
73 | {
74 | return Client::getCollection($this->fields->custom_fields->resource, 'ProductCustomField');
75 | }
76 |
77 | public function configurable_fields()
78 | {
79 | return Client::getCollection($this->fields->configurable_fields->resource, 'ProductConfigurableField');
80 | }
81 |
82 | public function discount_rules()
83 | {
84 | return Client::getCollection($this->fields->discount_rules->resource, 'DiscountRule');
85 | }
86 |
87 | public function option_set()
88 | {
89 | return Client::getResource($this->fields->option_set->resource, 'OptionSet');
90 | }
91 |
92 | public function options()
93 | {
94 | return Client::getCollection('/products/' . $this->id . '/options', 'ProductOption');
95 | }
96 |
97 | public function create()
98 | {
99 | return Client::createProduct($this->getCreateFields());
100 | }
101 |
102 | public function update()
103 | {
104 | return Client::updateProduct($this->id, $this->getUpdateFields());
105 | }
106 |
107 | public function delete()
108 | {
109 | return Client::deleteProduct($this->id);
110 | }
111 |
112 | public function tax_class()
113 | {
114 | return Client::getResource($this->fields->tax_class->resource, 'TaxClass');
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/ProductConfigurableField.php:
--------------------------------------------------------------------------------
1 | fields->product_id . '/customfields', $this->getCreateFields());
26 | }
27 |
28 | public function update()
29 | {
30 | Client::updateResource('/products/' . $this->fields->product_id . '/customfields/' . $this->id, $this->getUpdateFields());
31 | }
32 |
33 | public function delete()
34 | {
35 | Client::deleteResource('/products/' . $this->fields->product_id . '/customfields/' . $this->id);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/ProductGoogleProductSearch.php:
--------------------------------------------------------------------------------
1 | product_id, $this->getCreateFields());
28 | }
29 |
30 | public function update()
31 | {
32 | return Client::updateProductImage($this->product_id, $this->id, $this->getUpdateFields());
33 | }
34 |
35 | public function delete()
36 | {
37 | return Client::deleteProductImage($this->product_id, $this->id);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/ProductOption.php:
--------------------------------------------------------------------------------
1 | 'option_id'
15 | );
16 |
17 | public function option()
18 | {
19 | return Client::getResource('/options/' . $this->fields->option_id, 'Option');
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/ProductReview.php:
--------------------------------------------------------------------------------
1 | fields->conditions->resource, 'RuleCondition');
26 |
27 | foreach ($conditions as $condition) {
28 | $condition->product_id = $this->product_id;
29 | }
30 |
31 | return $conditions;
32 | }
33 |
34 | public function create()
35 | {
36 | return Client::createResource('/products/' . $this->fields->product_id . '/rules', $this->getCreateFields());
37 | }
38 |
39 | public function update()
40 | {
41 | Client::updateResource('/products/' . $this->fields->product_id . '/rules/' . $this->fields->id, $this->getUpdateFields());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/RuleCondition.php:
--------------------------------------------------------------------------------
1 | product_id . '/rules/' . $this->fields->rule_id . '/conditions', $this->getCreateFields());
27 | }
28 |
29 | public function update()
30 | {
31 | Client::updateResource('/products/' . $this->product_id . '/rules/' . $this->fields->rule_id . '/conditions/' . $this->id, $this->getUpdateFields());
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/Shipment.php:
--------------------------------------------------------------------------------
1 | fields->order_id . '/shipments', $this->getCreateFields());
30 | }
31 |
32 | public function update()
33 | {
34 | return Client::updateResource('/orders/' . $this->fields->order_id . '/shipments/' . $this->id, $this->getUpdateFields());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/ShippingMethod.php:
--------------------------------------------------------------------------------
1 | getCreateFields());
21 | }
22 |
23 | public function update($zoneId)
24 | {
25 | return Client::updateResource('/shipping/zones/' . $zoneId . '/methods/' . $this->id, $this->getUpdateFields());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/ShippingZone.php:
--------------------------------------------------------------------------------
1 | getCreateFields());
21 | }
22 |
23 | public function update()
24 | {
25 | return Client::updateResource('/shipping/zones/'. $this->id, $this->getUpdateFields());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/Sku.php:
--------------------------------------------------------------------------------
1 | fields->options)) {
32 | return $options;
33 | }
34 |
35 | foreach ($this->fields->options as $option) {
36 | $options[] = new SkuOption((object)$option);
37 | }
38 |
39 | return $options;
40 | }
41 |
42 | /**
43 | * @return mixed
44 | */
45 | public function create()
46 | {
47 | return Client::createResource('/products/' . $this->product_id . '/skus', $this->getCreateFields());
48 | }
49 |
50 | public function update()
51 | {
52 | Client::updateResource('/products/' . $this->product_id . '/skus/' . $this->id, $this->getUpdateFields());
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/SkuOption.php:
--------------------------------------------------------------------------------
1 | fields->product_id . '/skus/' . $this->fields->sku_id . '/options', $this->getCreateFields());
30 | }
31 |
32 | /**
33 | * @return void
34 | */
35 | public function update()
36 | {
37 | Client::updateResource('/products/' . $this->fields->product_id . '/skus/' . $this->fields->sku_id . '/options/' . $this->id, $this->getUpdateFields());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Bigcommerce/Api/Resources/TaxClass.php:
--------------------------------------------------------------------------------
1 |