Code Monkey home page Code Monkey logo

php-shopify's Introduction

PHP Shopify SDK

Build Status Monthly Downloads Total Downloads Latest Stable Version Latest Unstable Version License Hire

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

Installation

Install with Composer

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.

You can pass additional curl configuration to ShopifySDK

$config = array(
    'ShopUrl' => 'yourshop.myshopify.com',
    'ApiKey' => '***YOUR-PRIVATE-API-KEY***',
    'Password' => '***YOUR-PRIVATE-API-PASSWORD***',   
    'Curl' => array(
        CURLOPT_TIMEOUT => 10,
        CURLOPT_FOLLOWLOCATION => true
    )
);

PHPShopify\ShopifySDK::config($config);

Usage

You can use PHPShopify in a pretty simple object oriented way.

Configure ShopifySDK

If you are using your own private API (except GraphQL), provide the ApiKey and Password.

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

PHPShopify\ShopifySDK::config($config);

For Third party apps, use the permanent access token.

For GraphQL, AccessToken is required. If you are using private API for GraphQL, use your password as AccessToken here.

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

PHPShopify\ShopifySDK::config($config);

You can use specific Shopify API Version by adding in the config array

$config = array(
    'ShopUrl' => 'yourshop.myshopify.com',
    'AccessToken' => '***ACCESS-TOKEN-FOR-THIRD-PARTY-APP***',
    'ApiVersion' => '2022-07',
);

PHPShopify\ShopifySDK::config($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
$config = array(
    'ShopUrl' => 'yourshop.myshopify.com',
    'ApiKey' => '***YOUR-PRIVATE-API-KEY***',
    'SharedSecret' => '***YOUR-SHARED-SECRET***',
);

PHPShopify\ShopifySDK::config($config);
  1. Create the authentication request

The redirect url must be white listed from your app admin as one of Application Redirect URLs.

//your_authorize_url.php
$scopes = 'read_products,write_products,read_script_tags,write_script_tags';
//This is also valid
//$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.

\PHPShopify\AuthHelper::createAuthRequest($scopes, $redirectUrl, null, null, true);
  1. Get the access token when redirected back to the $redirectUrl after app authorization.
//your_redirect_url.php
PHPShopify\ShopifySDK::config($config);
$accessToken = \PHPShopify\AuthHelper::getAccessToken();
//Now store it in database or somewhere else

You can use the same page for creating the request and getting the access token (redirect url). In that case just skip the 2nd parameter $redirectUrl while calling createAuthRequest() method. The AuthHelper class will do the rest for you.

//your_authorize_and_redirect_url.php
PHPShopify\ShopifySDK::config($config);
$accessToken = \PHPShopify\AuthHelper::createAuthRequest($scopes);
//Now store it in database or somewhere else

Get the ShopifySDK Object

$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)

$shopify = new PHPShopify\ShopifySDK($config);
Now you can do get(), post(), put(), delete() calling the resources in the object oriented way. All resources are named as same as it is named in shopify API reference. (See the resource map below.)

All the requests returns an array (which can be a single resource array or an array of multiple resources) if succeeded. When no result is expected (for example a DELETE request), an empty array will be returned.

  • Get all product list (GET request)
$products = $shopify->Product->get();
  • Get any specific product with ID (GET request)
