PHP code example of dan / shopify

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

    

dan / shopify example snippets


$api = Dan\Shopify\Shopify::make($shop = 'shop-name.myshopify.com', $token = 'shpua_abc123');

// Shop information
$api->shop(); // array dictionary

// List of products
$api->products->get(); // array of array dictionaries

// Attach query parameters to a get request
$api->products->get(['created_at_min' => '2023-03-25']); // array of array dictionaries

// A specific product
$api->products('123456789')->get(); // array dictionary

// Get all variants for a product
$api->products('123456789')->variants->get(); // array of array dictionaries

// Get a specific variant for a specific product
$s->api2()->products('123456789')->variants('567891234')->get(); // array dictionary

// Append URI string to a get request
$api->orders('123456789')->get([], 'risks'); // array dictionary

// Create a product.
// See https://shopify.dev/docs/api/admin-rest/2023-01/resources/product#post-products
$api->products->post(['title' => 'Simple Test']); // array dictionary

// Update something specific on a product
$api->products('123456789')->put(['title' => 'My title changed.']); // array dictionary

$query = "{
  deliveryProfiles (first: 3) {
    edges {
      node {
        id,
        name,
      }
    }
  }
}"

$api->graphql($query); // hipster

// First call to next can have all the usual query params you might want.
$api->orders->next(['limit' => 100, 'status' => 'closed');

// Further calls will have all query params preset except for limit.
$api->orders->next(['limit' => 100]);

// Get our API
$api = Dan\Shopify\Shopify::make($shop, $token);

// Store metafields
$api->metafields->get();

// Metafields on an Order
$api->orders($order_id)->metafields->get();

// Metafields on a Product
$api->products($product_id)->metafields->get();

// Metafields on a Variant
$api->products($product_id)->variants($variant_id)->metafields->get();

// Metafields on a Customer
$api->customers($customer_id)->metafields->get();

// Metafields can also be updated like all other endpoints
$api->products($product_id)->metafields($metafield_id)->put($data);

Dan\Shopify\Integrations\Laravel\ShopifyServiceProvider::class,

'Shopify' => Dan\Shopify\Integrations\Laravel\ShopifyFacade::class,

// Facade same as $api->shop(), but for just the one store.
Shopify::shop();

// Facade same as $api->products->get(), but for just the one store.
Shopify::products()->get();

// Facade same as $api->products('123456789')->get(), but for just the one store.
Shopify::products('123456789')->get();

Shopify::getAppInstallResponse(
    'your_app_client_id', 
    'your_app_client_secret',
    'shop_from_request',
    'code_from_request'
);

// returns (object) ['access_token' => '...', 'scopes' => '...']

Dan\Shopify\Util::validAppHmac(
    'hmac_from_request', 
    'your_app_client_secret', 
    ['shop' => '...', 'timestamp' => '...', ...]
);

Dan\Shopify\Util::validWebhookHmac(
    'hmac_from_request', 
    'your_app_client_secret', 
    file_get_contents('php://input')
);