Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 joeyhub #148

Draft
wants to merge 31 commits into
base: v2.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7cdcb01
Move shopify resource classes into own folder.
joeyhub Mar 6, 2020
4710133
Update namespace / use for new location and clean up some excessive w…
joeyhub Mar 6, 2020
818ad92
Remove whitespace from other classes.
joeyhub Mar 6, 2020
943951e
Switch shopify resource to use new namespace (bit ugly, this should b…
joeyhub Mar 6, 2020
f4bf844
Pre beer.
joeyhub Mar 6, 2020
a0f0cf9
Clean up shop resources.
joeyhub Mar 6, 2020
2840dc7
Move http libraries into own folder. Simplify shopify SDK lib.
joeyhub Mar 6, 2020
0493d99
Update namespace.
joeyhub Mar 6, 2020
8f707a1
Less excessive static.
joeyhub Mar 6, 2020
10e2d11
Stop auth helper from embedding globals.
joeyhub Mar 6, 2020
a9f11cc
Update syntax, strip noisy comments, refactor.
joeyhub Mar 9, 2020
b64b177
LOL: return md5() === md5();
joeyhub Mar 9, 2020
46c4a9f
Pruine and clean up test formatting.
joeyhub Mar 9, 2020
81bd170
Move tests to ShopifyResource folder.
joeyhub Mar 9, 2020
561c0c4
Update test resources namespaces.
joeyhub Mar 9, 2020
f0dd889
Several partial small cleanups and fixes, switches to a variants of P…
joeyhub Mar 9, 2020
8666567
Add consistent formatting to tests.
joeyhub Mar 9, 2020
10df66f
Apply consistent style to shopify resources.
joeyhub Mar 9, 2020
5cf062c
Small fixes. Update composer packages.
joeyhub Mar 9, 2020
aa4d5c9
Fix most broken tests.
joeyhub Mar 9, 2020
c7962b7
Apply PR 145 and remove comment noise.
joeyhub Mar 9, 2020
ed9e56f
Update auth helper and pull in pull request for params.
joeyhub Mar 9, 2020
aa14651
Remove test that won't work (limited set of operations available for …
joeyhub Mar 9, 2020
23af264
Some poorly implemented but minimal improvements around error handling.
joeyhub Mar 9, 2020
ae1dba5
Small fixes and improvements.
joeyhub Mar 9, 2020
a7a06c6
Merge pull request #1 from phpclassic/master
joeyhub Mar 9, 2020
60cf10e
Merge remote-tracking branch 'origin/master' into dev-v2-joeyhub
joeyhub Mar 9, 2020
7d8c238
Change imaginary brand from Coconut to Pineapple.
joeyhub Mar 9, 2020
7485bfc
Use this for config.
joeyhub Mar 9, 2020
f76ff7c
Fix grant options.
joeyhub Mar 10, 2020
d320c8a
Delete has a null response.
joeyhub Mar 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
vendor
/vendor/
/nbproject/private/
.idea/
.idea/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: php

php:
- 7.1
- 7.3

before_script: composer install
6 changes: 6 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* This license applies to all files within this code base.
* This license must be attached if files are moved out of this codebase.
* @copyright Tareq Mahmood <tareqtms@yahoo.com>
*/

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down
103 changes: 45 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://travis-ci.org/phpclassic/php-shopify.svg?branch=master)](https://travis-ci.org/phpclassic/php-shopify) [![Monthly Downloads](https://poser.pugx.org/phpclassic/php-shopify/d/monthly)](https://packagist.org/packages/phpclassic/php-shopify) [![Total Downloads](https://poser.pugx.org/phpclassic/php-shopify/downloads)](https://packagist.org/packages/phpclassic/php-shopify) [![Latest Stable Version](https://poser.pugx.org/phpclassic/php-shopify/v/stable)](https://packagist.org/packages/phpclassic/php-shopify) [![Latest Unstable Version](https://poser.pugx.org/phpclassic/php-shopify/v/unstable)](https://packagist.org/packages/phpclassic/php-shopify) [![License](https://poser.pugx.org/phpclassic/php-shopify/license)](https://packagist.org/packages/phpclassic/php-shopify) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=ME9N6M2B87XT4&currency_code=USD&source=url)

PHPShopify is a simple SDK implementation of Shopify API. It helps accessing the API in an object oriented way.
PHPShopify is a minimal SDK for using the Shopify API.

## Installation
Install with Composer
Expand All @@ -11,8 +11,8 @@ composer require phpclassic/php-shopify
```

### Requirements
PHPShopify uses curl extension for handling http calls. So you need to have the curl extension installed and enabled with PHP.
>However if you prefer to use any other available package library for handling HTTP calls, you can easily do so by modifying 1 line in each of the `get()`, `post()`, `put()`, `delete()` methods in `PHPShopify\HttpRequestJson` class.

PHPShopify uses curl extension for handling http calls. So you need to have the PHP curl extension installed and enabled.

## Usage

Expand All @@ -22,38 +22,38 @@ You can use PHPShopify in a pretty simple object oriented way.
If you are using your own private API, provide the ApiKey and Password.

```php
$config = array(
$config = [
'ShopUrl' => 'yourshop.myshopify.com',
'ApiKey' => '***YOUR-PRIVATE-API-KEY***',
'Password' => '***YOUR-PRIVATE-API-PASSWORD***',
);
'Password' => '***YOUR-PRIVATE-API-PASSWORD***'
];

PHPShopify\ShopifySDK::config($config);
$shopify = new PHPShopify\ShopifySDK($config);
```

For Third party apps, use the permanent access token.

```php
$config = array(
$config = [
'ShopUrl' => 'yourshop.myshopify.com',
'AccessToken' => '***ACCESS-TOKEN-FOR-THIRD-PARTY-APP***',
);
'AccessToken' => '***ACCESS-TOKEN-FOR-THIRD-PARTY-APP***'
];

PHPShopify\ShopifySDK::config($config);
$shopify = new PHPShopify\ShopifySDK($config);
```
##### How to get the permanent access token for a shop?
There is a AuthHelper class to help you getting the permanent access token from the shop using oAuth.

1) First, you need to configure the SDK with additional parameter SharedSecret

```php
$config = array(
$config = [
'ShopUrl' => 'yourshop.myshopify.com',
'ApiKey' => '***YOUR-PRIVATE-API-KEY***',
'SharedSecret' => '***YOUR-SHARED-SECRET***',
);
'SharedSecret' => '***YOUR-SHARED-SECRET***'
];

PHPShopify\ShopifySDK::config($config);
$shopify = new PHPShopify\ShopifySDK($config);
```

2) Create the authentication request
Expand All @@ -67,21 +67,15 @@ $scopes = 'read_products,write_products,read_script_tags,write_script_tags';
//$scopes = array('read_products','write_products','read_script_tags', 'write_script_tags');
$redirectUrl = 'https://yourappurl.com/your_redirect_url.php';

\PHPShopify\AuthHelper::createAuthRequest($scopes, $redirectUrl);
```

> If you want the function to return the authentication url instead of auto-redirecting, you can set the argument `$return` (5th argument) to `true`.

```php
\PHPShopify\AuthHelper::createAuthRequest($scopes, $redirectUrl, null, null, true);
$url = $shopify->createAuthHelper()->createAuthRequest($scopes, $redirectUrl);
```

3) Get the access token when redirected back to the `$redirectUrl` after app authorization.

