承接 vin-sw/shopware-sdk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vin-sw/shopware-sdk

Composer 安装命令:

composer require vin-sw/shopware-sdk

包简介

A PHP SDK for Shopware 6 Platform

README 文档

README

php

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

SDK version SW schema
2.x >=6.5
1.x 6.4

You can use 1.x to connect to a sw 6.5 but for up-to-date schema and new 6.5 features, you should use 2.x version instead.

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 levienthuong@gmail.com

Security

If you discover any security related issues, please email levienthuong@gmail.com 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.

vin-sw/shopware-sdk 适用场景与选型建议

vin-sw/shopware-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 530.25k 次下载、GitHub Stars 达 121, 最近一次更新时间为 2021 年 06 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 vin-sw/shopware-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 vin-sw/shopware-sdk 我们能提供哪些服务?
定制开发 / 二次开发

基于 vin-sw/shopware-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 530.25k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 122
  • 点击次数: 23
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

  • Stars: 121
  • Watchers: 8
  • Forks: 49
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-23