PHP code example of slince / shopify-api-php
1. Go to this page and download the library: Download slince/shopify-api-php 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' );
slince / shopify-api-php example snippets
$credential = new Slince\Shopify\PublicAppCredential('Access Token' );
$credential = new Slince\Shopify\PrivateAppCredential('API KEY' , 'PASSWORD' , 'SHARED SECRET' );
$client = new Slince\Shopify\Client('your-store.myshopify.com' , $credential, [
'meta_cache_dir' => './tmp'
$middleware = function (\Psr\Http\Message\ServerRequestInterface $request, callable $next) {
$response = $next($request);
$this ->logger->log($request, $response);
return $response;
};
$client->getMiddlewares()->push($middleware);
$products = $client->getProductManager()->findAll([
'collection_id' => 841564295
'page' => 2
]);
$pagination = $client->getProductManager()->paginate([
'limit' => 3 ,
'created_at_min' => '2015-04-25T16:15:47-04:00'
]);
$currentProducts = $pagination->current();
while ($pagination->hasNext()) {
$nextProducts = $pagination->next();
}
$nextPageInfo = $pagination->getNextPageInfo();
$prevPageInfo = $pagination->getPrevPageInfo();
$products = $pagination->current($nextPageInfo);
$product = $client->getProductManager()->find(12800 );
$product = $client->getProductManager()->update(12800 , [
"title" => "Burton Custom Freestyle 151" ,
"body_html" => "<strong>Good snowboard!<\/strong>" ,
"vendor" => "Burton" ,
"product_type" => "Snowboard" ,
]);
$product = $client->getProductManager()->create([
"title" => "Burton Custom Freestyle 151" ,
"body_html" => "<strong>Good snowboard!<\/strong>" ,
"vendor" => "Burton" ,
"product_type" => "Snowboard" ,
]);
$client->getProductManager()->remove(12800 );
echo $product->getTitle();
echo $product->getCreatedAt();
print_r($product->getVariants());
print_r($product->getImages());
$products = $client->get('products' , [
]);
$product = $client->get('products/12800' );
$product = $client->post('products' , [
"product" => [
"title" => "Burton Custom Freestyle 151" ,
"body_html" => "<strong>Good snowboard!<\/strong>" ,
"vendor" => "Burton" ,
"product_type" => "Snowboard" ,
"images" => [
[
"attachment" => "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAw==\n"
]
]
]
]);
$product = $client->put('products/12800' , [
"product" => [
"title" => "Burton Custom Freestyle 151" ,
"body_html" => "<strong>Good snowboard!<\/strong>" ,
"vendor" => "Burton" ,
"product_type" => "Snowboard" ,
"images" => [
[
"attachment" => "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAw==\n"
]
]
]
]);
$client->delete('products/12800' );
bash
$ composer