```php
//your_redirect_url.php
PHPShopify\ShopifySDK::config($config);
$accessToken = \PHPShopify\AuthHelper::getAccessToken();
$shopify = new PHPShopify\ShopifySDK($config);
$accessToken = $shopifyClient->createAuthHelper()->getAccessToken($_GET);
//Now store it in database or somewhere else
```

Expand All @@ -96,12 +90,6 @@ $accessToken = \PHPShopify\AuthHelper::createAuthRequest($scopes);

#### Get the ShopifySDK Object

```php
$shopify = new PHPShopify\ShopifySDK;
```

You can provide the configuration as a parameter while instantiating the object (if you didn't configure already by calling `config()` method)

```php
$shopify = new PHPShopify\ShopifySDK($config);
```
Expand All @@ -118,28 +106,28 @@ $products = $shopify->Product->get();
- Get any specific product with ID (GET request)

```php
$productID = 23564666666;
$product = $shopify->Product($productID)->get();
$productId = 23564666666;
$product = $shopify->Product($productId)->get();
```

You can also filter the results by using the url parameters (as specified by Shopify API Reference for each specific resource).

- For example get the list of cancelled orders after a specified date and time (and `fields` specifies the data columns for each row to be rendered) :

```php
$params = array(
$params = [
'status' => 'cancelled',
'created_at_min' => '2016-06-25T16:15:47-04:00',
'fields' => 'id,line_items,name,total_price'
);
];

$orders = $shopify->Order->get($params);
```

- Create a new order (POST Request)

```php
$order = array (
$order = [
"email" => "foo@example.com",
"fulfillment_status" => "unfulfilled",
"line_items" => [
Expand All @@ -148,7 +136,7 @@ $order = array (
"quantity" => 5
]
]
);
];

$shopify->Order->post($order);
```
Expand All @@ -159,19 +147,19 @@ $shopify->Order->post($order);
- Update an order (PUT Request)

```php
$updateInfo = array (
$updateInfo = [
"fulfillment_status" => "fulfilled",
);
];

$shopify->Order($orderID)->put($updateInfo);
$shopify->Order($orderId)->put($updateInfo);
```

- Remove a Webhook (DELETE request)

```php
$webHookID = 453487303;
$webHookId = 453487303;

$shopify->Webhook($webHookID)->delete());
$shopify->Webhook($webHookId)->delete());
```


Expand All @@ -181,14 +169,14 @@ $shopify->Webhook($webHookID)->delete());
- For example, get the images of a product (GET request)

