PHP code example of phpclassic / php-shopify

1. Go to this page and download the library: Download phpclassic/php-shopify library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phpclassic / php-shopify example snippets


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

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

PHPShopify\ShopifySDK::config($config);

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

PHPShopify\ShopifySDK::config($config);

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

PHPShopify\ShopifySDK::config($config);

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

PHPShopify\ShopifySDK::config($config);

//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);

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

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

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

$shopify = new PHPShopify\ShopifySDK;

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

$products = $shopify->Product->get();

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

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

$order = array (
    "email" => "[email protected]",
    "fulfillment_status" => "unfulfilled",
    "line_items" => [
      [
          "variant_id" => 27535413959,
          "quantity" => 5
      ]
    ]
);

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

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

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

$webHookID = 453487303;

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

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

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

$fulfillmentEvent = array(
    "status" => "in_transit"
);

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

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

$blogArticle = $shopify->Blog($blogID)->Article($articleID)->delete();

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

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

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

$productCount = $shopify->Product->count();

$shopify->Customer($customerID)->Address($addressID)->makeDefault();

$shopify->Customer->search("Bob country:United States");

// 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)
shell
composer