webgriffe/sylius-back-in-stock-notification-plugin

及时通知客户和访客当产品库存恢复时

4.1.0 2024-06-03 08:17 UTC

This package is auto-updated.

Last update: 2024-09-03 09:00:12 UTC


README

库存恢复通知插件

添加产品库存恢复时接收电子邮件通知的功能的插件

Build Status

功能

订阅以在产品库存恢复时接收通知

Subscription process for configurable product

Subscription for simple product

在您的账户的相应部分查看您的订阅

See the apposite section in the my account

在相应的管理部分查看您的客户订阅

See the apposite section in the admin account

要求

  • PHP ^8.0
  • Sylius ^1.11.2

安装

  1. 运行 composer require webgriffe/sylius-back-in-stock-notification-plugin --no-scripts

  2. 将插件添加到 config/bundles.php 文件

Webgriffe\SyliusBackInStockNotificationPlugin\WebgriffeSyliusBackInStockNotificationPlugin::class => ['all' => true],
  1. 通过在 config/routes/webgriffe_sylius_back_in_stock_notification_plugin.yaml 文件中创建文件来导入插件路由,内容如下
webgriffe_sylius_back_in_stock_notification_plugin:
  resource: "@WebgriffeSyliusBackInStockNotificationPlugin/config/routing.yaml"
  1. 在您的 config/packages/webgriffe_sylius_back_in_stock_notification_plugin.yaml 文件中导入所需的包配置
imports:
   - { resource: "@WebgriffeSyliusBackInStockNotificationPlugin/config/packages.yaml" }
  1. 更新数据库模式并安装资源
bin/console doctrine:migrations:migrate
bin/console assets:install
bin/console sylius:theme:assets:install
  1. 通过将源添加到您的 webpack 配置来安装插件 JS 资源
// Shop config
Encore.setOutputPath('public/build/shop/')
    .setPublicPath('/build/shop')
    .addEntry('shop-entry', './vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/Resources/private/entry.js')
    .addEntry('webgriffe-sylius-back-in-stock-notification-entry', './vendor/webgriffe/sylius-back-in-stock-notification-plugin/public/js/back-in-stock-notification.js') // The line to add
    .disableSingleRuntimeChunk()
    .cleanupOutputBeforeBuild()
    .enableSourceMaps(!Encore.isProduction())
    .enableVersioning(Encore.isProduction())
    .enablePostCssLoader()
    .enableSassLoader()
  1. 运行 yarn build
bin/console yarn:build
  1. 清除缓存
bin/console cache:clear

配置

此模块使用 Symfony 命令发送邮件。不幸的是,命令行上下文不了解您的虚拟主机或域名。为了修复此问题,命令从订阅的渠道加载主机名,如果没有设置,则默认为 localhost。在控制台命令中,URL 默认使用 http。您可以使用这些配置参数全局更改它

  1. 通过添加以下内容编辑 config/services.yml 文件
parameters:
    router.request_context.scheme: https
  1. 如前所述,此模块提供了一个检查产品库存的命令。您必须在 crontab 中设置命令 bin/console webgriffe:back-in-stock-notification:alert,每天一次就足够了
0 12 * * * <absolute-php-path> <absolute-path-to-sylius-dir>/bin/console webgriffe:back-in-stock-notification:alert

可选配置

如果您想使用我们定义的 Behat 步骤,您必须将我们的 Behat 类包含在您的 autoloader-dev 中。为了实现这一点,请向您的 composer.json 添加以下行

"autoload-dev": {
    "psr-4": {
      "Tests\\Webgriffe\\SyliusBackInStockNotificationPlugin\\": "vendor/webgriffe/sylius-back-in-stock-notification-plugin/tests/"
    }
},

贡献

要为此插件做出贡献,请克隆此存储库,为您的功能或错误修复创建一个分支,进行更改,然后确保所有测试都通过。

composer install
(cd tests/Application && yarn install)
(cd tests/Application && yarn build)
(cd tests/Application && APP_ENV=test bin/console assets:install public)

docker-compose up -d # only if you haven't mysql and mailhog installed locally 

(cd tests/Application && APP_ENV=test bin/console doctrine:database:create)
(cd tests/Application && APP_ENV=test bin/console doctrine:schema:create)

要设置插件数据库,请记住在 tests/Application/.envtests/Application/.env.test 中配置您的数据库凭据。

运行插件测试

PHPUnit

vendor/bin/phpunit

PHPSpec

vendor/bin/phpspec run

Behat(非 JS 场景)

vendor/bin/behat --strict --tags="~@javascript"

Behat(JS 场景)

  1. 安装 Symfony CLI 命令.

  2. 启动无头 Chrome

google-chrome-stable --enable-automation --disable-background-networking --no-default-browser-check --no-first-run --disable-popup-blocking --disable-default-apps --allow-insecure-localhost --disable-translate --disable-extensions --no-sandbox --enable-features=Metal --headless --remote-debugging-port=9222 --window-size=2880,1800 --proxy-server='direct://' --proxy-bypass-list='*' http://127.0.0.1
  1. 安装 SSL 证书(只需一次)并在 127.0.0.1:8080 上运行测试应用程序的 web 服务器
symfony server:ca:install
APP_ENV=test symfony server:start --port=8080 --dir=tests/Application/public --daemon
  1. 运行 Behat
vendor/bin/behat --strict --tags="@javascript"

静态分析

Psalm
vendor/bin/psalm
PHPStan
vendor/bin/phpstan analyse -c phpstan.neon
编码标准
vendor/bin/ecs check

使用带有您的插件的 Sylius

  • 使用 test 环境
(cd tests/Application && APP_ENV=test bin/console sylius:fixtures:load)
APP_ENV=test symfony server:start --port=8080 --dir=tests/Application/public --daemon
  • 使用 dev 环境
(cd tests/Application && APP_ENV=dev bin/console sylius:fixtures:load)
APP_ENV=dev symfony server:start --dir=tests/Application/public --daemon

许可证

此插件受 MIT 许可证的保护。有关完整的许可证,请参阅 LICENSE 文件。

鸣谢

Webgriffe® 开发。