├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── composer.json ├── phpstan.neon.dist ├── phpunit.xml ├── rector.php └── src └── Bigcommerce └── Api ├── Client.php ├── ClientError.php ├── Connection.php ├── Error.php ├── Filter.php ├── NetworkError.php ├── Resource.php ├── Resources ├── Address.php ├── Brand.php ├── Category.php ├── Coupon.php ├── Currency.php ├── Customer.php ├── DiscountRule.php ├── Option.php ├── OptionSet.php ├── OptionSetOption.php ├── OptionValue.php ├── Order.php ├── OrderCoupons.php ├── OrderProduct.php ├── OrderStatus.php ├── Page.php ├── Product.php ├── ProductConfigurableField.php ├── ProductCustomField.php ├── ProductGoogleProductSearch.php ├── ProductImage.php ├── ProductOption.php ├── ProductReview.php ├── ProductVideo.php ├── RequestLog.php ├── Rule.php ├── RuleCondition.php ├── Shipment.php ├── ShippingMethod.php ├── ShippingZone.php ├── Sku.php ├── SkuOption.php └── TaxClass.php └── ServerError.php /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to the BigCommerce PHP API Client 2 | 3 | Thanks for showing interest in contributing! 4 | 5 | The following is a set of guidelines for contributing to the BigCommerce PHP API client. These are just guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request. 6 | 7 | By contributing to the BigCommerce PHP API client, you agree that your contributions will be licensed under its MIT license. 8 | 9 | #### Table of Contents 10 | 11 | [API Documentation](https://developer.bigcommerce.com/api) 12 | 13 | [How Can I Contribute?](#how-can-i-contribute) 14 | * [Your First Code Contribution](#your-first-code-contribution) 15 | * [Pull Requests](#pull-requests) 16 | * [Tests](#tests) 17 | 18 | [Styleguides](#styleguides) 19 | * [Git Commit Messages](#git-commit-messages) 20 | 21 | ### Your First Code Contribution 22 | 23 | Unsure where to begin contributing to the API client? Check our [forums](https://forum.bigcommerce.com/s/group/0F913000000HLjECAW), our [stackoverflow](https://stackoverflow.com/questions/tagged/bigcommerce) tag, and the reported [issues](https://github.com/bigcommerce/bigcommerce-api-php/issues). 24 | 25 | ### Tests 26 | You can run tests using the following command: `./vendor/bin/phpunit` 27 | 28 | ### Code quality - PhpStan 29 | To check your code with [phpstan](https://phpstan.org/), run `./vendor/bin/phpstan`. 30 | 31 | **Remove errors from baseline:** 32 | While changing the code you might see the following error from the PhpStan 33 | ``` 34 | Ignored error pattern #.... was not matched in reported errors. 35 | ``` 36 | This means that the error is [no longer present](https://phpstan.org/user-guide/ignoring-errors#reporting-unused-ignores) in the code, so you can remove it from the baseline file. 37 | To do so, run `./vendor/bin/phpstan --generate-baseline=.phpstan/baseline.neon` and commit the changes. 38 | 39 | 40 | ### Pull Requests 41 | 42 | * Fill in [the required template](https://github.com/bigcommerce/bigcommerce-api-php/pull/new/master) 43 | * Include screenshots and animated GIFs in your pull request whenever possible. 44 | * End files with a newline. 45 | 46 | ## Styleguides 47 | 48 | ### Git Commit Messages 49 | 50 | * Use the present tense ("Add feature" not "Added feature") 51 | * Use the imperative mood ("Move cursor to..." not "Moves cursor to...") 52 | * Limit the first line to 72 characters or less 53 | * Reference pull requests and external links liberally 54 | 55 | 56 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) Bigcommerce, 2019. 2 | All rights reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Bigcommerce API Client 2 | ====================== 3 | 4 | PHP client for connecting to the Bigcommerce V2 REST API. 5 | 6 | To find out more, visit the official documentation website: 7 | https://developer.bigcommerce.com/ 8 | 9 | [![Latest Stable Version](https://poser.pugx.org/bigcommerce/api/v/stable.png)](https://packagist.org/packages/bigcommerce/api) 10 | [![Total Downloads](https://poser.pugx.org/bigcommerce/api/downloads.png)](https://packagist.org/packages/bigcommerce/api) 11 | 12 | Requirements 13 | ------------ 14 | 15 | - PHP 8.1 or greater 16 | - `curl` extension enabled 17 | 18 | To generate an OAuth API token, [follow this guide.](https://support.bigcommerce.com/s/article/Store-API-Accounts) 19 | 20 | **To connect to the API with OAuth you will need the following:** 21 | 22 | - client_id 23 | - auth_token 24 | - store_hash 25 | 26 | Installation 27 | ------------ 28 | 29 | Use the following Composer command to install the 30 | API client from [the Bigcommerce vendor on Packagist](https://packagist.org/packages/bigcommerce/api): 31 | 32 | ~~~shell 33 | $ composer require bigcommerce/api 34 | $ composer update 35 | ~~~ 36 | 37 | You can also install composer for your specific project by running the following in the library folder. 38 | 39 | ~~~shell 40 | $ curl -sS https://getcomposer.org/installer | php 41 | $ php composer.phar install 42 | $ composer install 43 | ~~~ 44 | 45 | Namespace 46 | --------- 47 | 48 | All the examples below assume the `Bigcommerce\Api\Client` class is imported 49 | into the scope with the following namespace declaration: 50 | 51 | ~~~php 52 | use Bigcommerce\Api\Client as Bigcommerce; 53 | ~~~ 54 | 55 | Configuration 56 | ------------- 57 | 58 | To use the API client in your PHP code, ensure that you can access `Bigcommerce\Api` 59 | in your autoload path (using Composer’s `vendor/autoload.php` hook is recommended). 60 | 61 | Provide your credentials to the static configuration hook to prepare the API client 62 | for connecting to a store on the Bigcommerce platform: 63 | 64 | ### OAuth 65 | 66 | In order to obtain the auth_token you would consume `Bigcommerce::getAuthToken` method during an installation of a single-click app. Alternatively, if you already have a token, skip to `Bigcommerce::configure` and provide your credentials. 67 | 68 | ~~~php 69 | $object = new \stdClass(); 70 | $object->client_id = 'xxxxxx'; 71 | $object->client_secret = 'xxxxx'; 72 | $object->redirect_uri = 'https://app.com/redirect'; 73 | $object->code = $request->get('code'); 74 | $object->context = $request->get('context'); 75 | $object->scope = $request->get('scope'); 76 | 77 | $authTokenResponse = Bigcommerce::getAuthToken($object); 78 | 79 | Bigcommerce::configure([ 80 | 'client_id' => 'xxxxxxxx', 81 | 'auth_token' => $authTokenResponse->access_token, 82 | 'store_hash' => 'xxxxxxx' 83 | ]); 84 | ~~~ 85 | 86 | ### Basic Auth (deprecated) 87 | ~~~php 88 | Bigcommerce::configure([ 89 | 'store_url' => 'https://store.mybigcommerce.com', 90 | 'username' => 'admin', 91 | 'api_key' => 'd81aada4xc34xx3e18f0xxxx7f36ca' 92 | ]); 93 | ~~~ 94 | 95 | Connecting to the store 96 | ----------------------- 97 | 98 | To test that your configuration was correct and you can successfully connect to 99 | the store, ping the getStoreTime method which will return a DateTime object 100 | representing the current timestamp of the store if successful or null if 101 | unsuccessful: 102 | 103 | ~~~php 104 | $ping = Bigcommerce::getStoreTime(); 105 | 106 | if ($ping) echo $ping->format('H:i:s'); 107 | ~~~ 108 | 109 | Accessing collections and resources (GET) 110 | ----------------------------------------- 111 | 112 | To list all the resources in a collection: 113 | 114 | ~~~php 115 | $products = Bigcommerce::getProducts(); 116 | 117 | foreach ($products as $product) { 118 | echo $product->name; 119 | echo $product->price; 120 | } 121 | ~~~ 122 | 123 | To access a single resource and its connected sub-resources: 124 | 125 | ~~~php 126 | $product = Bigcommerce::getProduct(11); 127 | 128 | echo $product->name; 129 | echo $product->price; 130 | ~~~ 131 | 132 | To view the total count of resources in a collection: 133 | 134 | ~~~php 135 | $count = Bigcommerce::getProductsCount(); 136 | 137 | echo $count; 138 | ~~~ 139 | Paging and Filtering 140 | -------------------- 141 | 142 | All the default collection methods support paging, by passing 143 | the page number to the method as an integer: 144 | 145 | ~~~php 146 | $products = Bigcommerce::getProducts(3); 147 | ~~~ 148 | If you require more specific numbering and paging, you can explicitly specify 149 | a limit parameter: 150 | 151 | ~~~php 152 | $filter = ['page' => 3, 'limit' => 30]; 153 | 154 | $products = Bigcommerce::getProducts($filter); 155 | ~~~ 156 | 157 | To filter a collection, you can also pass parameters to filter by as key-value 158 | pairs: 159 | 160 | ~~~php 161 | $filter = ['is_featured' => true]; 162 | 163 | $featured = Bigcommerce::getProducts($filter); 164 | ~~~ 165 | See the API documentation for each resource for a list of supported filter 166 | parameters. 167 | 168 | Updating existing resources (PUT) 169 | --------------------------------- 170 | 171 | To update a single resource: 172 | 173 | ~~~php 174 | $product = Bigcommerce::getProduct(11); 175 | 176 | $product->name = 'MacBook Air'; 177 | $product->price = 99.95; 178 | $product->update(); 179 | ~~~ 180 | 181 | You can also update a resource by passing an array or stdClass object of fields 182 | you want to change to the global update method: 183 | 184 | ~~~php 185 | $fields = [ 186 | 'name' => 'MacBook Air', 187 | 'price' => 999.95 188 | ]; 189 | 190 | Bigcommerce::updateProduct(11, $fields); 191 | ~~~ 192 | 193 | Creating new resources (POST) 194 | ----------------------------- 195 | 196 | Some resources support creation of new items by posting to the collection. This 197 | can be done by passing an array or stdClass object representing the new 198 | resource to the global create method: 199 | 200 | ~~~php 201 | $fields = [ 202 | 'name' => 'Apple' 203 | ]; 204 | 205 | Bigcommerce::createBrand($fields); 206 | ~~~ 207 | 208 | You can also create a resource by making a new instance of the resource class 209 | and calling the create method once you have set the fields you want to save: 210 | 211 | ~~~php 212 | $brand = new Bigcommerce\Api\Resources\Brand(); 213 | 214 | $brand->name = 'Apple'; 215 | $brand->create(); 216 | ~~~ 217 | 218 | Deleting resources and collections (DELETE) 219 | ------------------------------------------- 220 | 221 | To delete a single resource you can call the delete method on the resource object: 222 | 223 | ~~~php 224 | $category = Bigcommerce::getCategory(22); 225 | $category->delete(); 226 | ~~~ 227 | 228 | You can also delete resources by calling the global wrapper method: 229 | 230 | ~~~php 231 | Bigcommerce::deleteCategory(22); 232 | ~~~ 233 | 234 | Some resources support deletion of the entire collection. You can use the 235 | deleteAll methods to do this: 236 | 237 | ~~~php 238 | Bigcommerce::deleteAllOptionSets(); 239 | ~~~ 240 | 241 | Using The XML API 242 | ----------------- 243 | 244 | By default, the API client handles requests and responses by converting between 245 | JSON strings and their PHP object representations. If you need to work with XML 246 | you can switch the API into XML mode with the useXml method: 247 | 248 | ~~~php 249 | Bigcommerce::useXml(); 250 | ~~~ 251 | 252 | This will configure the API client to use XML for all subsequent requests. Note 253 | that the client does not convert XML to PHP objects. In XML mode, all object 254 | parameters to API create and update methods must be passed as strings 255 | containing valid XML, and all responses from collection and resource methods 256 | (including the ping, and count methods) will return XML strings instead of PHP 257 | objects. An example transaction using XML would look like: 258 | 259 | ~~~php 260 | Bigcommerce::useXml(); 261 | 262 | $xml = ' 263 | 264 | Apple 265 | computers laptops 266 | '; 267 | 268 | $result = Bigcommerce::createBrand($xml); 269 | ~~~ 270 | 271 | Handling Errors And Timeouts 272 | ---------------------------- 273 | 274 | For whatever reason, the HTTP requests at the heart of the API may not always 275 | succeed. 276 | 277 | Every method will return false if an error occurred, and you should always 278 | check for this before acting on the results of the method call. 279 | 280 | In some cases, you may also need to check the reason why the request failed. 281 | This would most often be when you tried to save some data that did not validate 282 | correctly. 283 | 284 | ~~~php 285 | $orders = Bigcommerce::getOrders(); 286 | 287 | if (!$orders) { 288 | $error = Bigcommerce::getLastError(); 289 | echo $error->code; 290 | echo $error->message; 291 | } 292 | ~~~ 293 | 294 | Returning false on errors, and using error objects to provide context is good 295 | for writing quick scripts but is not the most robust solution for larger and 296 | more long-term applications. 297 | 298 | An alternative approach to error handling is to configure the API client to 299 | throw exceptions when errors occur. Bear in mind, that if you do this, you will 300 | need to catch and handle the exception in code yourself. The exception throwing 301 | behavior of the client is controlled using the failOnError method: 302 | 303 | ~~~php 304 | Bigcommerce::failOnError(); 305 | 306 | try { 307 | $orders = Bigcommerce::getOrders(); 308 | 309 | } catch(Bigcommerce\Api\Error $error) { 310 | echo $error->getCode(); 311 | echo $error->getMessage(); 312 | } 313 | ~~~ 314 | 315 | The exceptions thrown are subclasses of Error, representing 316 | client errors and server errors. The API documentation for response codes 317 | contains a list of all the possible error conditions the client may encounter. 318 | 319 | 320 | Verifying SSL certificates 321 | -------------------------- 322 | 323 | By default, the client will attempt to verify the SSL certificate used by the 324 | Bigcommerce store. In cases where this is undesirable, or where an unsigned 325 | certificate is being used, you can turn off this behavior using the verifyPeer 326 | switch, which will disable certificate checking on all subsequent requests: 327 | 328 | ~~~php 329 | Bigcommerce::verifyPeer(false); 330 | ~~~ 331 | 332 | Connecting through a proxy server 333 | --------------------------------- 334 | 335 | In cases where you need to connect to the API through a proxy server, you may 336 | need to configure the client to recognize this. Provide the URL of the proxy 337 | server and (optionally) a port to the useProxy method: 338 | 339 | ~~~php 340 | Bigcommerce::useProxy('http://proxy.example.com', 81); 341 | ~~~ 342 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bigcommerce/api", 3 | "type": "library", 4 | "description": "Enables PHP applications to communicate with the Bigcommerce API.", 5 | "keywords": [ 6 | "api", 7 | "http", 8 | "rest", 9 | "ecommerce", 10 | "business" 11 | ], 12 | "homepage": "https://developer.bigcommerce.com", 13 | "license": "MIT", 14 | "authors": [ 15 | { 16 | "name": "Bigcommerce", 17 | "homepage": "https://www.bigcommerce.com" 18 | } 19 | ], 20 | "require": { 21 | "php": ">=8.1", 22 | "firebase/php-jwt": "~5.0 || ~6.0", 23 | "ext-curl": "*" 24 | }, 25 | "require-dev": { 26 | "friendsofphp/php-cs-fixer": "^3.13", 27 | "php-coveralls/php-coveralls": "^2.7", 28 | "phpunit/phpunit": "^10.0", 29 | "phpstan/phpstan": "^2.0", 30 | "rector/rector": "^2.0" 31 | }, 32 | "autoload": { 33 | "psr-0": { 34 | "Bigcommerce": "src/" 35 | } 36 | }, 37 | "autoload-dev": { 38 | "psr-4": { 39 | "Bigcommerce\\Test\\": "test/" 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /phpstan.neon.dist: -------------------------------------------------------------------------------- 1 | parameters: 2 | level: 6 3 | paths: 4 | - ./src 5 | bootstrapFiles: 6 | - ./vendor/autoload.php 7 | includes: 8 | - .phpstan/baseline.neon 9 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | test/ 17 | 18 | 19 | 20 | 21 | src/ 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /rector.php: -------------------------------------------------------------------------------- 1 | paths([__DIR__ . '/test']); 12 | $rectorConfig->sets([ 13 | PHPUnitSetList::PHPUNIT_100 14 | ]); 15 | }; 16 | -------------------------------------------------------------------------------- /src/Bigcommerce/Api/Client.php: -------------------------------------------------------------------------------- 1 | $settings 84 | * @return void 85 | */ 86 | public static function configure($settings) 87 | { 88 | if (isset($settings['client_id'])) { 89 | self::configureOAuth($settings); 90 | } else { 91 | self::configureBasicAuth($settings); 92 | } 93 | } 94 | 95 | /** 96 | * Configure the API client with the required OAuth credentials. 97 | * 98 | * Requires a settings array to be passed in with the following keys: 99 | * 100 | * - client_id 101 | * - auth_token 102 | * - store_hash 103 | * 104 | * @param array $settings 105 | * @return void 106 | * @throws \Exception 107 | */ 108 | public static function configureOAuth($settings) 109 | { 110 | if (!isset($settings['auth_token'])) { 111 | throw new Exception("'auth_token' must be provided"); 112 | } 113 | 114 | if (!isset($settings['store_hash'])) { 115 | throw new Exception("'store_hash' must be provided"); 116 | } 117 | 118 | if (isset($settings['api_url'])) { 119 | self::$api_url = $settings['api_url']; 120 | } 121 | 122 | if (isset($settings['login_url'])) { 123 | self::$login_url = $settings['login_url']; 124 | } 125 | 126 | self::$client_id = $settings['client_id']; 127 | self::$auth_token = $settings['auth_token']; 128 | self::$store_hash = $settings['store_hash']; 129 | 130 | self::$client_secret = $settings['client_secret'] ?? null; 131 | 132 | self::$api_path = self::$api_url . sprintf(self::$stores_prefix, self::$store_hash); 133 | self::$connection = false; 134 | } 135 | 136 | /** 137 | * Configure the API client with the required credentials. 138 | * 139 | * Requires a settings array to be passed in with the following keys: 140 | * 141 | * - store_url 142 | * - username 143 | * - api_key 144 | * 145 | * @param array $settings 146 | * @return void 147 | * @throws \Exception 148 | */ 149 | public static function configureBasicAuth(array $settings) 150 | { 151 | if (!isset($settings['store_url'])) { 152 | throw new Exception("'store_url' must be provided"); 153 | } 154 | 155 | if (!isset($settings['username'])) { 156 | throw new Exception("'username' must be provided"); 157 | } 158 | 159 | if (!isset($settings['api_key'])) { 160 | throw new Exception("'api_key' must be provided"); 161 | } 162 | 163 | self::$username = $settings['username']; 164 | self::$api_key = $settings['api_key']; 165 | self::$store_url = rtrim($settings['store_url'], '/'); 166 | self::$api_path = self::$store_url . self::$path_prefix; 167 | self::$connection = false; 168 | } 169 | 170 | /** 171 | * Configure the API client to throw exceptions when HTTP errors occur. 172 | * 173 | * Note that network faults will always cause an exception to be thrown. 174 | * 175 | * @param bool $option sets the value of this flag 176 | * @return void 177 | */ 178 | public static function failOnError($option = true) 179 | { 180 | self::connection()->failOnError($option); 181 | } 182 | 183 | /** 184 | * Return XML strings from the API instead of building objects. 185 | * @return void 186 | */ 187 | public static function useXml() 188 | { 189 | self::connection()->useXml(); 190 | } 191 | 192 | /** 193 | * Return JSON objects from the API instead of XML Strings. 194 | * This is the default behavior. 195 | * @return void 196 | */ 197 | public static function useJson() 198 | { 199 | self::connection()->useXml(false); 200 | } 201 | 202 | /** 203 | * Switch SSL certificate verification on requests. 204 | * 205 | * @param bool $option sets the value of this flag 206 | * @return void 207 | */ 208 | public static function verifyPeer($option = false) 209 | { 210 | self::connection()->verifyPeer($option); 211 | } 212 | 213 | /** 214 | * Connect to the internet through a proxy server. 215 | * 216 | * @param string $host host server 217 | * @param int|bool $port port number to use, or false 218 | * @return void 219 | */ 220 | public static function useProxy($host, $port = false) 221 | { 222 | self::connection()->useProxy($host, $port); 223 | } 224 | 225 | /** 226 | * Get error message returned from the last API request if 227 | * failOnError is false (default). 228 | * 229 | * @return string 230 | */ 231 | public static function getLastError() 232 | { 233 | return self::connection()->getLastError(); 234 | } 235 | 236 | /** 237 | * Get an instance of the HTTP connection object. Initializes 238 | * the connection if it is not already active. 239 | * 240 | * @return Connection 241 | */ 242 | private static function connection() 243 | { 244 | if (!self::$connection) { 245 | self::$connection = new Connection(); 246 | if (self::$client_id) { 247 | self::$connection->authenticateOauth(self::$client_id, self::$auth_token); 248 | } else { 249 | self::$connection->authenticateBasic(self::$username, self::$api_key); 250 | } 251 | } 252 | 253 | return self::$connection; 254 | } 255 | 256 | /** 257 | * Convenience method to return instance of the connection 258 | * 259 | * @return Connection 260 | */ 261 | public static function getConnection() 262 | { 263 | return self::connection(); 264 | } 265 | 266 | /** 267 | * Set the HTTP connection object. DANGER: This can screw up your Client! 268 | * 269 | * @param Connection|null $connection The connection to use 270 | * @return void 271 | */ 272 | public static function setConnection(?Connection $connection = null) 273 | { 274 | self::$connection = $connection; 275 | } 276 | 277 | /** 278 | * Get a collection result from the specified endpoint. 279 | * 280 | * @param string $path api endpoint 281 | * @param string $resource resource class to map individual items 282 | * @return mixed array|string mapped collection or XML string if useXml is true 283 | */ 284 | public static function getCollection($path, $resource = 'Resource') 285 | { 286 | $response = self::connection()->get(self::$api_path . $path); 287 | 288 | return self::mapCollection($resource, $response); 289 | } 290 | 291 | /** 292 | * Get a resource entity from the specified endpoint. 293 | * 294 | * @param string $path api endpoint 295 | * @param string $resource resource class to map individual items 296 | * @return mixed Resource|string resource object or XML string if useXml is true 297 | */ 298 | public static function getResource($path, $resource = 'Resource') 299 | { 300 | $response = self::connection()->get(self::$api_path . $path); 301 | 302 | return self::mapResource($resource, $response); 303 | } 304 | 305 | /** 306 | * Get a count value from the specified endpoint. 307 | * 308 | * @param string $path api endpoint 309 | * @return mixed int|string count value or XML string if useXml is true 310 | */ 311 | public static function getCount($path) 312 | { 313 | $response = self::connection()->get(self::$api_path . $path); 314 | 315 | if ($response == false || is_string($response)) { 316 | return $response; 317 | } 318 | 319 | return $response->count; 320 | } 321 | 322 | /** 323 | * Send a post request to create a resource on the specified collection. 324 | * 325 | * @param string $path api endpoint 326 | * @param mixed $object object or XML string to create 327 | * @return mixed 328 | */ 329 | public static function createResource($path, $object) 330 | { 331 | if (is_array($object)) { 332 | $object = (object)$object; 333 | } 334 | 335 | return self::connection()->post(self::$api_path . $path, $object); 336 | } 337 | 338 | /** 339 | * Send a put request to update the specified resource. 340 | * 341 | * @param string $path api endpoint 342 | * @param mixed $object object or XML string to update 343 | * @return mixed 344 | */ 345 | public static function updateResource($path, $object) 346 | { 347 | if (is_array($object)) { 348 | $object = (object)$object; 349 | } 350 | 351 | return self::connection()->put(self::$api_path . $path, $object); 352 | } 353 | 354 | /** 355 | * Send a delete request to remove the specified resource. 356 | * 357 | * @param string $path api endpoint 358 | * @return mixed 359 | */ 360 | public static function deleteResource($path) 361 | { 362 | return self::connection()->delete(self::$api_path . $path); 363 | } 364 | 365 | /** 366 | * Internal method to wrap items in a collection to resource classes. 367 | * 368 | * @param string $resource name of the resource class 369 | * @param mixed $object object collection 370 | * @return Resource[] 371 | */ 372 | private static function mapCollection($resource, $object) 373 | { 374 | if ($object == false || is_string($object)) { 375 | return $object; 376 | } 377 | 378 | $baseResource = __NAMESPACE__ . '\\' . $resource; 379 | self::$resource = (class_exists($baseResource)) ? $baseResource : 'Bigcommerce\\Api\\Resources\\' . $resource; 380 | 381 | return array_map(array(self::class, 'mapCollectionObject'), $object); 382 | } 383 | 384 | /** 385 | * Callback for mapping collection objects resource classes. 386 | * 387 | * @param \stdClass $object 388 | * @return Resource 389 | */ 390 | private static function mapCollectionObject($object) 391 | { 392 | $class = self::$resource; 393 | 394 | return new $class($object); 395 | } 396 | 397 | /** 398 | * Map a single object to a resource class. 399 | * 400 | * @param string $resource name of the resource class 401 | * @param \stdClass|boolean|string $object 402 | * @return bool|\stdClass|string 403 | */ 404 | private static function mapResource($resource, $object) 405 | { 406 | if ($object == false || is_string($object)) { 407 | return $object; 408 | } 409 | 410 | $baseResource = __NAMESPACE__ . '\\' . $resource; 411 | $class = (class_exists($baseResource)) ? $baseResource : 'Bigcommerce\\Api\\Resources\\' . $resource; 412 | return new $class($object); 413 | } 414 | 415 | /** 416 | * Map object representing a count to an integer value. 417 | * 418 | * @param \stdClass|boolean|string $object 419 | * @return int|boolean 420 | */ 421 | private static function mapCount($object) 422 | { 423 | if ($object == false || is_string($object)) { 424 | return $object; 425 | } 426 | 427 | return $object->count; 428 | } 429 | 430 | /** 431 | * Swaps a temporary access code for a long expiry auth token. 432 | * 433 | * @param \stdClass|array $object 434 | * @return \stdClass 435 | */ 436 | public static function getAuthToken($object) 437 | { 438 | $context = array_merge(array('grant_type' => 'authorization_code'), (array)$object); 439 | $connection = new Connection(); 440 | 441 | return $connection->post(self::$login_url . '/oauth2/token', $context); 442 | } 443 | 444 | /** 445 | * @param int $id 446 | * @param string $redirectUrl 447 | * @param string $requestIp 448 | * @return string 449 | */ 450 | public static function getCustomerLoginToken($id, $redirectUrl = '', $requestIp = '') 451 | { 452 | if (empty(self::$client_secret)) { 453 | throw new Exception('Cannot sign customer login tokens without a client secret'); 454 | } 455 | 456 | $payload = array( 457 | 'iss' => self::$client_id, 458 | 'iat' => time(), 459 | 'jti' => bin2hex(random_bytes(32)), 460 | 'operation' => 'customer_login', 461 | 'store_hash' => self::$store_hash, 462 | 'customer_id' => $id 463 | ); 464 | 465 | if (!empty($redirectUrl)) { 466 | $payload['redirect_to'] = $redirectUrl; 467 | } 468 | 469 | if (!empty($requestIp)) { 470 | $payload['request_ip'] = $requestIp; 471 | } 472 | 473 | return JWT::encode($payload, self::$client_secret, 'HS256'); 474 | } 475 | 476 | /** 477 | * Pings the time endpoint to test the connection to the BigCommerce API. 478 | * 479 | * @return ?DateTime 480 | */ 481 | public static function getTime() 482 | { 483 | $response = self::connection()->get(self::$api_url . '/time'); 484 | 485 | if (empty($response) || !is_numeric($response)) { 486 | return null; 487 | } 488 | 489 | // The response from /time is unix time in milliseconds 490 | $seconds = floor($response / 1000); 491 | $milliseconds = $response % 1000; 492 | return DateTime::createFromFormat('U.u', sprintf('%d.%03d', $seconds, $milliseconds)); 493 | } 494 | 495 | /** 496 | * Pings the time endpoint to test the connection to a store. 497 | * 498 | * @return ?DateTime 499 | */ 500 | public static function getStoreTime() 501 | { 502 | $response = self::connection()->get(self::$api_path . '/time'); 503 | 504 | if (!is_object($response) || !property_exists($response, 'time')) { 505 | return null; 506 | } 507 | 508 | return new DateTime("@{$response->time}"); 509 | } 510 | 511 | /** 512 | * Returns the default collection of products. 513 | * 514 | * @param array $filter 515 | * @return mixed array|string list of products or XML string if useXml is true 516 | */ 517 | public static function getProducts($filter = array()) 518 | { 519 | $filter = Filter::create($filter); 520 | return self::getCollection('/products' . $filter->toQuery(), 'Product'); 521 | } 522 | 523 | /** 524 | * Gets collection of images for a product. 525 | * 526 | * @param int $id product id 527 | * @return mixed array|string list of products or XML string if useXml is true 528 | */ 529 | public static function getProductImages($id) 530 | { 531 | return self::getCollection('/products/' . $id . '/images', 'ProductImage'); 532 | } 533 | 534 | /** 535 | * Gets collection of custom fields for a product. 536 | * 537 | * @param int $id product ID 538 | * @return array|string list of products or XML string if useXml is true 539 | */ 540 | public static function getProductCustomFields($id) 541 | { 542 | return self::getCollection('/products/' . $id . '/custom_fields', 'ProductCustomField'); 543 | } 544 | 545 | /** 546 | * Returns a single custom field by given id 547 | * @param int $product_id product id 548 | * @param int $id custom field id 549 | * @return Resources\ProductCustomField|bool Returns ProductCustomField if exists, false if not exists 550 | */ 551 | public static function getProductCustomField($product_id, $id) 552 | { 553 | return self::getResource('/products/' . $product_id . '/custom_fields/' . $id, 'ProductCustomField'); 554 | } 555 | 556 | /** 557 | * Create a new custom field for a given product. 558 | * 559 | * @param int $product_id product id 560 | * @param mixed $object fields to create 561 | * @return Object Object with `id`, `product_id`, `name` and `text` keys 562 | */ 563 | public static function createProductCustomField($product_id, $object) 564 | { 565 | return self::createResource('/products/' . $product_id . '/custom_fields', $object); 566 | } 567 | 568 | /** 569 | * Gets collection of reviews for a product. 570 | * 571 | * @param $id 572 | * @return mixed 573 | */ 574 | public static function getProductReviews($id) 575 | { 576 | return self::getCollection('/products/' . $id . '/reviews/', 'ProductReview'); 577 | } 578 | 579 | /** 580 | * Update the given custom field. 581 | * 582 | * @param int $product_id product id 583 | * @param int $id custom field id 584 | * @param mixed $object custom field to update 585 | * @return mixed 586 | */ 587 | public static function updateProductCustomField($product_id, $id, $object) 588 | { 589 | return self::updateResource('/products/' . $product_id . '/custom_fields/' . $id, $object); 590 | } 591 | 592 | /** 593 | * Delete the given custom field. 594 | * 595 | * @param int $product_id product id 596 | * @param int $id custom field id 597 | * @return mixed 598 | */ 599 | public static function deleteProductCustomField($product_id, $id) 600 | { 601 | return self::deleteResource('/products/' . $product_id . '/custom_fields/' . $id); 602 | } 603 | 604 | /** 605 | * Returns the total number of products in the collection. 606 | * 607 | * @param array $filter 608 | * @return int|string number of products or XML string if useXml is true 609 | */ 610 | public static function getProductsCount($filter = array()) 611 | { 612 | $filter = Filter::create($filter); 613 | return self::getCount('/products/count' . $filter->toQuery()); 614 | } 615 | 616 | /** 617 | * Returns a single product resource by the given id. 618 | * 619 | * @param int $id product id 620 | * @return Resources\Product|string 621 | */ 622 | public static function getProduct($id) 623 | { 624 | return self::getResource('/products/' . $id, 'Product'); 625 | } 626 | 627 | /** 628 | * Create a new product. 629 | * 630 | * @param mixed $object fields to create 631 | * @return mixed 632 | */ 633 | public static function createProduct($object) 634 | { 635 | return self::createResource('/products', $object); 636 | } 637 | 638 | /** 639 | * Update the given product. 640 | * 641 | * @param int $id product id 642 | * @param mixed $object fields to update 643 | * @return mixed 644 | */ 645 | public static function updateProduct($id, $object) 646 | { 647 | return self::updateResource('/products/' . $id, $object); 648 | } 649 | 650 | /** 651 | * Delete the given product. 652 | * 653 | * @param int $id product id 654 | * @return mixed 655 | */ 656 | public static function deleteProduct($id) 657 | { 658 | return self::deleteResource('/products/' . $id); 659 | } 660 | 661 | /** 662 | * Delete all products. 663 | * 664 | * @return mixed 665 | */ 666 | public static function deleteAllProducts() 667 | { 668 | return self::deleteResource('/products'); 669 | } 670 | 671 | /** 672 | * Return the collection of options. 673 | * 674 | * @param array $filter 675 | * @return array 676 | */ 677 | public static function getOptions($filter = array()) 678 | { 679 | $filter = Filter::create($filter); 680 | return self::getCollection('/options' . $filter->toQuery(), 'Option'); 681 | } 682 | 683 | /** 684 | * Create Options 685 | * @param $object 686 | * @return mixed 687 | */ 688 | public static function createOption($object) 689 | { 690 | return self::createResource('/options', $object); 691 | } 692 | 693 | /** 694 | * Update the given option. 695 | * 696 | * @param int $id category id 697 | * @param mixed $object 698 | * @return mixed 699 | */ 700 | public static function updateOption($id, $object) 701 | { 702 | return self::updateResource('/options/' . $id, $object); 703 | } 704 | 705 | /** 706 | * Return the number of options in the collection 707 | * 708 | * @return int 709 | */ 710 | public static function getOptionsCount() 711 | { 712 | return self::getCount('/options/count'); 713 | } 714 | 715 | /** 716 | * Return a single option by given id. 717 | * 718 | * @param int $id option id 719 | * @return Resources\Option 720 | */ 721 | public static function getOption($id) 722 | { 723 | return self::getResource('/options/' . $id, 'Option'); 724 | } 725 | 726 | /** 727 | * Delete the given option. 728 | * 729 | * @param int $id option id 730 | * @return mixed 731 | */ 732 | public static function deleteOption($id) 733 | { 734 | return self::deleteResource('/options/' . $id); 735 | } 736 | 737 | /** 738 | * Return a single value for an option. 739 | * 740 | * @param int $option_id option id 741 | * @param int $id value id 742 | * @return Resources\OptionValue 743 | */ 744 | public static function getOptionValue($option_id, $id) 745 | { 746 | return self::getResource('/options/' . $option_id . '/values/' . $id, 'OptionValue'); 747 | } 748 | 749 | /** 750 | * Return the collection of all option values. 751 | * 752 | * @param array $filter 753 | * @return array 754 | */ 755 | public static function getOptionValues($filter = array()) 756 | { 757 | $filter = Filter::create($filter); 758 | return self::getCollection('/options/values' . $filter->toQuery(), 'OptionValue'); 759 | } 760 | 761 | /** 762 | * The collection of categories. 763 | * 764 | * @param array $filter 765 | * @return array 766 | */ 767 | public static function getCategories($filter = array()) 768 | { 769 | $filter = Filter::create($filter); 770 | return self::getCollection('/categories' . $filter->toQuery(), 'Category'); 771 | } 772 | 773 | /** 774 | * The number of categories in the collection. 775 | * 776 | * @param array $filter 777 | * @return int 778 | */ 779 | public static function getCategoriesCount($filter = array()) 780 | { 781 | $filter = Filter::create($filter); 782 | return self::getCount('/categories/count' . $filter->toQuery()); 783 | } 784 | 785 | /** 786 | * A single category by given id. 787 | * 788 | * @param int $id category id 789 | * @return Resources\Category 790 | */ 791 | public static function getCategory($id) 792 | { 793 | return self::getResource('/categories/' . $id, 'Category'); 794 | } 795 | 796 | /** 797 | * Create a new category from the given data. 798 | * 799 | * @param mixed $object 800 | * @return mixed 801 | */ 802 | public static function createCategory($object) 803 | { 804 | return self::createResource('/categories', $object); 805 | } 806 | 807 | /** 808 | * Update the given category. 809 | * 810 | * @param int $id category id 811 | * @param mixed $object 812 | * @return mixed 813 | */ 814 | public static function updateCategory($id, $object) 815 | { 816 | return self::updateResource('/categories/' . $id, $object); 817 | } 818 | 819 | /** 820 | * Delete the given category. 821 | * 822 | * @param int $id category id 823 | * @return mixed 824 | */ 825 | public static function deleteCategory($id) 826 | { 827 | return self::deleteResource('/categories/' . $id); 828 | } 829 | 830 | /** 831 | * Delete all categories. 832 | * 833 | * @return mixed 834 | */ 835 | public static function deleteAllCategories() 836 | { 837 | return self::deleteResource('/categories'); 838 | } 839 | 840 | /** 841 | * The collection of brands. 842 | * 843 | * @param array $filter 844 | * @return array 845 | */ 846 | public static function getBrands($filter = array()) 847 | { 848 | $filter = Filter::create($filter); 849 | return self::getCollection('/brands' . $filter->toQuery(), 'Brand'); 850 | } 851 | 852 | /** 853 | * The total number of brands in the collection. 854 | * 855 | * @param array $filter 856 | * @return int 857 | */ 858 | public static function getBrandsCount($filter = array()) 859 | { 860 | $filter = Filter::create($filter); 861 | return self::getCount('/brands/count' . $filter->toQuery()); 862 | } 863 | 864 | /** 865 | * A single brand by given id. 866 | * 867 | * @param int $id brand id 868 | * @return Resources\Brand 869 | */ 870 | public static function getBrand($id) 871 | { 872 | return self::getResource('/brands/' . $id, 'Brand'); 873 | } 874 | 875 | /** 876 | * Create a new brand from the given data. 877 | * 878 | * @param mixed $object 879 | * @return mixed 880 | */ 881 | public static function createBrand($object) 882 | { 883 | return self::createResource('/brands', $object); 884 | } 885 | 886 | /** 887 | * Update the given brand. 888 | * 889 | * @param int $id brand id 890 | * @param mixed $object 891 | * @return mixed 892 | */ 893 | public static function updateBrand($id, $object) 894 | { 895 | return self::updateResource('/brands/' . $id, $object); 896 | } 897 | 898 | /** 899 | * Delete the given brand. 900 | * 901 | * @param int $id brand id 902 | * @return mixed 903 | */ 904 | public static function deleteBrand($id) 905 | { 906 | return self::deleteResource('/brands/' . $id); 907 | } 908 | 909 | /** 910 | * Delete all brands. 911 | * 912 | * @return mixed 913 | */ 914 | public static function deleteAllBrands() 915 | { 916 | return self::deleteResource('/brands'); 917 | } 918 | 919 | /** 920 | * The collection of orders. 921 | * 922 | * @param array $filter 923 | * @return array 924 | */ 925 | public static function getOrders($filter = array()) 926 | { 927 | $filter = Filter::create($filter); 928 | return self::getCollection('/orders' . $filter->toQuery(), 'Order'); 929 | } 930 | 931 | /** 932 | * The number of orders in the collection. 933 | * 934 | * @param array $filter 935 | * @return int 936 | */ 937 | public static function getOrdersCount($filter = array()) 938 | { 939 | $filter = Filter::create($filter); 940 | return self::getCount('/orders/count' . $filter->toQuery()); 941 | } 942 | 943 | /** 944 | * The order count grouped by order status 945 | * 946 | * @param array $filter 947 | * @return Resources\OrderStatus 948 | */ 949 | public static function getOrderStatusesWithCounts($filter = array()) 950 | { 951 | $filter = Filter::create($filter); 952 | $resource = self::getResource('/orders/count' . $filter->toQuery(), "OrderStatus"); 953 | return $resource->statuses; 954 | } 955 | 956 | /** 957 | * A single order. 958 | * 959 | * @param int $id order id 960 | * @return Resources\Order 961 | */ 962 | public static function getOrder($id) 963 | { 964 | return self::getResource('/orders/' . $id, 'Order'); 965 | } 966 | 967 | /** 968 | * @param $orderID 969 | * @return mixed 970 | */ 971 | public static function getOrderProducts($orderID) 972 | { 973 | return self::getCollection('/orders/' . $orderID . '/products', 'OrderProduct'); 974 | } 975 | 976 | /** 977 | * The total number of order products in the collection. 978 | * 979 | * @param $orderID 980 | * @param array $filter 981 | * @return mixed 982 | */ 983 | public static function getOrderProductsCount($orderID, $filter = array()) 984 | { 985 | $filter = Filter::create($filter); 986 | return self::getCount('/orders/' . $orderID . '/products/count' . $filter->toQuery()); 987 | } 988 | 989 | /** 990 | * Delete the given order (unlike in the Control Panel, this will permanently 991 | * delete the order). 992 | * 993 | * @param int $id order id 994 | * @return mixed 995 | */ 996 | public static function deleteOrder($id) 997 | { 998 | return self::deleteResource('/orders/' . $id); 999 | } 1000 | 1001 | /** 1002 | * Delete all orders. 1003 | * 1004 | * @return mixed 1005 | */ 1006 | public static function deleteAllOrders() 1007 | { 1008 | return self::deleteResource('/orders'); 1009 | } 1010 | 1011 | /** 1012 | * Create an order 1013 | * 1014 | * @param $object 1015 | * @return mixed 1016 | */ 1017 | public static function createOrder($object) 1018 | { 1019 | return self::createResource('/orders', $object); 1020 | } 1021 | 1022 | /** 1023 | * Update the given order. 1024 | * 1025 | * @param int $id order id 1026 | * @param mixed $object fields to update 1027 | * @return mixed 1028 | */ 1029 | public static function updateOrder($id, $object) 1030 | { 1031 | return self::updateResource('/orders/' . $id, $object); 1032 | } 1033 | 1034 | /** 1035 | * The list of customers. 1036 | * 1037 | * @param array $filter 1038 | * @return array 1039 | */ 1040 | public static function getCustomers($filter = array()) 1041 | { 1042 | $filter = Filter::create($filter); 1043 | return self::getCollection('/customers' . $filter->toQuery(), 'Customer'); 1044 | } 1045 | 1046 | /** 1047 | * The total number of customers in the collection. 1048 | * 1049 | * @param array $filter 1050 | * @return int 1051 | */ 1052 | public static function getCustomersCount($filter = array()) 1053 | { 1054 | $filter = Filter::create($filter); 1055 | return self::getCount('/customers/count' . $filter->toQuery()); 1056 | } 1057 | 1058 | /** 1059 | * Bulk delete customers. 1060 | * 1061 | * @param array $filter 1062 | * @return array 1063 | */ 1064 | public static function deleteCustomers($filter = array()) 1065 | { 1066 | $filter = Filter::create($filter); 1067 | return self::deleteResource('/customers' . $filter->toQuery()); 1068 | } 1069 | 1070 | /** 1071 | * A single customer by given id. 1072 | * 1073 | * @param int $id customer id 1074 | * @return Resources\Customer 1075 | */ 1076 | public static function getCustomer($id) 1077 | { 1078 | return self::getResource('/customers/' . $id, 'Customer'); 1079 | } 1080 | 1081 | /** 1082 | * Create a new customer from the given data. 1083 | * 1084 | * @param mixed $object 1085 | * @return mixed 1086 | */ 1087 | public static function createCustomer($object) 1088 | { 1089 | return self::createResource('/customers', $object); 1090 | } 1091 | 1092 | /** 1093 | * Update the given customer. 1094 | * 1095 | * @param int $id customer id 1096 | * @param mixed $object 1097 | * @return mixed 1098 | */ 1099 | public static function updateCustomer($id, $object) 1100 | { 1101 | return self::updateResource('/customers/' . $id, $object); 1102 | } 1103 | 1104 | /** 1105 | * Delete the given customer. 1106 | * 1107 | * @param int $id customer id 1108 | * @return mixed 1109 | */ 1110 | public static function deleteCustomer($id) 1111 | { 1112 | return self::deleteResource('/customers/' . $id); 1113 | } 1114 | 1115 | /** 1116 | * A list of addresses belonging to the given customer. 1117 | * 1118 | * @param int $id customer id 1119 | * @return array 1120 | */ 1121 | public static function getCustomerAddresses($id) 1122 | { 1123 | return self::getCollection('/customers/' . $id . '/addresses', 'Address'); 1124 | } 1125 | 1126 | /** 1127 | * Returns the collection of option sets. 1128 | * 1129 | * @param array $filter 1130 | * @return array 1131 | */ 1132 | public static function getOptionSets($filter = array()) 1133 | { 1134 | $filter = Filter::create($filter); 1135 | return self::getCollection('/optionsets' . $filter->toQuery(), 'OptionSet'); 1136 | } 1137 | 1138 | /** 1139 | * Create Optionsets 1140 | * 1141 | * @param $object 1142 | * @return mixed 1143 | */ 1144 | public static function createOptionSet($object) 1145 | { 1146 | return self::createResource('/optionsets', $object); 1147 | } 1148 | 1149 | /** 1150 | * Create Option Set Options 1151 | * 1152 | * @param $object 1153 | * @param $id 1154 | * @return mixed 1155 | */ 1156 | public static function createOptionSetOption($object, $id) 1157 | { 1158 | return self::createResource('/optionsets/' . $id . '/options', $object); 1159 | } 1160 | 1161 | /** 1162 | * Returns the total number of option sets in the collection. 1163 | * 1164 | * @return int 1165 | */ 1166 | public static function getOptionSetsCount() 1167 | { 1168 | return self::getCount('/optionsets/count'); 1169 | } 1170 | 1171 | /** 1172 | * A single option set by given id. 1173 | * 1174 | * @param int $id option set id 1175 | * @return Resources\OptionSet 1176 | */ 1177 | public static function getOptionSet($id) 1178 | { 1179 | return self::getResource('/optionsets/' . $id, 'OptionSet'); 1180 | } 1181 | 1182 | /** 1183 | * Update the given option set. 1184 | * 1185 | * @param int $id option set id 1186 | * @param mixed $object 1187 | * @return mixed 1188 | */ 1189 | public static function updateOptionSet($id, $object) 1190 | { 1191 | return self::updateResource('/optionsets/' . $id, $object); 1192 | } 1193 | 1194 | /** 1195 | * Delete the given option set. 1196 | * 1197 | * @param int $id option id 1198 | * @return mixed 1199 | */ 1200 | public static function deleteOptionSet($id) 1201 | { 1202 | Client::deleteResource('/optionsets/' . $id); 1203 | } 1204 | 1205 | /** 1206 | * Status code used to represent the state of an order. 1207 | * 1208 | * @param int $id order status id 1209 | * 1210 | * @return mixed 1211 | */ 1212 | public static function getOrderStatus($id) 1213 | { 1214 | return self::getResource('/order_statuses/' . $id, 'OrderStatus'); 1215 | } 1216 | 1217 | /** 1218 | * Status codes used to represent the state of an order. 1219 | * 1220 | * @return array 1221 | */ 1222 | public static function getOrderStatuses() 1223 | { 1224 | return self::getCollection('/order_statuses', 'OrderStatus'); 1225 | } 1226 | 1227 | /** 1228 | * Get collection of product skus 1229 | * 1230 | * @param array $filter 1231 | * @return mixed 1232 | */ 1233 | public static function getSkus($filter = array()) 1234 | { 1235 | $filter = Filter::create($filter); 1236 | return self::getCollection('/products/skus' . $filter->toQuery(), 'Sku'); 1237 | } 1238 | 1239 | /** 1240 | * Create a SKU 1241 | * 1242 | * @param $productId 1243 | * @param $object 1244 | * @return mixed 1245 | */ 1246 | public static function createSku($productId, $object) 1247 | { 1248 | return self::createResource('/products/' . $productId . '/skus', $object); 1249 | } 1250 | 1251 | /** 1252 | * Update sku 1253 | * 1254 | * @param $id 1255 | * @param $object 1256 | * @return mixed 1257 | */ 1258 | public static function updateSku($id, $object) 1259 | { 1260 | return self::updateResource('/products/skus/' . $id, $object); 1261 | } 1262 | 1263 | /** 1264 | * Returns the total number of SKUs in the collection. 1265 | * 1266 | * @return int 1267 | */ 1268 | public static function getSkusCount() 1269 | { 1270 | return self::getCount('/products/skus/count'); 1271 | } 1272 | 1273 | /** 1274 | * Returns the googleproductsearch mapping for a product. 1275 | * 1276 | * @return Resources\ProductGoogleProductSearch 1277 | */ 1278 | public static function getGoogleProductSearch($productId) 1279 | { 1280 | return self::getResource('/products/' . $productId . '/googleproductsearch', 'ProductGoogleProductSearch'); 1281 | } 1282 | 1283 | /** 1284 | * Get a single coupon by given id. 1285 | * 1286 | * @param int $id customer id 1287 | * @return Resources\Coupon 1288 | */ 1289 | public static function getCoupon($id) 1290 | { 1291 | return self::getResource('/coupons/' . $id, 'Coupon'); 1292 | } 1293 | 1294 | /** 1295 | * Get coupons 1296 | * 1297 | * @param array $filter 1298 | * @return mixed 1299 | */ 1300 | public static function getCoupons($filter = array()) 1301 | { 1302 | $filter = Filter::create($filter); 1303 | return self::getCollection('/coupons' . $filter->toQuery(), 'Coupon'); 1304 | } 1305 | 1306 | /** 1307 | * Create coupon 1308 | * 1309 | * @param $object 1310 | * @return mixed 1311 | */ 1312 | public static function createCoupon($object) 1313 | { 1314 | return self::createResource('/coupons', $object); 1315 | } 1316 | 1317 | /** 1318 | * Update coupon 1319 | * 1320 | * @param $id 1321 | * @param $object 1322 | * @return mixed 1323 | */ 1324 | public static function updateCoupon($id, $object) 1325 | { 1326 | return self::updateResource('/coupons/' . $id, $object); 1327 | } 1328 | 1329 | /** 1330 | * Delete the given coupon. 1331 | * 1332 | * @param int $id coupon id 1333 | * @return mixed 1334 | */ 1335 | public static function deleteCoupon($id) 1336 | { 1337 | return self::deleteResource('/coupons/' . $id); 1338 | } 1339 | 1340 | /** 1341 | * Delete all Coupons. 1342 | * 1343 | * @return mixed 1344 | */ 1345 | public static function deleteAllCoupons() 1346 | { 1347 | return self::deleteResource('/coupons'); 1348 | } 1349 | 1350 | /** 1351 | * Return the number of coupons 1352 | * 1353 | * @return int 1354 | */ 1355 | public static function getCouponsCount() 1356 | { 1357 | return self::getCount('/coupons/count'); 1358 | } 1359 | 1360 | /** 1361 | * The request logs with usage history statistics. 1362 | */ 1363 | public static function getRequestLogs() 1364 | { 1365 | return self::getCollection('/requestlogs', 'RequestLog'); 1366 | } 1367 | 1368 | public static function getStore() 1369 | { 1370 | $response = self::connection()->get(self::$api_path . '/store'); 1371 | return $response; 1372 | } 1373 | 1374 | /** 1375 | * The number of requests remaining at the current time. Based on the 1376 | * last request that was fetched within the current script. If no 1377 | * requests have been made, pings the time endpoint to get the value. 1378 | * 1379 | * @return int|false 1380 | */ 1381 | public static function getRequestsRemaining() 1382 | { 1383 | $limit = self::connection()->getHeader('X-Rate-Limit-Requests-Left'); 1384 | 1385 | if (!$limit) { 1386 | $result = self::getTime(); 1387 | 1388 | if (!$result) { 1389 | return false; 1390 | } 1391 | 1392 | $limit = self::connection()->getHeader('X-Rate-Limit-Requests-Left'); 1393 | } 1394 | 1395 | return (int)$limit; 1396 | } 1397 | 1398 | /** 1399 | * Get a single shipment by given id. 1400 | * 1401 | * @param $orderID 1402 | * @param $shipmentID 1403 | * @return mixed 1404 | */ 1405 | public static function getShipment($orderID, $shipmentID) 1406 | { 1407 | return self::getResource('/orders/' . $orderID . '/shipments/' . $shipmentID, 'Shipment'); 1408 | } 1409 | 1410 | /** 1411 | * Get shipments for a given order 1412 | * 1413 | * @param $orderID 1414 | * @param array $filter 1415 | * @return mixed 1416 | */ 1417 | public static function getShipments($orderID, $filter = array()) 1418 | { 1419 | $filter = Filter::create($filter); 1420 | return self::getCollection('/orders/' . $orderID . '/shipments' . $filter->toQuery(), 'Shipment'); 1421 | } 1422 | 1423 | /** 1424 | * Create shipment 1425 | * 1426 | * @param $orderID 1427 | * @param $object 1428 | * @return mixed 1429 | */ 1430 | public static function createShipment($orderID, $object) 1431 | { 1432 | return self::createResource('/orders/' . $orderID . '/shipments', $object); 1433 | } 1434 | 1435 | /** 1436 | * Update shipment 1437 | * 1438 | * @param $orderID 1439 | * @param $shipmentID 1440 | * @param $object 1441 | * @return mixed 1442 | */ 1443 | public static function updateShipment($orderID, $shipmentID, $object) 1444 | { 1445 | return self::updateResource('/orders/' . $orderID . '/shipments/' . $shipmentID, $object); 1446 | } 1447 | 1448 | /** 1449 | * Delete the given shipment. 1450 | * 1451 | * @param $orderID 1452 | * @param $shipmentID 1453 | * @return mixed 1454 | */ 1455 | public static function deleteShipment($orderID, $shipmentID) 1456 | { 1457 | return self::deleteResource('/orders/' . $orderID . '/shipments/' . $shipmentID); 1458 | } 1459 | 1460 | /** 1461 | * Delete all Shipments for the given order. 1462 | * 1463 | * @param $orderID 1464 | * @return mixed 1465 | */ 1466 | public static function deleteAllShipmentsForOrder($orderID) 1467 | { 1468 | return self::deleteResource('/orders/' . $orderID . '/shipments'); 1469 | } 1470 | 1471 | /** 1472 | * Get order coupons for a given order 1473 | * 1474 | * @param $orderID 1475 | * @param array $filter 1476 | * @return mixed 1477 | */ 1478 | public static function getOrderCoupons($orderID, $filter = array()) 1479 | { 1480 | $filter = Filter::create($filter); 1481 | return self::getCollection('/orders/' . $orderID . '/coupons' . $filter->toQuery(), 'OrderCoupons'); 1482 | } 1483 | 1484 | /** 1485 | * Get a single order shipping address by given order and order shipping address id. 1486 | * 1487 | * @param $orderID 1488 | * @param $orderShippingAddressID 1489 | * @return mixed 1490 | */ 1491 | public static function getOrderShippingAddress($orderID, $orderShippingAddressID) 1492 | { 1493 | return self::getResource('/orders/' . $orderID . '/shipping_addresses/' . $orderShippingAddressID, 'Address'); 1494 | } 1495 | 1496 | /** 1497 | * Get order shipping addresses for a given order 1498 | * 1499 | * @param $orderID 1500 | * @param array $filter 1501 | * @return mixed 1502 | */ 1503 | public static function getOrderShippingAddresses($orderID, $filter = array()) 1504 | { 1505 | $filter = Filter::create($filter); 1506 | return self::getCollection('/orders/' . $orderID . '/shipping_addresses' . $filter->toQuery(), 'Address'); 1507 | } 1508 | 1509 | /** 1510 | * Create a new currency. 1511 | * 1512 | * @param mixed $object fields to create 1513 | * @return mixed 1514 | */ 1515 | public static function createCurrency($object) 1516 | { 1517 | return self::createResource('/currencies', $object); 1518 | } 1519 | 1520 | /** 1521 | * Returns a single currency resource by the given id. 1522 | * 1523 | * @param int $id currency id 1524 | * @return Resources\Currency|string 1525 | */ 1526 | public static function getCurrency($id) 1527 | { 1528 | return self::getResource('/currencies/' . $id, 'Currency'); 1529 | } 1530 | 1531 | /** 1532 | * Update the given currency. 1533 | * 1534 | * @param int $id currency id 1535 | * @param mixed $object fields to update 1536 | * @return mixed 1537 | */ 1538 | public static function updateCurrency($id, $object) 1539 | { 1540 | return self::updateResource('/currencies/' . $id, $object); 1541 | } 1542 | 1543 | /** 1544 | * Delete the given currency. 1545 | * 1546 | * @param int $id currency id 1547 | * @return mixed 1548 | */ 1549 | public static function deleteCurrency($id) 1550 | { 1551 | return self::deleteResource('/currencies/' . $id); 1552 | } 1553 | 1554 | /** 1555 | * Returns the default collection of currencies. 1556 | * 1557 | * @param array $filter 1558 | * @return mixed array|string list of currencies or XML string if useXml is true 1559 | */ 1560 | public static function getCurrencies($filter = array()) 1561 | { 1562 | $filter = Filter::create($filter); 1563 | return self::getCollection('/currencies' . $filter->toQuery(), 'Currency'); 1564 | } 1565 | 1566 | /** 1567 | * Create a new product image. 1568 | * 1569 | * @param string $productId 1570 | * @param mixed $object 1571 | * @return mixed 1572 | */ 1573 | public static function createProductImage($productId, $object) 1574 | { 1575 | return self::createResource('/products/' . $productId . '/images', $object); 1576 | } 1577 | 1578 | /** 1579 | * Update a product image. 1580 | * 1581 | * @param string $productId 1582 | * @param string $imageId 1583 | * @param mixed $object 1584 | * @return mixed 1585 | */ 1586 | public static function updateProductImage($productId, $imageId, $object) 1587 | { 1588 | return self::updateResource('/products/' . $productId . '/images/' . $imageId, $object); 1589 | } 1590 | 1591 | /** 1592 | * Returns a product image resource by the given product id. 1593 | * 1594 | * @param int $productId 1595 | * @param int $imageId 1596 | * @return Resources\ProductImage|string 1597 | */ 1598 | public static function getProductImage($productId, $imageId) 1599 | { 1600 | return self::getResource('/products/' . $productId . '/images/' . $imageId, 'ProductImage'); 1601 | } 1602 | 1603 | /** 1604 | * Delete the given product image. 1605 | * 1606 | * @param int $productId 1607 | * @param int $imageId 1608 | * @return mixed 1609 | */ 1610 | public static function deleteProductImage($productId, $imageId) 1611 | { 1612 | return self::deleteResource('/products/' . $productId . '/images/' . $imageId); 1613 | } 1614 | 1615 | /** 1616 | * Get all content pages 1617 | * 1618 | * @return mixed 1619 | */ 1620 | public static function getPages() 1621 | { 1622 | return self::getCollection('/pages', 'Page'); 1623 | } 1624 | 1625 | /** 1626 | * Get single content pages 1627 | * 1628 | * @param int $pageId 1629 | * @return mixed 1630 | */ 1631 | public static function getPage($pageId) 1632 | { 1633 | return self::getResource('/pages/' . $pageId, 'Page'); 1634 | } 1635 | 1636 | /** 1637 | * Create a new content pages 1638 | * 1639 | * @param $object 1640 | * @return mixed 1641 | */ 1642 | public static function createPage($object) 1643 | { 1644 | return self::createResource('/pages', $object); 1645 | } 1646 | 1647 | /** 1648 | * Update an existing content page 1649 | * 1650 | * @param int $pageId 1651 | * @param $object 1652 | * @return mixed 1653 | */ 1654 | public static function updatePage($pageId, $object) 1655 | { 1656 | return self::updateResource('/pages/' . $pageId, $object); 1657 | } 1658 | 1659 | /** 1660 | * Delete an existing content page 1661 | * 1662 | * @param int $pageId 1663 | * @return mixed 1664 | */ 1665 | public static function deletePage($pageId) 1666 | { 1667 | return self::deleteResource('/pages/' . $pageId); 1668 | } 1669 | 1670 | /** 1671 | * Create a Gift Certificate 1672 | * 1673 | * @param array $object 1674 | * @return mixed 1675 | */ 1676 | public static function createGiftCertificate($object) 1677 | { 1678 | return self::createResource('/gift_certificates', $object); 1679 | } 1680 | 1681 | /** 1682 | * Get a Gift Certificate 1683 | * 1684 | * @param int $giftCertificateId 1685 | * @return mixed 1686 | */ 1687 | public static function getGiftCertificate($giftCertificateId) 1688 | { 1689 | return self::getResource('/gift_certificates/' . $giftCertificateId); 1690 | } 1691 | 1692 | /** 1693 | * Return the collection of all gift certificates. 1694 | * 1695 | * @param array $filter 1696 | * @return mixed 1697 | */ 1698 | public static function getGiftCertificates($filter = array()) 1699 | { 1700 | $filter = Filter::create($filter); 1701 | return self::getCollection('/gift_certificates' . $filter->toQuery()); 1702 | } 1703 | 1704 | /** 1705 | * Update a Gift Certificate 1706 | * 1707 | * @param int $giftCertificateId 1708 | * @param array $object 1709 | * @return mixed 1710 | */ 1711 | public static function updateGiftCertificate($giftCertificateId, $object) 1712 | { 1713 | return self::updateResource('/gift_certificates/' . $giftCertificateId, $object); 1714 | } 1715 | 1716 | /** 1717 | * Delete a Gift Certificate 1718 | * 1719 | * @param int $giftCertificateId 1720 | * @return mixed 1721 | */ 1722 | public static function deleteGiftCertificate($giftCertificateId) 1723 | { 1724 | return self::deleteResource('/gift_certificates/' . $giftCertificateId); 1725 | } 1726 | 1727 | /** 1728 | * Delete all Gift Certificates 1729 | * 1730 | * @return mixed 1731 | */ 1732 | public static function deleteAllGiftCertificates() 1733 | { 1734 | return self::deleteResource('/gift_certificates'); 1735 | } 1736 | 1737 | /** 1738 | * Create Product Review 1739 | * 1740 | * @param int $productId 1741 | * @param array $object 1742 | * @return mixed 1743 | */ 1744 | public static function createProductReview($productId, $object) 1745 | { 1746 | return self::createResource('/products/' . $productId . '/reviews', $object); 1747 | } 1748 | 1749 | /** 1750 | * Create Product Bulk Discount rules 1751 | * 1752 | * @param string $productId 1753 | * @param array $object 1754 | * @return mixed 1755 | */ 1756 | public static function createProductBulkPricingRules($productId, $object) 1757 | { 1758 | return self::createResource('/products/' . $productId . '/discount_rules', $object); 1759 | } 1760 | 1761 | /** 1762 | * Create a Marketing Banner 1763 | * 1764 | * @param array $object 1765 | * @return mixed 1766 | */ 1767 | public static function createMarketingBanner($object) 1768 | { 1769 | return self::createResource('/banners', $object); 1770 | } 1771 | 1772 | /** 1773 | * Get all Marketing Banners 1774 | * 1775 | * @return mixed 1776 | */ 1777 | public static function getMarketingBanners() 1778 | { 1779 | return self::getCollection('/banners'); 1780 | } 1781 | 1782 | /** 1783 | * Delete all Marketing Banners 1784 | * 1785 | * @return mixed 1786 | */ 1787 | public static function deleteAllMarketingBanners() 1788 | { 1789 | return self::deleteResource('/banners'); 1790 | } 1791 | 1792 | /** 1793 | * Delete a specific Marketing Banner 1794 | * 1795 | * @param int $bannerID 1796 | * @return mixed 1797 | */ 1798 | public static function deleteMarketingBanner($bannerID) 1799 | { 1800 | return self::deleteResource('/banners/' . $bannerID); 1801 | } 1802 | 1803 | /** 1804 | * Update an existing banner 1805 | * 1806 | * @param int $bannerID 1807 | * @param array $object 1808 | * @return mixed 1809 | */ 1810 | public static function updateMarketingBanner($bannerID, $object) 1811 | { 1812 | return self::updateResource('/banners/' . $bannerID, $object); 1813 | } 1814 | 1815 | /** 1816 | * Add a address to the customer's address book. 1817 | * 1818 | * @param int $customerID 1819 | * @param array $object 1820 | * @return mixed 1821 | */ 1822 | public static function createCustomerAddress($customerID, $object) 1823 | { 1824 | return self::createResource('/customers/' . $customerID . '/addresses', $object); 1825 | } 1826 | 1827 | /** 1828 | * Create a product rule 1829 | * 1830 | * @param int $productID 1831 | * @param array $object 1832 | * @return mixed 1833 | */ 1834 | public static function createProductRule($productID, $object) 1835 | { 1836 | return self::createResource('/products/' . $productID . '/rules', $object); 1837 | } 1838 | 1839 | /** 1840 | * Create a customer group. 1841 | * 1842 | * @param array $object 1843 | * @return mixed 1844 | */ 1845 | public static function createCustomerGroup($object) 1846 | { 1847 | return self::createResource('/customer_groups', $object); 1848 | } 1849 | 1850 | /** 1851 | * Get list of customer groups 1852 | * 1853 | * @return mixed 1854 | */ 1855 | public static function getCustomerGroups() 1856 | { 1857 | return self::getCollection('/customer_groups'); 1858 | } 1859 | 1860 | /** 1861 | * Delete a customer group 1862 | * 1863 | * @param int $customerGroupId 1864 | * @return mixed 1865 | */ 1866 | public static function deleteCustomerGroup($customerGroupId) 1867 | { 1868 | return self::deleteResource('/customer_groups/' . $customerGroupId); 1869 | } 1870 | 1871 | /** 1872 | * Delete all customers 1873 | * 1874 | * @return mixed 1875 | */ 1876 | public static function deleteAllCustomers() 1877 | { 1878 | return self::deleteResource('/customers'); 1879 | } 1880 | 1881 | /** 1882 | * Delete all options 1883 | * 1884 | * @return mixed 1885 | */ 1886 | public static function deleteAllOptions() 1887 | { 1888 | return self::deleteResource('/options'); 1889 | } 1890 | 1891 | /** 1892 | * Return the collection of all option values for a given option. 1893 | * 1894 | * @param int $productId 1895 | * @return mixed 1896 | */ 1897 | public static function getProductOptions($productId) 1898 | { 1899 | return self::getCollection('/products/' . $productId . '/options'); 1900 | } 1901 | 1902 | /** 1903 | * Return the collection of all option values for a given option. 1904 | * 1905 | * @param int $productId 1906 | * @param int $productOptionId 1907 | * @return mixed 1908 | */ 1909 | public static function getProductOption($productId, $productOptionId) 1910 | { 1911 | return self::getResource('/products/' . $productId . '/options/' . $productOptionId); 1912 | } 1913 | 1914 | /** 1915 | * Return the collection of all option values for a given option. 1916 | * 1917 | * @param int $productId 1918 | * @param int $productRuleId 1919 | * @return mixed 1920 | */ 1921 | public static function getProductRule($productId, $productRuleId) 1922 | { 1923 | return self::getResource('/products/' . $productId . '/rules/' . $productRuleId); 1924 | } 1925 | 1926 | /** 1927 | * Return the option value object that was created. 1928 | * 1929 | * @param int $optionId 1930 | * @param array $object 1931 | * @return mixed 1932 | */ 1933 | public static function createOptionValue($optionId, $object) 1934 | { 1935 | return self::createResource('/options/' . $optionId . '/values', $object); 1936 | } 1937 | 1938 | /** 1939 | * Delete all option sets that were created. 1940 | * 1941 | * @return mixed 1942 | */ 1943 | public static function deleteAllOptionSets() 1944 | { 1945 | return self::deleteResource('/optionsets'); 1946 | } 1947 | 1948 | /** 1949 | * Return the option value object that was updated. 1950 | * 1951 | * @param int $optionId 1952 | * @param int $optionValueId 1953 | * @param array $object 1954 | * @return mixed 1955 | */ 1956 | public static function updateOptionValue($optionId, $optionValueId, $object) 1957 | { 1958 | return self::updateResource( 1959 | '/options/' . $optionId . '/values/' . $optionValueId, 1960 | $object 1961 | ); 1962 | } 1963 | 1964 | /** 1965 | * Returns all webhooks. 1966 | * 1967 | * @return mixed Resource|string resource object or XML string if useXml is true 1968 | */ 1969 | public static function listWebhooks() 1970 | { 1971 | return self::getCollection('/hooks'); 1972 | } 1973 | 1974 | /** 1975 | * Returns data for a specific web-hook. 1976 | * 1977 | * @param int $id 1978 | * @return mixed Resource|string resource object or XML string if useXml is true 1979 | */ 1980 | public static function getWebhook($id) 1981 | { 1982 | return self::getResource('/hooks/' . $id); 1983 | } 1984 | 1985 | /** 1986 | * Creates a web-hook. 1987 | * 1988 | * @param mixed $object object or XML string to create 1989 | * @return mixed 1990 | */ 1991 | public static function createWebhook($object) 1992 | { 1993 | return self::createResource('/hooks', $object); 1994 | } 1995 | 1996 | /** 1997 | * Updates the given webhook. 1998 | * 1999 | * @param int $id 2000 | * @param mixed $object object or XML string to create 2001 | * @return mixed 2002 | */ 2003 | public static function updateWebhook($id, $object) 2004 | { 2005 | return self::updateResource('/hooks/' . $id, $object); 2006 | } 2007 | 2008 | /** 2009 | * Delete the given webhook. 2010 | * 2011 | * @param int $id 2012 | * @return mixed 2013 | */ 2014 | public static function deleteWebhook($id) 2015 | { 2016 | return self::deleteResource('/hooks/' . $id); 2017 | } 2018 | 2019 | /** 2020 | * Return a collection of shipping-zones 2021 | * 2022 | * @return mixed 2023 | */ 2024 | public static function getShippingZones() 2025 | { 2026 | return self::getCollection('/shipping/zones', 'ShippingZone'); 2027 | } 2028 | 2029 | /** 2030 | * Return a shipping-zone by id 2031 | * 2032 | * @param int $id shipping-zone id 2033 | * @return mixed 2034 | */ 2035 | public static function getShippingZone($id) 2036 | { 2037 | return self::getResource('/shipping/zones/' . $id, 'ShippingZone'); 2038 | } 2039 | 2040 | 2041 | /** 2042 | * Delete the given shipping-zone 2043 | * 2044 | * @param int $id shipping-zone id 2045 | * @return mixed 2046 | */ 2047 | public static function deleteShippingZone($id) 2048 | { 2049 | return self::deleteResource('/shipping/zones/' . $id); 2050 | } 2051 | 2052 | /** 2053 | * Return a shipping-method by id 2054 | * 2055 | * @param $zoneId 2056 | * @param $methodId 2057 | * @return mixed 2058 | */ 2059 | public static function getShippingMethod($zoneId, $methodId) 2060 | { 2061 | return self::getResource('/shipping/zones/'. $zoneId . '/methods/'. $methodId, 'ShippingMethod'); 2062 | } 2063 | 2064 | /** 2065 | * Return a collection of shipping-methods 2066 | * 2067 | * @param $zoneId 2068 | * @return mixed 2069 | */ 2070 | public static function getShippingMethods($zoneId) 2071 | { 2072 | return self::getCollection('/shipping/zones/' . $zoneId . '/methods', 'ShippingMethod'); 2073 | } 2074 | 2075 | 2076 | /** 2077 | * Delete the given shipping-method by id 2078 | * 2079 | * @param $zoneId 2080 | * @param $methodId 2081 | * @return mixed 2082 | */ 2083 | public static function deleteShippingMethod($zoneId, $methodId) 2084 | { 2085 | return self::deleteResource('/shipping/zones/'. $zoneId . '/methods/'. $methodId); 2086 | } 2087 | 2088 | /** 2089 | * Get collection of product skus by Product 2090 | * 2091 | * @param $productId 2092 | * @param array $filter 2093 | * @return mixed 2094 | */ 2095 | public static function getSkusByProduct($productId, $filter = array()) 2096 | { 2097 | $filter = Filter::create($filter); 2098 | return self::getCollection('/products/'.$productId.'/skus' . $filter->toQuery(), 'Sku'); 2099 | } 2100 | 2101 | /** 2102 | * Delete the given optionValue. 2103 | * 2104 | * @param int $optionId 2105 | * @Param int $valueId 2106 | * @return mixed 2107 | */ 2108 | public static function deleteOptionValue($optionId, $valueId) 2109 | { 2110 | return self::deleteResource('/options/' . $optionId .'/values/'. $valueId); 2111 | } 2112 | 2113 | /** 2114 | * Return the collection of all option values By OptionID 2115 | * 2116 | * @param int $optionId 2117 | * @param array $filter 2118 | * @return array 2119 | */ 2120 | public static function getOptionValuesByOption($optionId, $filter = array()) 2121 | { 2122 | $filter = Filter::create($filter); 2123 | return self::getCollection('/options/' . $optionId . '/values' . $filter->toQuery(), 'OptionValue'); 2124 | } 2125 | 2126 | /** 2127 | * Get collection of product rules by ProductId 2128 | * 2129 | * @param int $productId 2130 | * @param array $filter 2131 | * @return mixed 2132 | */ 2133 | public static function getRulesByProduct($productId, $filter = array()) 2134 | { 2135 | $filter = Filter::create($filter); 2136 | return self::getCollection('/products/'.$productId.'/rules' . $filter->toQuery(), 'Rule'); 2137 | } 2138 | } 2139 | -------------------------------------------------------------------------------- /src/Bigcommerce/Api/ClientError.php: -------------------------------------------------------------------------------- 1 | code}): " . $this->message; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Bigcommerce/Api/Connection.php: -------------------------------------------------------------------------------- 1 | Hash of HTTP request headers. 32 | */ 33 | private $headers = []; 34 | 35 | /** 36 | * @var array Hash of headers from HTTP response. Will overwrite headers with duplicates keys eg. it is 37 | * common for a response to have multiple 'set-cookie' headers and only the last one will be kept. 38 | */ 39 | private $responseHeaders = []; 40 | 41 | /** 42 | * @var array 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 |