PHP code example of gztango / php-shoplazza

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

    

gztango / php-shoplazza example snippets


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

PHPShoplazza\ShoplazzaSDK::config($config);

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

PHPShoplazza\ShoplazzaSDK::config($config);

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

PHPShoplazza\ShoplazzaSDK::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';

\PHPShoplazza\AuthHelper::createAuthRequest($scopes, $redirectUrl);

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

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

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

$shoplazza = new PHPShoplazza\ShoplazzaSDK;

$shoplazza = new PHPShoplazza\ShoplazzaSDK($config);

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

$productID = 23564666666;
$product = $shoplazza->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 = $shoplazza->Order->get($params);

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

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

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

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

$webHookID = 453487303;

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

$productID = 23564666666;
$productImages = $shoplazza->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;

$shoplazza->Customer($customerID)->Address->post($address);

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

$shoplazza->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>",
);
$shoplazza->Blog($blogID)->Article($articleID)->put($updateArtilceInfo);

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

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

$data = $shoplazza->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]"
  ]
]
$shoplazza->GraphQL->post($graphQL, null, null, $variables);

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

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

$shoplazza->Customer->search("Bob country:United States");
shell
composer