All Projects → vienthuong → shopware-php-sdk

vienthuong / shopware-php-sdk

Licence: MIT License
A PHP SDK for Shopware 6 Admin API

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to shopware-php-sdk

shopware-sdk
A PHP SDK for the Shopware 5 REST API
Stars: ✭ 33 (-37.74%)
Mutual labels:  shopware, shopware-sdk
SwagMediaS3
No description or website provided.
Stars: ✭ 22 (-58.49%)
Mutual labels:  shopware
Vue Storefront
The open-source frontend for any eCommerce. Built with a PWA and headless approach, using a modern JS stack. We have custom integrations with Magento, commercetools, Shopware and Shopify and total coverage is just a matter of time. The API approach also allows you to merge VSF with any third-party tool like CMS, payment gateways or analytics. Ne…
Stars: ✭ 9,111 (+17090.57%)
Mutual labels:  shopware
docker-setup
🐳 Docker setup by Etribes for almost every PHP based web application that needs a webserver and database.
Stars: ✭ 12 (-77.36%)
Mutual labels:  shopware
downtown
With our portal, we want to support local authorities and merchants. We want to connect merchants with closed stores to their customers. And we want to keep in mind, that not every merchant has a sophisticated digital strategy - or even a homepage.
Stars: ✭ 45 (-15.09%)
Mutual labels:  shopware
production
Shopware 6 production template
Stars: ✭ 156 (+194.34%)
Mutual labels:  shopware
sw6-media-optimizer
Image Optimizer for Shopware 6 💙
Stars: ✭ 18 (-66.04%)
Mutual labels:  shopware
shopware-docker
A docker setup ready for shopware development
Stars: ✭ 75 (+41.51%)
Mutual labels:  shopware
plentymarkets-shopware-connector
plentymarkets shopware connector plugin
Stars: ✭ 32 (-39.62%)
Mutual labels:  shopware
shopware-cms-generator
Generate a CMS element scaffolding within seconds.
Stars: ✭ 26 (-50.94%)
Mutual labels:  shopware
docs
No description or website provided.
Stars: ✭ 28 (-47.17%)
Mutual labels:  shopware
shopware6-advanced-banners
Advanced Banners (Digital Publishing) for Shopware 6 💙
Stars: ✭ 30 (-43.4%)
Mutual labels:  shopware
v-shopware-api-client
The reliable way to import and update a bazillion products.
Stars: ✭ 20 (-62.26%)
Mutual labels:  shopware
SwagThreeSixtyViewer
No description or website provided.
Stars: ✭ 23 (-56.6%)
Mutual labels:  shopware
shopware5-live-templates
Shopware Live Templates for PhpStorm
Stars: ✭ 14 (-73.58%)
Mutual labels:  shopware
idea-php-shopware-plugin
Shopware Plugin for PhpStorm which extends Symfony Plugin
Stars: ✭ 50 (-5.66%)
Mutual labels:  shopware
WbmTagManager
Shopware 5 Plugin for Google Tag Manager integration and dataLayer configuration
Stars: ✭ 24 (-54.72%)
Mutual labels:  shopware
FroshProductCompare
A Plugin for Shopware 6 - Ecommerce Platform
Stars: ✭ 27 (-49.06%)
Mutual labels:  shopware
FroshPluginUploader
Tool for uploading new plugin releases to Shopware Store
Stars: ✭ 26 (-50.94%)
Mutual labels:  shopware
hubble-frontend-pwa
E-Commerce PWA Frontend
Stars: ✭ 43 (-18.87%)
Mutual labels:  shopware

Shopware 6 PHP SDK

php

"Buy Me A Coffee"

GitHub Release Latest Version on Packagist Software License

Shopware PHP SDK is a simple SDK implementation of Shopware 6 APIs. It helps to access the API in an object-oriented way.

If you're familiar with Shopware 6 DAL syntax and how to retrieve it you might see this example is predictable and straightforward

image

Or sending notification from external server image

Installation

Install with Composer

composer require vin-sw/shopware-sdk