$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) :
$params = array(
    '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)
$order = array (
    "email" => "[email protected]",
    "fulfillment_status" => "unfulfilled",
    "line_items" => [
      [
          "variant_id" => 27535413959,
          "quantity" => 5
      ]
    ]
);

$shopify->Order->post($order);

Note that you don't need to wrap the data array with the resource key (order in this case), which is the expected syntax from Shopify API. This is automatically handled by this SDK.

  • Update an order (PUT Request)
$updateInfo = array (
    "fulfillment_status" => "fulfilled",
);

$shopify->Order($orderID)->put($updateInfo);
  • Remove a Webhook (DELETE request)
$webHookID = 453487303;

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

The child resources can be used in a nested way.

You must provide the ID of the parent resource when trying to get any child resource

  • For example, get the images of a product (GET request)
$productID = 23564666666;
$productImages = $shopify->Product($productID)->Image->get();
  • Add a new address for a customer (POST Request)
$address = array(
    "address1" => "129 Oak St",
    "city" => "Ottawa",
    "province" => "ON",
    "phone" => "555-1212",
    "zip" => "123 ABC",
    "last_name" => "Lastnameson",
    "first_name" => "Mother",
    "country" => "CA",
);

$customerID = 4425749127;

$shopify->Customer($customerID)->Address->post($address);
  • Create a fulfillment event (POST request)
$fulfillmentEvent = array(
    "status" => "in_transit"
);

$shopify->Order($orderID)->Fulfillment($fulfillmentID)->Event->post($fulfillmentEvent);
  • Update a Blog article (PUT request)
$blogID = 23564666666;
$articleID = 125336666;
$updateArtilceInfo = array(
    "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);
  • Delete any specific article from a specific blog (DELETE request)
$blogArticle = $shopify->Blog($blogID)->Article($articleID)->delete();

GraphQL v1.1

The GraphQL Admin API is a GraphQL-based alternative to the REST-based Admin API, and makes the functionality of the Shopify admin available at a single GraphQL endpoint. The full set of supported types can be found in the GraphQL Admin API reference. You can simply call the GraphQL resource and make a post request with a GraphQL string:

The GraphQL Admin API requires an access token for making authenticated requests. You can obtain an access token either by creating a private app and using that app's API password, or by following the OAuth authorization process. See GraphQL Authentication Guide

$graphQL = <<<Query
query {
  shop {
    name
    primaryDomain {
      url
      host
    }
  }
}
Query;

$data = $shopify->GraphQL->post($graphQL);
Variables

If you want to use GraphQL variables, you need to put the variables in an array and give it as the 4th argument of the post() method. The 2nd and 3rd arguments don't have any use in GraphQL, but are there to keep similarity with other requests, you can just keep those as null. Here is an example:

$graphQL = <<<Query
mutation ($input: CustomerInput!) {
  customerCreate(input: $input)
  {
    customer {
      id
      displayName
    }
    userErrors {
      field
      message
    }
  }
}
Query;

$variables = [
  "input" => [
    "firstName" => "Greg",
    "lastName" => "Variables",
    "email" => "[email protected]"
  ]
]
$shopify->GraphQL->post($graphQL, null, null, $variables);
GraphQL Builder

This SDK only accepts a GraphQL string as input. You can build your GraphQL from Shopify GraphQL 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.

Custom Actions

There are several action methods which can be called without calling the get(), post(), put(), delete() methods directly, but eventually results in a custom call to one of those methods.

  • For example, get count of total products
$productCount = $shopify->Product->count();
  • Make an address default for the customer.
$shopify->Customer($customerID)->Address($addressID)->makeDefault();
  • Search for customers with keyword "Bob" living in country "United States".
$shopify->Customer->search("Bob country:United States");

Custom Actions List

The custom methods are specific to some resources which may not be available for other resources. It is recommended that you see the details in the related Shopify API Reference page about each action. We will just list the available actions here with some brief info. each action name is linked to an example in Shopify API Reference which has more details information.

  • (Any resource type except ApplicationCharge, CarrierService, FulfillmentService, Location, Policy, RecurringApplicationCharge, ShippingZone, Shop, Theme) ->

    • count() Get a count of all the resources. Unlike all other actions, this function returns an integer value.
  • Comment ->

  • Customer ->

  • Customer -> Address ->

    • makeDefault() Sets the address as default for the customer
    • set($params) Perform bulk operations against a number of addresses
  • DraftOrder ->

  • Discount ->

  • DiscountCode ->

  • Fulfillment ->

  • GiftCard ->

    • disable() Disable a gift card.
    • search() Search for gift cards matching supplied query
  • InventoryLevel ->

  • Order ->

  • Order -> Refund ->

  • ProductListing ->

    • productIds() Retrieve product_ids that are published to your app.
  • RecurringApplicationCharge ->

  • SmartCollection ->

    • sortOrder($params) Set the ordering type and/or the manual order of products in a smart collection
  • User ->

FulfillmentRequest Resource - including actions

  • Mapped FulfillmentOrder->FulfillmentRequest
  • Mapped Order(id)->FulfillmentOrder
// Requesting the FulfilmentOrder for a given order
$fo = $client->Order("1234567890")->FulfillmentOrder()->get();

// Requesting assigned fulfillment orders (with status fulfillment_requested)
$shopify->AssignedFulfillmentOrder()->get(["assignment_status" => "fulfillment_requested"]);

// Creating a FulfilmentRequest
// Follow instructions to get partial fulfilments
$fr = $client->FulfillmentOrder('0987654321')->FulfillmentRequest->post([]);

// Accepting \ Rejecting a FulfilmentRequest
$fr = $client->FulfillmentOrder('0987654321')->FulfillmentRequest->accept();
$fr = $client->FulfillmentOrder('0987654321')->FulfillmentRequest->reject();

// Communicating fulfillment
$client->Fulfillment->post($body)

Shopify API features headers

To send X-Shopify-Api-Features headers while using the SDK, you can use the following:

$config['ShopifyApiFeatures'] = ['include-presentment-prices'];
$shopify = new PHPShopify\ShopifySDK($config);

Reference

Paid Support

You can hire the author of this SDK for setting up your project with PHPShopify SDK.

Hire at Upwork

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]

php-shopify's People

Contributors

andyexeter avatar anikghosh256 avatar baldrs avatar db306 avatar derak-kilgo avatar dinofratelli avatar do-samantha avatar fabio-sassi-spotview avatar felixlehmann avatar jeroendelau avatar liamjcooper avatar marxolly avatar mcriggerxroadz avatar n3o77 avatar npabisz avatar rjacobso avatar roemerb avatar salman0802 avatar saumil122 avatar seka19 avatar spotnyk avatar stevenbrookes avatar tareqtms avatar thomas-multisafepay avatar tompec avatar tonydestefano avatar victorlap avatar vkislichenko avatar whobutsb avatar zealnagar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-shopify's Issues

Class 'PHPShopify\ShopifySDK' not found error

I am new to php api, the below code i used under vendor folder

$config = array(
'ShopUrl' => '.myshopify.com',
'ApiKey' => '
***************',
'Password' => '*******************'
);

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

$productID = ######;
$product = $shopify->Product($productID)->get();
//$products = $shopify->Product->get();

var_dump($product);

where i need to place this file under which folder and how to fix this error, can you help to fix it.

Not getting any access tooken

Hi,

We trying use this to interact with shopify and get access token

listing the step we followed,

  1. ran this 'composer require phpclassic/php-shopify' in cmd(my app)
  2. put the code snippet
    $config = array(
    'ShopUrl' => 'yourshop.myshopify.com',
    'ApiKey' => 'YOUR-PRIVATE-API-KEY',
    'SharedSecret' => 'YOUR-SHARED-SECRET',
    );

PHPShopify\ShopifySDK::config($config);
$scopes = 'read_products,write_products,read_script_tags,write_script_tags';

$redirectUrl = 'https://yourappurl.com/your_redirect_url.php';

\PHPShopify\AuthHelper::createAuthRequest($scopes, $redirectUrl);
$accessToken = \PHPShopify\AuthHelper::getAccessToken();


We are not getting any response .

Is any step we missed??
Please help

PHPShopify\ShopifySDK not found

I know this is very basic, I am newbie in app development. I already Install the package using composer

I use this command ---> composer require phpclassic/php-shopify

It was successfully installed, but when I codes, like below, I got an error that says (Fatal error: Uncaught Error: Class 'PHPShopify\ShopifySDK' not found in C:\xampp\htdocs\shopify\Redirect.php:12 Stack trace: #0 {main} thrown in C:\xampp\htdocs\shopify\Redirect.php on line 12)

Below is my code: I tried to manually include files and it works, so code is correct I think.
`<?php

$config = array(
	'ShopUrl' => '*****.myshopify.com',
	'ApiKey' => '********************',
	'Password' => '*******************'
);

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


$productID = ######;
$product = $shopify->Product($productID)->get();
//$products = $shopify->Product->get();

var_dump($product);

?>`

verifyShopRequest is incorrectly implemented

http_build_query in the method does URL-encoding to its components. While it may seem a logical thing to do, technically the string to be constructed is not a URL. Shopify doesn't do such encoding and as a result, the generated hash value does not match.

For example in the case when Shopify supplies protocol=http:// query parameter and current implementation with http_build_query encodes it to protocol=https%3A%2F%2F resulting in false negative result.

How to get a products metafield data?

Shopify's documentation lists it as such:

Retrieve a list of metafields that belong to a Product resource
GET /admin/products/#{product_id}/metafields.json

I've tried like this, but I'm not sure on the correct way:

$metafields = $this->shopify->Product("628755693631")->Metafield->get($params)

Thanks.

Posting to Metafield of Product

I get an exception when trying to post to the metafield of a product.

The request I'm doing looks like this:
$client->Product($this->id)->Metafield->post($payload);

ID is the ID of the product, payload is an array containing metafield data, the payload was valid when I tested this when posting to the Shop metafield rather than a product one.

Am I doing something wrong or is this a bug?

The exception I get is below:
PHPShopify\Exception\SdkException thrown with message "Invalid resource name get. Pls check the API Reference to get the appropriate resource name."

FulfillmentService post goes in Fatal error!!! D:

Hi guys,

i'm having problem with this code

$data	=	array (
	"fulfillment" => array("name" => "Fulfillment Service",
					  "callback_url" => "test.com/tracking",
					  "inventory_management" => false,
					  "tracking_support" => true,
					  "requires_shipping_method" => true,
					 ),
	);
$shopify->FulfillmentService->post($data);

The class return me Fatal Error with this message

Fatal error: Class 'PHPShopify\FulfillmentService' not found in /(path censured)/(path censured)/phpclassic/php-shopify/lib/ShopifySDK.php on line 202

Thanks for your help.

Can i create a new Fulfillment Services

Hi guys,

it is possible create a Fulfillment Services with this SDK?
Or I must create/use a personalized code to create Fulfillment Services when i connect new store to my app?

Thanks in advance.

SmartCollection Metafields

With the SDK it's currently not possible to add metafields to SmartCollections (from what I can see).

According to this doc page:
https://help.shopify.com/en/api/reference/metafield

It should be possible to add metafields to SmartCollections using the /collections/{id}/metafields.json endpoint. I've tested using postman and it is indeed possible to add metafields to those objects using the collections resource but I couldn't figure out how to do this with the SDK. I'm currently using a manual HTTP request to do this call instead.

Required class not found

Im getting the following error during instantiation:

A PHP Error was encountered

Severity: Error

Message: Class 'ShopifyResource' not found

Filename: lib/Product.php

Line Number: 28

Backtrace:

Getting this error

Fatal error: Uncaught Error: Class 'Php_Shopify_Apps\lib\Product' not found in C:\xampp\htdocs\Php_Shopify_Apps\lib\ShopifySDK.php:206 Stack trace: #0 C:\xampp\htdocs\Php_Shopify_Apps\lib\ShopifySDK.php(174): Php_Shopify_Apps\lib\ShopifySDK->__call('Product', Array) #1 C:\xampp\htdocs\Php_Shopify_Apps\lib\ShopifySDK.php(43): Php_Shopify_Apps\lib\ShopifySDK->__get('Product') #2 {main} thrown in C:\xampp\htdocs\Php_Shopify_Apps\lib\ShopifySDK.php on line 206

Retry loop in curl request logic

The SDK includes a while loop that keeps retrying until a 429 is no longer received. In my case this behaviour is unexpected and undesirable. My app has many background jobs running for stores and has logic to queue jobs to retry later. I do not want the processes to sleep for a potentially infinite amount of time.

I've forked the repo to remove this logic for myself. I think at the very least this option should be made as a config which can be toggled on or off. If a config option is desired for this, I'll submit a pull request with that change.

Connection Timed Out

Getting this error in my logs today:

ERROR - 2018-11-14 20:43:27 --> Severity: error --> Exception: 7 : Failed to connect to store_name-test.myshopify.com port 443: Connection timed out /home/store_name/public_html/vendor/phpclassic/php-shopify/lib/CurlRequest.php 147

Not sure if its a library issue or if shopify is having issues on their end.

Any insight would be greatly appreciated.

Automatic throttling of API calls

Is it possible to build in an automatic throttling of API calls to avoid the too many requests error? There are many other implementations of the leaky bucket algorithm.

Basically, if the API response is the too many requests error, wait X seconds and retry the request.

HMAC value not found in url parameters

capture

please help, i'm getting this error.
these are my codes.

function index()
{
if ($this->isPost()){
$config = array(
'ShopUrl' => preg_replace("(^https?://)", "", $this->input->post('shopify')),
'ApiKey' => 'key',
'SharedSecret' => 'key',
);
// $this->addChannel();
PHPShopify\ShopifySDK::config($config);
$scopes = 'read_products,write_products,read_orders,write_orders';
$redirectUrl = 'http://localhost:8080/settings/channels/';
\PHPShopify\AuthHelper::createAuthRequest($scopes, $redirectUrl);
}
PHPShopify\ShopifySDK::config($config);
$accessToken = \PHPShopify\AuthHelper::getAccessToken();
print_r($accessToken);
}
function addShopify(){
$this->load->view('settings/shopify');
}

How to create multiple shopify objects to access multiple stores

Hi everybody,
I want to update data to my two Shopify stores. But if I changed a config of Shopify SDK, it's not working. Object 1 of store 1 is same to Object 2 of store 2.

Here 's my code:

PHPShopify\ShopifySDK::config($config_store_1);
$shopify_1 = new PHPShopify\ShopifySDK;

PHPShopify\ShopifySDK::config($config_store_2);
$shopify_2 = new PHPShopify\ShopifySDK;
    
$locations_1 = $shopify_1->Location->get();
echo json_encode($locations_1)."<br/><br/><br/>==========================<br/><br/><br/>";

$locations_2 = $shopify_2->Location->get();
echo json_encode($locations_2);

===> $locations_1 is same to $locations_2

Please help me. Thanks!

Discrepancy in POST request payload format

Shopify API docs specify that JSON payload should be in this form:
{ "recurring_application_charge": { "name": "Super Duper Plan", "price": 10.0, "return_url": "http://super-duper.shopifyapps.com" } }

This library however, expects this form:
{ "name": "Super Duper Plan", "price": 10.0, "return_url": "http://super-duper.shopifyapps.com" }

Basically the library expects you to leave out the outer array/JSON element. I think it would be better to accept it either way and just check if the outer object is there or to indicate more clearly in the documentation not to include the outer object.

Subresource requests whose URLs contain embedded credentials

Hi,

We have developed a Shopify App with your library.
At the beginning we have created two pages: a landing page where the user grants his/her rights to the shop and a redirect page which displays the information after the app is installed.
So far so good, we got these parts working.
However after installing our App, we browse to our shop and click on the App in particular Chrome.
The page is trying to load our landing page which has the following content:

$config = array(
'ShopUrl' => $shop,
'ApiKey' => $settings->apikey,
'Password' => $settings->apisecret,
);

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

In our Chrome browser network tab it displays the following message: Subresource requests whose URLs contain embedded credentials.

The question is, how can we bypass this behaviour? Firefox ignores it and just redirects us to our redirect page, which works fine. Please advice.

Thanks,

Greetings,

Remie

How to use Transactions?

Hi, I wanted to know how I can use Transactions, specifically the capture

POST /admin/orders/#{id}/transactions.json
{
  "transaction": {
    "kind": "capture"
  }
}

also, i am trying your example post

$updateInfo = array (
    "fulfillment_status" => "fulfilled",
);

$shopify->Order($orderID)->put($order);

but it doesn't work, not sure what I am doing wrong, i can change the email information on the order

Cannot create new variant

Shopify Api reference

Create a new product variant

POST /admin/products/#{product_id}/variants.json
{
"variant": {
"option1": "Yellow",
"price": "1.00"
}
}

With this PHP Code:

$newVariant = array(
        "option1" => "black",
         "price" => "20.00"
         );
	  
$shopify->Product($product_id)->Variant->post($newVariant);

I recive this error:

Fatal error: Uncaught PHPShopify\Exception\CurlException: Request failed with HTTP Code 406.

Multiple Fulfillment Issue

Hi guys,

I'm having some issue for fulfill an order that have 1 product with app fulfillment service and another one that have a fulfillment service to manual.

When i Post the json that who create a fulfillment for the order wih property line_items with the id that have app fulfillment service.

There is a json that i post to endpoint

`
print_r $our_product:
Array
(
[0] => Array
(
[id] => 1922576121914
[quantity] => 1
)

)

$updateInfo = array ("fulfillment" => array(
"location_id" => $location_id,
"id" => $OrderId,
"notify_customer" => "true",
"line_items" => $our_product,
));
There is a post with SDK
$fulfill_post = $shopify->Order($OrderId)->Fulfillment->post($updateInfo);`

API call return me a error: All line items of a fulfillment must use the same fulfillment service.

The id set in in line items property is associated with app fulfillment service.

Thanks in advace for help.
Please replay fast I'm STUCK. :(

Discount

When using $connection->Discount()->get()the following error
Fatal error: Uncaught PHPShopify\Exception\ApiException: Scope undefined for API access: discounts_next. Valid scopes: admin_notifications, analytics, apps, capital, channel_app, channels, checkout_settings, checkouts, collection_listings, collection_publications, content, customers, disputes, draft_orders, fulfillments, gift_card_adjustments, gift_cards, home, images, inventory, locations, marketing_events, meta_tags, mobile_payments, mobile_platform_applications, notifications, online_store, online_store_preferences, orders, payment_gateways, price_rules, product_engagements, product_listings, product_publications, products, reports, resource_feedbacks, script_tags, scripts, shipping, shopify_payments, social_network_accounts, taxes, themes, tracking_pixels, and users in /home/cognizancerpm/public_html/vendor/php-shopify-master/lib/ShopifyResource.php:432 Stack trace: #0 /home/cognizancerpm/public_html/vendor/php-shopify-master/lib/ShopifyResource.php(274): PHPShopify\ShopifyResource->processResponse(Array, 'discounts') in

Is there a specific call that needs to be made in order to access the discount codes list?

Can't set fulfillment(main status) to open

Hi guys,

every time i try to set fulfillment main status to open
SDK return this fatal error:

Fatal error: Uncaught exception 'PHPShopify\Exception\ApiException' with message 'status - can't be blank, "" is not a valid status' in /phpclassic/php-shopify/lib/ShopifyResource.php:492 Stack trace: #0 /phpclassic/php-shopify/lib/ShopifyResource.php(373): PHPShopify\ShopifyResource->processResponse(Array, 'fulfillment_eve...') #1 test/test-fulfillment.php(138): PHPShopify\ShopifyResource->post(Array) #2 {main} thrown in /phpclassic/php-shopify/lib/ShopifyResource.php on line 492

But the status is set in the array. Another Exception comes out from testing is status can't be open.
But in shopify documentation the status can be: pending, open, success, cancelled, error, faliure.
See here shopify documentation(https://help.shopify.com/en/api/reference/shipping_and_fulfillment/fulfillment#properties)

I have tried so many times with
$updateInfo = array ("fulfillment" => array("location_id" => $location_id, "id" => $orderID, "status" => "open", "notify_customer" => "true")); $fulfill_put = $shopify->Order($orderID)->Fulfillment($fulfillmentID)->put($updateInfo);

Another try with events:
$updateStatus = array ("fulfillment_event" => array("status" => "open")); $fulfill_status = $shopify->Order( $orderID,)->Fulfillment($fulfillmentID)->Event->post($updateStatus);

Another try with normal order put
$updateInfo = array ( "fulfillment_status" => "fulfilled", ); $shopify->Order($orderID)->put($updateInfo);

Pls some one can help me?

Thanks in advance

Unable to Use

Hello,
Greetings!

Getting issue in using this library, getting error "Fatal error: Class 'PHPShopify\TestSimpleResource' not found", please guide what I am missing.

Looking forward for your help.

Thanks & Regards
Milan G.

Is it possible to get all products within a given collection?

I have a use case where I need to pull a list of products which are in a given collection. It would be useful to be able to query for this in a similar way to: $client->Collection($id)->Product->get();

Is anything like this currently possible? I'm thinking I may have to just do this with http requests from what I'm seeing.

Or alternatively in a way that closer matches the API it could be done like this $client->Product($collection_id)->get(); in order to filter for products that are in that collection. This is how you do it with their API directly, you pass URL argument for the collection as a filter.

Example on the ReadMe to update order status is incorrect

The example is:

$updateInfo = array (
    "fulfillment_status" => "fulfilled",
);

$shopify->Order($orderID)->put($order);

I'd assume it should be:

$updateInfo = array (
    "fulfillment_status" => "fulfilled",
);

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

However Shopify still just returns order information as if it is a GET request.

Get value of single asset

Does this framework supports to get the value of a single asset? The thing is, for assets it different to most of the other calls because Shopify excepts the key for the template as request parameter. Also an Asset do not have an id like an articel in blogs for example.

To retrieve a single asset, include asset[key]=#{asset_key} as a request parameter. For example, to retrieve the asset with a key of templates/index.liquid, the request might be /admin/themes/828155753/assets.json?asset[key]=templates/index.liquid.

Could find any example in the readme nor in the tests to get the value.

What I already tried:

  $template1 = $shopify->Theme($themes[0]['id'])->Asset->get(array('key'=>'sections/page.liquid'));
  $template2 = $shopify->Theme($themes[0]['id'])->Asset('sections/page.liquid')->get();

Orders are not creating after a limit

I need to add 5000 orders to shopify site.But after a particular no of order creation, it is not working.Is there any way to find the error? or any solution for this issue.I think it is related to API Rate Limit.

hmacs do not match.

Fatal error: Uncaught PHPShopify\Exception\SdkException: This request is not initiated from a valid shopify shop!

Theme or Theme->Asset calls are not working.

Hey, so when I try to call Theme like this:
$shopify = new PHPShopify\ShopifySDK($config); $themes = $shopify->Asset->get(); var_dump($themes);
It returns HTTP ERROR 500, any idea what I am missing?

[Other actions are working well though]

Product->put() issue - HTTP Code 406

Hi @tareqtms,
I'm trying to update an existing product with the API:

Here's the code I'm using:
$putArray = array("id" => "100000000", "title" => "titleTest", "body_html" => "description");
// Update existing product
$shopify->Product->put($putArray);

However, when I process this, I get the following error:

Fatal error: Uncaught PHPShopify\Exception\CurlException: Request failed with HTTP Code 406. in E:\xampp\htdocs\libraries\php-shopify\lib\ShopifyResource.php:485 Stack trace: #0 E:\xampp\htdocs\libraries\php-shopify\lib\ShopifyResource.php(395): PHPShopify\ShopifyResource->processResponse(NULL, 'product') #1 E:\xampp\htdocs\shopifyInventory.php(146): PHPShopify\ShopifyResource->put(Array) #2 {main} thrown in E:\xampp\htdocs\libraries\php-shopify\lib\ShopifyResource.php on line 485

I can't figure out why it is responding with 'product' being null, as the array elements seem OK and the product does exist. Any advice here?

composer require phpclassic/php-shopify

when i excute composer require phpclassic/php-shopify, report below exception:

[ReflectionException]
Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist

[ErrorException]
Declaration of Fxp\Composer\AssetPlugin\Repository\AbstractAssetsRepository::whatProvides(Composer\DependencyResolver\Pool $pool, $name) should b
e compatible with Composer\Repository\ComposerRepository::whatProvides(Composer\DependencyResolver\Pool $pool, $name, $bypassFilters = false)

sorting issue with created_at

Hi,

i tried to sort(order) products while fetching the data. but it showed an error.

Attempt to order records by unknown orders created_at+ASC, expected [:total, :title, :created_at, :updated_at] - Required parameter missing or invalid

this is what i did using SDK

$params = [
	'limit'		=> $limit,
	'order'		=> 'created_at+ASC'
];

$data = $this->shopify->Product->get($params);

but it showed above error. but i tried directly using api as following. it worked!

`admin/products.json?limit=4&order=created_at+ASC

help me on this issue.

Thank You

PriceRule

Hey guys.

PriceRule API is missing from your sdk. Maybe others too, but I needed this one, so here it goes:

namespace PHPShopify;

class PriceRule extends ShopifyResource {

protected $resourceKey = 'price_rule';

}

PHPShopify\Exception\ApiException : Not Found

PHPShopify\Exception\ApiException : Not Found

at /home/vagrant/code/local/vendor/phpclassic/php-shopify/lib/ShopifyResource.php:496
492|
493| if (isset($responseArray['errors'])) {
494| $message = $this->castString($responseArray['errors']);
495|

496| throw new ApiException($message);
497| }
498|
499| if ($dataKey && isset($responseArray[$dataKey])) {
500| return $responseArray[$dataKey];

Exception trace:

1 PHPShopify\ShopifyResource::processResponse(["Not Found"], "product")
/home/vagrant/code/local/vendor/phpclassic/php-shopify/lib/ShopifyResource.php:315

Can't get article metafields

Would love to be able to use this call to grab article metafields.

$shopify->Blog($blogID)->Article($articleID)->Metafield()->get();

Is it possible to get Variants of a product(using GET request)

The child resources can be used in a nested way.
For example, get the images of a product (GET request)
$productID = 23564666666;
$productImages = $shopify->Product($productID)->Image->get();

Is it possible to get Variants of a product(using GET request) like above????

Required class not found

I have the same issue: #4

Message: Class 'ShopifyResource' not found in lib/Product.php Line Number: 28

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.