|
1 |
| -# php-shopify |
2 |
| -PHP SDK for Shopify API |
| 1 | +# PHP Shopify SDK |
| 2 | +PHPShopify is a simple SDK implementation of Shopify API. It helps accessing the API in an object oriented way. |
| 3 | + |
| 4 | +## Installation |
| 5 | +PHPShopify is composer supported but still not sumitted to packagist. For the time being you can download and put this into `vendor/phpclassic` folder and add the following code into your `composer.json` file: |
| 6 | + |
| 7 | +``` |
| 8 | + "autoload": { |
| 9 | + "psr-4": { |
| 10 | + "PHPShopify\\": "vendor/phpclassic/php-shopify/lib/" |
| 11 | + } |
| 12 | + } |
| 13 | +``` |
| 14 | + |
| 15 | +### Requirements |
| 16 | +PHPShopify uses CURL extension for handling http calls to the API. So you need to be have enabled the curl extension. |
| 17 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | +PHPShopify is developed in a fully object oriented way. Usage is very simple. |
| 21 | + |
| 22 | +#### Configure |
| 23 | +If you are using your own private API, provide the ApiKey and Password. For Third party apps, use the permanent access token which you have got from the app. |
| 24 | + |
| 25 | +```php |
| 26 | +<?php |
| 27 | +$config = array( |
| 28 | + 'ShopUrl' => 'yourshop.myshopify.com', |
| 29 | + 'ApiKey' => '***YOUR-PRIVATE-API-KEY***', |
| 30 | + 'Password' => '***YOUR-PRIVATE-API-PASSWORD', |
| 31 | +); |
| 32 | +``` |
| 33 | + |
| 34 | +Or |
| 35 | + |
| 36 | +```php |
| 37 | +<?php |
| 38 | +$config = array( |
| 39 | + 'ShopUrl' => 'yourshop.myshopify.com', |
| 40 | + 'AccessToken' => '***ACCESS-TOKEN-FOR-THIRD-PARTY-APPS***', |
| 41 | +); |
| 42 | +``` |
| 43 | + |
| 44 | +#### Get the ShopifyClient SDK Object |
| 45 | + |
| 46 | +```php |
| 47 | +$shopify = new PHPShopify\ShopifyClient($config); |
| 48 | +``` |
| 49 | + |
| 50 | +##### Now just have fun using the SDK using the object oriented way. All objects are named as same as it is named in shopify API reference and you can GET, POST, PUT, DELETE accordingly. |
| 51 | + |
| 52 | +For example getting all product list: |
| 53 | + |
| 54 | +```php |
| 55 | +$products = $shopify->Product->get(); |
| 56 | +``` |
| 57 | + |
| 58 | +GET any specific product with ID |
| 59 | + |
| 60 | +```php |
| 61 | +$productID = 23564666666; |
| 62 | +$product = $shopify->Product($productID)->get(); |
| 63 | +``` |
| 64 | + |
| 65 | +The child resources can be used in a nested way. For example, get the images of a product |
| 66 | + |
| 67 | +```php |
| 68 | +$productID = 23564666666; |
| 69 | +$productImages = $shopify->Product($productID)->Image->get(); |
| 70 | +``` |
| 71 | + |
| 72 | +Or GET any specific article from a specific blog like this |
| 73 | + |
| 74 | +```php |
| 75 | +$blogID = 23564666666; |
| 76 | +$articleID = 125336666; |
| 77 | +$blogArticle = $shopify->Blog($blogID)->Article($articleID)->get(); |
| 78 | +``` |
| 79 | + |
| 80 | +Create a new order (POST Request) |
| 81 | + |
| 82 | +```php |
| 83 | +$order = array ( |
| 84 | + |
| 85 | + "fulfillment_status" => "unfulfilled", |
| 86 | + "line_items" => [ |
| 87 | + [ |
| 88 | + "variant_id" => 27535413959, |
| 89 | + "quantity" => 5 |
| 90 | + ] |
| 91 | + ] |
| 92 | +); |
| 93 | + |
| 94 | +$shopify->Order->post($order); |
| 95 | +``` |
| 96 | + |
| 97 | +Update a customer address (PUT Request) |
| 98 | + |
| 99 | +```php |
| 100 | +$updatedAddress = array( |
| 101 | + "address1" => "129 Oak St", |
| 102 | + "city" => "Ottawa", |
| 103 | + "province" => "ON", |
| 104 | + "phone" => "555-1212", |
| 105 | + "zip" => "123 ABC", |
| 106 | + "last_name" => "Lastnameson", |
| 107 | + "first_name" => "Mother", |
| 108 | + "country" => "CA", |
| 109 | +); |
| 110 | + |
| 111 | +$customerID = 4425749127; |
| 112 | +$addressID = 225663355; |
| 113 | + |
| 114 | +$shopify->Customer($customerID)->Address($addressID)->put($updatedAddress); |
| 115 | +``` |
| 116 | + |
| 117 | +DELETE a WebHook |
| 118 | + |
| 119 | +```php |
| 120 | +$webHookID = 453487303; |
| 121 | + |
| 122 | +$shopify->WebHook($webHookID)->delete()); |
| 123 | +``` |
| 124 | + |
| 125 | +#Reference |
| 126 | +- [Shopify API Reference](https://help.shopify.com/api/reference/) |
0 commit comments