setono/sylius-stock-movement-plugin

处理库存相关活动的插件


README

Latest Version Latest Unstable Version Software License Build Status Quality Score

记录商店中所有库存变动。您可以使用此功能创建非常精确的库存变动报告。

安装

步骤 1: 下载插件

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

$ composer require setono/sylius-stock-movement-plugin

此命令要求您全局安装了Composer,具体说明请参阅Composer文档中的安装章节

步骤 2: 启用插件

然后,将插件添加到项目 config/bundles.php 文件中注册的插件/包列表中,以启用该插件

<?php

return [
    // ...
    
    League\FlysystemBundle\FlysystemBundle::class => ['all' => true],
    Setono\CronExpressionBundle\SetonoCronExpressionBundle::class => ['all' => true],
    Setono\SyliusStockMovementPlugin\SetonoSyliusStockMovementPlugin::class => ['all' => true],
    
    // It is important to add plugin before the grid bundle
    Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
        
    // ...
];

注意:您必须在网格包之前实例化插件,否则您将看到类似 您请求了不存在的参数 "setono_sylius_stock_movement.model.report_configuration.class"。 的异常。

步骤 3: 导入路由

# config/routes/setono_sylius_stock_movement.yaml
setono_sylius_stock_movement:
    resource: "@SetonoSyliusStockMovementPlugin/Resources/config/routing.yaml"

步骤 4: 配置插件

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

setono_sylius_stock_movement:
    templates:
        - label: Default
          template: "@SetonoSyliusStockMovementPlugin/Template/default.txt.twig"

步骤 5: 更新数据库模式

使用Doctrine迁移创建迁移文件并更新数据库。

$ bin/console doctrine:migrations:diff
$ bin/console doctrine:migrations:migrate

步骤 6: 安装资源

$ php bin/console assets:install

步骤 7: 使用异步传输(可选,但推荐)

此插件中的所有命令都将扩展 CommandInterface。因此,您可以通过添加以下内容到您的 信使配置 来轻松路由所有命令。

# config/packages/messenger.yaml
framework:
    messenger:
        routing:
            # Route all command messages to the async transport
            # This presumes that you have already set up an 'async' transport
            # See docs on how to setup a transport like that: https://symfony.com.cn/doc/current/messenger.html#transports-async-queued-messages
            'Setono\SyliusStockMovementPlugin\Message\Command\CommandInterface': async

步骤 8(可选):创建或导入数据集

  • 导入数据集

    # config/packages/_sylius.yaml
    imports:
        # ...
        - { resource: "@SetonoSyliusStockMovementPlugin/Resources/config/app/fixtures.yaml" }
  • 或创建自己的

    # config/fixtures.yaml
    sylius_fixtures:
        suites:
            YOUR_SUITE:
                fixtures:
                    setono_stock_movement:
                        options:
                            amount: 1000

API

在变体 variant-code 上创建一个库存变动,数量为 1

brew install jq
SYLIUS_HOST=http://127.0.0.1:8000
SYLIUS_ADMIN_API_ACCESS_TOKEN=$(curl $SYLIUS_HOST/api/oauth/v2/token \
    --silent --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)
SYLIUS_SOME_PRODUCT_CODE=$(curl $SYLIUS_HOST/api/v1/products/?limit=1 \
    --silent --show-error \
    -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN" \
    -H "Accept: application/json" | jq '._embedded.items[0].code' --raw-output)
echo "Some product code: $SYLIUS_SOME_PRODUCT_CODE"
SYLIUS_SOME_PRODUCT_VARIANT_CODE=$(curl $SYLIUS_HOST/api/v1/products/$SYLIUS_SOME_PRODUCT_CODE/variants/?limit=1 \
    --silent --show-error \
    -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN" \
    -H "Accept: application/json"| jq '._embedded.items[0].code' --raw-output)
echo "Some product variant code: $SYLIUS_SOME_PRODUCT_VARIANT_CODE"

curl $SYLIUS_HOST/api/v1/stock-movements/ \
  -X POST \
  -H 'Accept: application/json' \
  -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN" \
  -H 'Content-Type: application/json' \
  -d "{
	\"quantity\": 1,
	\"variant\": \"$SYLIUS_SOME_PRODUCT_VARIANT_CODE\"
}"