```php
$productID = 23564666666;
$productImages = $shopify->Product($productID)->Image->get();
$productId = 23564666666;
$productImages = $shopify->Product($productId)->Image->get();
```

- Add a new address for a customer (POST Request)

```php
$address = array(
$address = [
"address1" => "129 Oak St",
"city" => "Ottawa",
"province" => "ON",
Expand All @@ -197,41 +185,41 @@ $address = array(
"last_name" => "Lastnameson",
"first_name" => "Mother",
"country" => "CA",
);
];

$customerID = 4425749127;
$customerId = 4425749127;

$shopify->Customer($customerID)->Address->post($address);
$shopify->Customer($customerId)->Address->post($address);
```

- Create a fulfillment event (POST request)

```php
$fulfillmentEvent = array(
$fulfillmentEvent = [
"status" => "in_transit"
);
];

$shopify->Order($orderID)->Fulfillment($fulfillmentID)->Event->post($fulfillmentEvent);
$shopify->Order($orderId)->Fulfillment($fulfillmentId)->Event->post($fulfillmentEvent);
```

- Update a Blog article (PUT request)

```php
$blogID = 23564666666;
$articleID = 125336666;
$updateArtilceInfo = array(
$blogId = 23564666666;
$articleId = 125336666;
$updateArticleInfo = [
"title" => "My new Title",
"author" => "Your name",
"tags" => "Tags, Will Be, Updated",
"body_html" => "<p>Look, I can even update through a web service.<\/p>",
);
$shopify->Blog($blogID)->Article($articleID)->put($updateArtilceInfo);
];
$shopify->Blog($blogId)->Article($articleId)->put($updateArticleInfo);
```

- Delete any specific article from a specific blog (DELETE request)

```php
$blogArticle = $shopify->Blog($blogID)->Article($articleID)->delete();
$blogArticle = $shopify->Blog($blogId)->Article($articleId)->delete();
```

### GraphQL <sup>*v1.1*</sup>
Expand Down Expand Up @@ -259,7 +247,6 @@ $data = $shopify->GraphQL->post($graphQL);
##### GraphQL Builder
This SDK only accepts a GraphQL string as input. You can build your GraphQL from [Shopify GraphQL Builder](https://help.shopify.com/en/api/graphql-admin-api/graphiql-builder)


### Resource Mapping
Some resources are available directly, some resources are only available through parent resources and a few resources can be accessed both ways. It is recommended that you see the details in the related Shopify API Reference page about each resource. Each resource name here is linked to related Shopify API Reference page.
> Use the resources only by listed resource map. Trying to get a resource directly which is only available through parent resource may end up with errors.
Expand Down Expand Up @@ -345,7 +332,7 @@ $productCount = $shopify->Product->count();

- Make an address default for the customer.
```php
$shopify->Customer($customerID)->Address($addressID)->makeDefault();
$shopify->Customer($customerId)->Address($addressId)->makeDefault();
```

- Search for customers with keyword "Bob" living in country "United States".
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"homepage": "https://github.com/phpclassic/php-shopify",
"type": "library",
"require": {
"php": ">=5.6",
"php": ">=7.3",
"ext-curl": "*",
"ext-json": "*"
},
Expand Down
Loading