PHP code example of sonu179208 / shopify-sdk

1. Go to this page and download the library: Download sonu179208/shopify-sdk 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/ */

    

sonu179208 / shopify-sdk example snippets




use ShopifySDK\Shopify;

$shopify = new Shopify("yourstore.myshopify.com", "your-access-token");

// Get all products
$response = $shopify->get("products.json");

print_r($response);

$newProduct = [
    "product" => [
        "title" => "New Product",
        "body_html" => "<strong>Awesome product</strong>",
        "vendor" => "Sonu Inc.",
        "product_type" => "Custom"
    ]
];

$response = $shopify->post("products.json", $newProduct);

$response = $shopify->get("products.json");

$productId = 1234567890;

$update = [
    "product" => [
        "id" => $productId,
        "title" => "Updated Product Title"
    ]
];

$response = $shopify->put("products/{$productId}.json", $update);

$productId = 1234567890;
$response = $shopify->delete("products/{$productId}.json");

$query = <<<GQL
{
  shop {
    name
    myshopifyDomain
  }
}
GQL;

$response = $shopify->graphql($query);

$mutation = <<<GQL
mutation {
  productCreate(input: {
    title: "GraphQL Product",
    bodyHtml: "Product via GraphQL"
  }) {
    product {
      id
      title
    }
    userErrors {
      field
      message
    }
  }
}
GQL;

$response = $shopify->graphql($mutation);

$response = $shopify->registerWebhook("orders/create", "[https://yourdomain.com/webhooks/order-created](https://yourdomain.com/webhooks/order-created)");

$response = $shopify->listWebhooks();

$webhookId = 123456789;
$response = $shopify->deleteWebhook($webhookId);