Skip to content

neta-io/shopware-sdk

 
 

Repository files navigation

A PHP SDK for Shopware 5 REST API

Code Information:
Build Status Code Coverage Scrutinizer Scrutinizer Code Quality StyleCI

Package Information:
Latest Stable Version Total Downloads License

Requirement

PHP >= 7.2

Installing

composer require neta-io/shopware-sdk

Code Docs

See API Docs

Examples

<?php
    require 'vendor/autoload.php';
    
    // Create a new client
    $client = new ShopwareClient('http://shopware.dev/api/', 'user', 'api_key');

    /**
     * set custom options for guzzle
     * the official guzzle documentation contains a list of valid options (http://docs.guzzlephp.org/en/latest/request-options.html) 
     */  
    //$client = new ShopwareClient('http://shopware.dev/api/', 'user', 'api_key', ['cert' => ['/path/server.pem']]);
    
    // Fetch all articles
    $articles = $client->getArticleQuery()->findAll();
    
    // Fetch one article by id
    $article = $client->getArticleQuery()->findOne(1);
    $article->getName();
    $article->getDescription();
    $article->get('mainDetail.id'); // Nested fields
    $article->get('customField');
    
    // Create an article
    $article = new Article();
    $article->setName("John product doe");
    $article->setDescription("Lorem ipsum");
    // ... <- more setters are required
    $client->getArticleQuery()->create($article);
   
    
    // Update article
    $article->setName("John product doe");
    $updatedArticle = $client->getArticleQuery()->update($article);
    
    // Update multiple articles
    $articleOne = $client->getArticleQuery()->findOne(1);
    $articleOne->setName("John product doe");
    $articleTwo = $client->getArticleQuery()->findOne(2);
    $articleTwo->setName("John product doe 2");
        
    $articles = $client->getArticleQuery()->updateBatch([$articleOne, $articleTwo]);
    
    // Delete an article
    $client->getArticleQuery()->delete(1);
    
    // Delete multiple articles at once
    $client->getArticleQuery()->deleteBatch([1, 2, 3]);
    
    // Find article by parameters
    $client->getArticleQuery()->findByParams([
        'limit' => 10,
        'start' => 20,
        'sort' => [
            [
                'property' => 'name',
                'direction' => \Neta\Shopware\SDK\Util\Constants::ORDER_ASC
            ]
        ],
        'filter' => [
            [
                'property' => 'name',
                'expression' => 'LIKE',
                'value' => '%' . $term . '%'
            ],
            [
                'operator' => 'AND',
                'property' => 'number',
                'expression' => '>',
                'value' => '500'
            ]
        ]
    ]);
?>

Issues/Features proposals

Here is the issue tracker.

Contributing

  • Write some code
  • Write some tests
  • Make a pull request

License

MIT

TODO

  • More tests
  • Generate docs
  • Fluent query builder
  • out-of-the-box pagination
  • Bugs
    • apiUrl: http://example/api doesn't work. It must have a trailing slash in order to work.
    • Invalid response doesn't throw an exception. instead Symfony\Component\Debug\Exception\FatalThrowableError : Call to a member function getId() on array

Credits

This package has been forked from: portrino GmbH leadcommerce

Originally authored by

About

A PHP SDK for the Shopware 5 REST API

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%