Hello,
Thanks jimbobrjames. As a starting project I used the Plainkit: Shop.
I use snipcart in v3.12.0.
texnixe, thanks !
here PHP code:
<?php
function call_snipcart_api($url, $method = "GET", $post_data = null) {
$url = 'https://app.snipcart.com/api' . $url;
$query = curl_init();
$headers = array();
$headers[] = 'Content-type: application/json';
if ($post_data)
$headers[] = 'Content-Length: ' . strlen($post_data);
$headers[] = 'Accept: application/json';
// API KEY TEST MODE SNIPCART
$secret = 'ST_YmZjMmUzZWMtYjMzOC00OGQ0LWI3ZjAtNDBmNDJmMzQxNGQxNjM3MjU0MzQyODAxNzgyNzM1';
$headers[] = 'Authorization: Basic '.base64_encode($secret . ":");
$options = array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0
);
if ($post_data) {
$options[CURLOPT_CUSTOMREQUEST] = $method;
$options[CURLOPT_POSTFIELDS] = $post_data;
}
curl_setopt_array($query, $options);
$resp = curl_exec($query);
curl_close($query);
return json_decode($resp);
}
$orders = call_snipcart_api('/products');
echo json_encode($orders);
?>
here is the JSON code:
{
keywords: null,
userDefinedId: null,
archived: false,
excludeZeroSales: false,
from: null,
to: null,
orderBy: "SalesValue",
hasMoreResults: false,
totalItems: 4,
offset: 0,
limit: 20,
items: [
{
mode: "Test",
userDefinedId: "watch",
url: "http://dev.siteinternetfacile.com/_demokitmaster/demokit-master/shop/watch",
name: "Watch",
description: "A watch without a face. No longer get distracted by the vague concept of time.",
fileGuid: null,
price: 249,
categories: [ ],
image: null,
archived: false,
inventoryManagementMethod: "Single",
stock: 10,
totalStock: 10,
allowOutOfStockPurchases: false,
statistics: {
numberOfSales: 0,
totalSales: 0
},
customFields: [ ],
variants: [ ],
metadata: null,
id: "59415ccf-64d5-4e35-82e0-190675ca89ea",
creationDate: "2020-04-07T20:28:11.673Z",
modificationDate: "2020-04-07T20:28:11.673Z"
},
{ ... },
{ ... },
{ ... }
]
}
To display the stock of a product I take its “id” and I put it in the url with this little piece of php code:
$orders = call_snipcart_api('/products/59415ccf-64d5-4e35-82e0-190675ca89ea');
echo $orders->stock;
I don’t know if you know snipcart well. For a product to be added to the inventory, you must send its url in the snipcart administration interface.
Then click on the product and add the stock:
For the moment the support of snipcart told me to look at these links there but the documentation is not as simple as Kirby. There is no very concrete example.
General: https://docs.snipcart.com/v3/api-reference/introduction
Product: https://docs.snipcart.com/v3/api-reference/products
He indicated me a single project which manages the stock:
Indeed in the demonstration he manages to report products in “out of stock”:
Thanks for help !