setono / sylius-items-sold-plugin
Sylius 插件,用于在每条产品/产品变体详情管理页面上显示已售商品。
dev-master / 1.2.x-dev
2018-09-04 13:21 UTC
Requires
- php: ^7.1
- sylius/sylius: ~1.2.3
- symfony/symfony: ^3.4|^4.1
Requires (Dev)
- behat/behat: ^3.4
- behat/mink: ^1.7@dev
- behat/mink-browserkit-driver: ^1.3
- behat/mink-extension: ^2.2
- behat/mink-selenium2-driver: ^1.3
- friends-of-behat/context-service-extension: ^1.2
- friends-of-behat/cross-container-extension: ^1.1
- friends-of-behat/service-container-extension: ^1.0
- friends-of-behat/symfony-extension: ^1.2.1
- friends-of-behat/variadic-extension: ^1.1
- lakion/mink-debug-extension: ^1.2.3
- phpspec/phpspec: ^4.0
- phpstan/phpstan-doctrine: ^0.10
- phpstan/phpstan-shim: ^0.10
- phpstan/phpstan-symfony: ^0.10
- phpstan/phpstan-webmozart-assert: ^0.10
- phpunit/phpunit: ^6.5
- sylius-labs/coding-standard: ^2.0
This package is auto-updated.
Last update: 2024-09-15 03:50:00 UTC
README
Sylius 插件,用于在每条产品/产品变体详情管理页面上显示已售商品
安装
将插件添加到 composer.json 文件中
composer require setono/sylius-items-sold-plugin
在 AppKernel.php 中注册插件
# app/AppKernel.php final class AppKernel extends Kernel { public function registerBundles(): array { return array_merge(parent::registerBundles(), [ // ... new \Setono\SyliusItemsSoldPlugin\SetonoSyliusItemsSoldPlugin(), ]); } }
添加路由
# app/config/routing.yml setono_sylius_items_sold_plugin_admin: resource: "@SetonoSyliusItemsSoldPlugin/Resources/config/admin_routing.yml" prefix: /admin
配置插件(可选)
您可以选择跳过此步骤,因为即使不进行配置,插件也可以正常工作。在这种情况下,结果将计算任何(结账/支付/发货)状态中的购物车/订单,而不受任何间隔限制,并且不会进行缓存。
但假设我们需要
- 查看每个商品过去14天内被售出的次数
- 将值缓存30分钟(1800秒)以减少服务器负载
- 我们不想计算状态为非 已支付 和 已发货 的订单
# app/config/config.yml services: app.setono_sylius_items_sold.cache: class: Symfony\Component\Cache\Simple\FilesystemCache arguments: - '' - 0 - "%kernel.cache_dir%/items-sold" setono_sylius_items_sold: cache: service: 'app.setono_sylius_items_sold.cache' ttl: 1800 interval: 14 payment_states: - paid shipping_states: - shipped
提示
- 在更改
interval
参数后,别忘了清理缓存。 - 如果您希望计算即使添加到购物车(只要购物车没有在
checkoutCompletedAt
字段中设置订单日期)的商品,请不要指定interval
- 查看
Setono\SyliusItemsSoldPlugin\DependencyInjection\Configuration
以获取有关配置选项的更多信息
(手动)测试插件
-
运行应用程序:(默认情况下,应用程序在
dev
环境中具有默认配置,在prod
环境中具有“配置插件”步骤中的示例配置)SYMFONY_ENV=dev cd tests/Application && \ yarn install && \ yarn run gulp && \ bin/console assets:install web -e $SYMFONY_ENV && \ bin/console doctrine:database:create -e $SYMFONY_ENV && \ bin/console doctrine:schema:create -e $SYMFONY_ENV && \ bin/console sylius:fixtures:load -e $SYMFONY_ENV && \ bin/console server:run -d web -e $SYMFONY_ENV
-
使用 Sylius 示例凭证登录到
https://:8000/admin
Login: sylius@example.com Password: sylius
-
转到任何产品编辑页面,如
https://:8000/admin/products/1
-
或转到产品变体页面,如
https://:8000/admin/products/1/variants/1/edit
-
查看该商品被订购了多少次(或根据配置甚至添加到购物车)