setono/sylius-lagersystem-plugin

Lagersystem.dk 系统的官方 Sylius 插件

This package is auto-updated.

Last update: 2024-09-15 19:19:57 UTC


README

Latest Version Latest Unstable Version Software License Build Status Quality Score

这是 Lagersystem.dk 系统的官方插件

安装

步骤 1: 安装并启用插件

打开命令行控制台,进入您的项目目录,并执行以下命令以下载此插件的最新稳定版本

$ composer require setono/sylius-lagersystem-plugin

此命令需要您已全局安装 Composer,具体请参阅 Composer 文档中的 安装章节

将捆绑包添加到您的 config/bundles.php

<?php
# config/bundles.php

return [
    // ...
    Setono\SyliusLagersystemPlugin\SetonoSyliusLagersystemPlugin::class => ['all' => true],
    // ...
];

安装其他插件(可选)

为了在端点渲染产品变体的条形码,安装

步骤 2: 导入路由和配置

导入路由

# config/routes/setono_sylius_lagersystem.yaml
setono_sylius_lagersystem:
    resource: "@SetonoSyliusLagersystemPlugin/Resources/config/routes.yaml"

导入应用程序配置

# config/packages/setono_sylius_lagersystem.yaml
imports:
    - { resource: "@SetonoSyliusLagersystemPlugin/Resources/config/app/config.yaml" }    

步骤 3: 覆盖存储库

注意

  • 我们假设产品变体的运输重量存储在数据库中以千克为单位。
  • Lagersystem API 返回的重量以克为单位
  • 未跟踪的产品变体在 API 响应中将具有 onHand 的值为 1

请求示例

先决条件

  • 安装 Curl CLI 和 JQ

    # OSX
    brew install curl
    brew install jq
  • 加载默认 Sylius 固件套件

    (cd tests/Application && bin/console sylius:fixtures:load default -n)
  • 运行本地服务器

    (cd tests/Application && symfony server:start --port=8000)

认证

SYLIUS_HOST=https://:8000
SYLIUS_ADMIN_API_ACCESS_TOKEN=$(curl $SYLIUS_HOST/api/oauth/v2/token \
    --show-error \
    -d "client_id"=demo_client \
    -d "client_secret"=secret_demo_client \
    -d "grant_type"=password \
    -d "username"=api@example.com \
    -d "password"=sylius-api | jq '.access_token' --raw-output)
echo $SYLIUS_ADMIN_API_ACCESS_TOKEN

产品变体列表端点

curl "$SYLIUS_HOST/api/lagersystem/product-variants?locale=en_US&limit=3" \
    -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"

产品变体显示端点

SYLIUS_SOME_PRODUCT_VARIANT_CODE=$(curl "$SYLIUS_HOST/api/lagersystem/product-variants?locale=en_US&limit=1" \
    --show-error \
    -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN" \
    -H "Accept: application/json" | jq '.items[0].code' --raw-output)
echo "Some product code: $SYLIUS_SOME_PRODUCT_VARIANT_CODE"

curl "$SYLIUS_HOST/api/lagersystem/product-variants/$SYLIUS_SOME_PRODUCT_VARIANT_CODE?locale=en_US" \
    -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"

订单列表端点

curl "$SYLIUS_HOST/api/lagersystem/orders?limit=3" \
    -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"