PHP code example of schababerle-digital / shopware6-api-client
1. Go to this page and download the library: Download schababerle-digital/shopware6-api-client 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/ */
schababerle-digital / shopware6-api-client example snippets
use Shopware6Client\Shopware6ApiClient;
// Initialize client
$client = new Shopware6ApiClient(
'https://your-shop.com',
'YOUR_CLIENT_ID',
'YOUR_CLIENT_SECRET'
);
// Authenticate
$client->authenticate();
// Fetch products
$products = $client->getProducts(['limit' => 10]);
// Create a new product
$newProduct = $client->createProduct([
'name' => 'My Product',
'productNumber' => 'MP-001',
'stock' => 100,
'taxId' => 'YOUR_TAX_ID',
'price' => [
[
'currencyId' => 'YOUR_CURRENCY_ID',
'gross' => 19.99,
'net' => 16.80,
'linked' => true
]
]
]);
// Update product
$client->updateProduct($newProduct['data']['id'], [
'stock' => 150,
'description' => 'This is a product description'
]);
// Delete product
$client->deleteProduct($newProduct['data']['id']);
// Fetch products with filter
$activeProducts = $client->getProducts([
'filter' => [
[
'type' => 'equals',
'field' => 'active',
'value' => true
]
],
'sort' => [
[
'field' => 'name',
'order' => 'ASC'
]
],
'limit' => 10,
'page' => 1
]);
// Filter orders by date
$recentOrders = $client->getOrders([
'filter' => [
[
'type' => 'range',
'field' => 'orderDateTime',
'parameters' => [
'gte' => '2023-01-01T00:00:00+00:00'
]
]
],
'sort' => [
[
'field' => 'orderDateTime',
'order' => 'DESC'
]
]
]);
try {
$client->authenticate();
$products = $client->getProducts(['limit' => 10]);
} catch (\Exception $e) {
echo "Error: " . $e->getMessage();
}