ecoco / sylius-base-price-plugin
Sylius base price 插件会在产品价格旁边显示产品基础价格,并在购物车中显示
v1.3.1
2021-07-29 08:40 UTC
Requires
- php: ^7.3
- ext-bcmath: *
- ext-curl: *
- ext-exif: *
- ext-gd: *
- ext-intl: *
- ext-mbstring: *
- ext-simplexml: *
- friendsofsymfony/oauth-server-bundle: ^1.6 || >2.0.0-alpha.0 ^2.0@dev
- jordanbrauer/unit-converter: ^0.8
- sylius/sylius: ^1.8 || ^1.9
Requires (Dev)
- behat/behat: ^3.8.1
- behat/mink-selenium2-driver: ^1.4
- dmore/behat-chrome-extension: ^1.3
- dmore/chrome-mink-driver: ^2.7
- friends-of-behat/mink: ^1.9
- friends-of-behat/mink-browserkit-driver: ^1.5
- friends-of-behat/mink-extension: ^2.5
- friends-of-behat/page-object-extension: ^0.3
- friends-of-behat/suite-settings-extension: ^1.0
- friends-of-behat/symfony-extension: ^2.2
- friends-of-behat/variadic-extension: ^1.3
- lakion/mink-debug-extension: ^1.2.3
- phpspec/phpspec: ^6.3
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: 0.12.25
- phpstan/phpstan-doctrine: 0.12.13
- phpstan/phpstan-strict-rules: ^0.12.3
- phpstan/phpstan-webmozart-assert: 0.12.4
- phpunit/phpunit: ^8.5
- sensiolabs/security-checker: ^6.0
- sylius-labs/coding-standard: ^3.2
- symfony/browser-kit: ^4.4|^5.0
- symfony/debug-bundle: ^4.4|^5.0
- symfony/dotenv: ^4.4|^5.0
- symfony/intl: ^4.4|^5.0
- symfony/web-profiler-bundle: ^4.4|^5.0
- symfony/web-server-bundle: ^4.4|^5.0
- vimeo/psalm: 3.11.4
README
计算并显示产品基础价格的插件
文档
Sylius Base Price Plugin 允许您向您的商店添加有关产品基础价格的信息。安装后,您需要设置产品的变量质量或体积或其他单位。此值将用于计算基础单价,并在产品详情页和购物车中显示。
特性
- 在 sylius_product_variant 表中安装 base_price_unit 和 base_price_value 列。
- 管理员产品变量页面中的“基础价格”标签
- 在产品详情页显示基础价格
- 在购物车中为每个产品显示基础价格
安装
下载并安装
composer require ecoco/sylius-base-price-plugin
启用插件
*此步骤由 symfony 自动完成。
通过将其添加到您的 config/bundles.php
文件来注册插件
return [ // ... Ecocode\SyliusBasePricePlugin\EcocodeSyliusBasePricePlugin::class => ['all' => true], ];
配置
您需要将配置文件复制到项目中
config/packages/ecocode_sylius_base_price_plugin.yaml
cp vendor/ecoco/sylius-base-price-plugin/data/config/packages/ecocode_sylius_base_price_plugin.yaml config/packages/ecocode_sylius_base_price_plugin.yaml
高级配置
如果您想更多地控制可见的指标以及它们如何转换,那么您应该更新
ecocode_sylius_base_price:
(从上方取消注释)
其默认值定义在 src/Resources/config/config.yaml
扩展 ProductVariant
实体
向现有实体添加特质和接口。
src/Entity/Product/ProductVariant.php
cp vendor/ecoco/sylius-base-price-plugin/data/src/Entity/Product/ProductVariant.php src/Entity/Product/ProductVariant.php
运行迁移
bin/console doctrine:migrations:diff bin/console doctrine:migrations:migrate
或更新模式而不定义迁移
bin/console -e test doctrine:schema:update --dump-sql bin/console -e test doctrine:schema:update --dump-sql --force
清除缓存
bin/console cache:clear
使用
1. 选择产品单位
2. 设置产品单位值
3. 在产品详情页中查看
4. 在购物车中查看
测试
使用 docker-compose(推荐)
首先,您需要编辑 edit behat.yml.dist
并取消注释与 docker-compose 相关的行。
然后您可以启动它。准备数据库并运行测试。
docker-compose up -d
docker-compose exec php bash -c "XDEBUG_MODE=coverage composer test"
#docker-compose exec php console doctrine:database:drop --force
#docker-compose exec php console doctrine:database:create
docker-compose exec php console doctrine:schema:update --force
docker-compose exec php console sylius:fixtures:load
docker-compose exec php behat
docker-compose down
使用 docker
使用此测试方法,您将无法轻松测试 behat
docker build . -t sylius-base-price-plugin
docker run -v $(pwd)/build:/var/www/html/build -e XDEBUG_MODE=coverage sylius-base-price-plugin composer test
本地(复杂)
-
您需要有一个正在运行的数据库。您可以使用本地安装的数据库或使用 docker 运行它。
docker run -d --rm -p 3306:3306 -e MYSQL_ROOT_PASSWORD=test -e MYSQL_DATABASE=sylius -e MYSQL_USER=app -e MYSQL_PASSWORD=test mariadb:10.5.9
-
然后编辑并确保数据库配置正确
编辑 tests/Application/.env.test 文件。并将数据库配置添加到其中
DATABASE_URL=mysql://root:root@127.0.0.1/sylius
# if you're running mariadb
DATABASE_URL=mysql://root:root@0.0.0.0/sylius?serverVersion=mariadb-10.3.25
- 导出测试环境(然后命令不需要
-e test
)
export APP_ENV=test
安装
继续设置
composer install cd tests/Application yarn install yarn run gulp bin/console assets:install public -e test bin/console cache:clear -e test #bin/console doctrine:database:drop --force -e test #bin/console doctrine:database:create -e test bin/console doctrine:schema:create -e test bin/console sylius:fixtures:load -e test bin/console doctrine:schema:update --dump-sql --force -e test # If you want to develop something this is one way of starting dev server. # Later on we will use symfony server because it can handle https way easier. #bin/console server:run 127.0.0.1:8080 -d public -e test
回到根目录
cd ../../
然后您应该能够运行 phpunit 和其他静态代码分析检查。
PhpUnit
vendor/bin/phpunit
静态代码分析
Psalm
vendor/bin/psalm
PHPStan
vendor/bin/phpstan analyse -c phpstan.neon -l max src/
Behat(JS 场景)
1. [Install Symfony CLI command](https://symfony.com.cn/download).
2. Start Chrome (all other chrome sessions needs to be closed first):
Headless
```bash
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
```
Normal
```bash
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 --remote-debugging-port=9222 --window-size=2880,1800 --proxy-server='direct://' --proxy-bypass-list='*' http://127.0.0.1
```
3. Install SSL certificates (only once needed) and run test application's webserver on `127.0.0.1:8080`:
```bash
symfony server:ca:install
APP_ENV=test symfony server:start --port=8080 --dir=tests/Application/public --daemon
```
4. Run Behat:
Uncomment local configuration in `behat.yml.dist` (and comment out docker-compose one)
```bash
vendor/bin/behat --strict --tags="@javascript"
```