The SDK main features:

  • Admin API

    • CRUD API
    • Sync Api
    • User Config API
    • Notification API
    • Admin Search API
    • Other services
    • ... (TODO)
  • Webhook helper

    • Webhook registration
    • Webhook authentication
    • Webhook receiver
  • If you're using Laravel 8, consider check this out Laravel Shopware SDK Adapter

Usage

More in the examples folder, for integrating the sdk in an App, have a look at this repository

Admin Authentication

  • Supported 3 grant types, you can create one of these 3 grant type for authentication:

Using Password grant type

$grantType = new PasswordGrantType($username, $password);

Using Client credential grant type

$grantType = new ClientCredentialsGrantType($clientId, $clientSecret);

Using Refresh token grant type

$grantType = new RefreshTokenGrantType($refreshToken);

Or dynamically via

$grantType = GrantType::createFromConfig($config);

Check the authentication example for the reference.

After having a GrantType object, you can fetch the admin's access token using the AdminAuthenticator

$adminClient = new AdminAuthenticator($grantType, $shopUrl);
$accessToken = $adminClient->fetchAccessToken();
$context = new Context($shopUrl, $accessToken);

Notice: You might want to store the access token object into the database so you can create the object without request for another access token for every Admin API request.

Working with Criteria and Repositories

It's pretty identical to what you expected when working with Shopware's core or repositories in the SW administration.

This is an example to retrieve a product that have free shipping

// Create the repository for the entity
$productRepository = RepositoryFactory::create(ProductDefinition::ENTITY_NAME);

// Create the criteria
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('shippingFree', true));

// Using this criteria and the context object that you create from authentication step, you can retrieving the result
$products = $productRepository->search($criteria, $context);

Each shopware's entity is mapped into Entity and Collection Classes which can be found in Data/Entity so you can easily access their properties when retrieving data from Admin API.

Support methods get, search, searchIds, create, update, delete, syncDeleted, createVersion, mergeVersion, deleteVersion, clone, schema. Each method requires a Context object

Check examples/entity-repository.php for some useful references.

Working with App

AppRegistration examples:

The example took from a Laravel route action, but it can be the same in other frameworks

public function register(ShopRepository $repository): RegistrationResponse
{
    $authenticator = new WebhookAuthenticator();

    $app = new App(config('sas_app.app_name'), config('sas_app.app_secret'));

    $response = $authenticator->register($app);

    // Save the response the database...
    $repository->createShop($response->getShop());

    $confirmationUrl = route('sas.app.auth.confirmation');

    return new RegistrationResponse($response, $confirmationUrl);
}

public function confirm(Request $request, ShopRepository $shopRepository): Response
{
    $shopId = $request->request->get('shopId');

    $shopSecret = $shopRepository->getSecretByShopId($shopId);

    if (!WebhookAuthenticator::authenticatePostRequest($shopSecret)) {
        return new Response(null, 401);
    }

    $shopRepository->updateAccessKeysForShop(
        $shopId,
        $request->request->get('apiKey'),
        $request->request->get('secretKey')
    );

    return new Response();
}

Action Button Response examples:

When receive a POST request from an action button, you can return one of these ActionResponse (PSR-7 Response) classes ported from Shopware's core

namespace Vin\ShopwareSdk\Data\Response;
/**
* @see Shopware\Core\Framework\App\ActionButton
 */
new EmptyResponse();
new ReloadDataResponse($shopSecret);
new OpenNewTabResponse($shopSecret, 'http://shopware.test');
new NotificationResponse($shopSecret, 'Success!', NotificationResponse::SUCCESS);
new NotificationResponse($shopSecret, 'Error!', NotificationResponse::ERROR);
new OpenModalResponse($shopSecret, $iframeUrl, OpenModalResponse::LARGE_SIZE, true);

Working with Admin API Services

An ApiService requires a Context object as its first argument. Check examples/sync-service.php or examples/info-service.php for some references.

Change log

Please see CHANGELOG for more information on what has changed recently.

Working with Webhook

Contribution

Feels free to create an issue on Github issues page or contact me directly at [email protected]

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Requirements

  • ext-curl
  • PHP 7.4
  • SW >= 6.4

This SDK is mainly dedicated to Shopware 6.4 and onwards, earlier SW application may still be usable without test

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].