brille24 /sylius-tierprice-plugin
一个允许为Sylius添加阶梯价格的插件
2.4.2
2024-07-31 01:12 UTC
Requires
- php: ^8.0
- sylius/sylius: ^1.11.2||^1.12.0
Requires (Dev)
- behat/behat: ^3.6.1
- behat/mink-selenium2-driver: ^1.4
- dmore/behat-chrome-extension: ^1.3
- dmore/chrome-mink-driver: ^2.7
- friends-of-behat/mink: ^1.8
- friends-of-behat/mink-browserkit-driver: ^1.4
- friends-of-behat/mink-debug-extension: ^2.0.0
- friends-of-behat/mink-extension: ^2.4
- friends-of-behat/page-object-extension: ^0.3
- friends-of-behat/suite-settings-extension: ^1.0
- friends-of-behat/symfony-extension: ^2.1
- friends-of-behat/variadic-extension: ^1.3
- friendsofsymfony/oauth-server-bundle: ^1.6 || >2.0.0-alpha.0 ^2.0@dev
- phpspec/phpspec: ^7.0
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: 0.12.99
- phpstan/phpstan-doctrine: 0.12.33
- phpstan/phpstan-strict-rules: ^0.12.0
- phpstan/phpstan-webmozart-assert: 0.12.12
- phpunit/phpunit: ^9.5
- polishsymfonycommunity/symfony-mocker-container: ^1.0
- sensiolabs/security-checker: ^6.0
- sylius-labs/coding-standard: ^4.0
- symfony/browser-kit: ^5.4
- symfony/debug-bundle: ^5.4
- symfony/dotenv: ^5.4
- symfony/intl: ^5.4
- symfony/web-profiler-bundle: ^5.4
- vimeo/psalm: 4.7.1
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.2
- 2.3.1
- 2.3.0
- 2.3.0-ALPHA
- 2.2.0
- 2.1.0
- 2.0.1
- 2.0.0
- dev-master / 1.12.x-dev
- 1.8
- v1.7.4
- v1.7.3
- v1.7.2.2
- v1.7.2.1
- v1.7.2
- v1.7.1
- v1.7
- v1.6
- v1.5.0
- v1.4.5
- v1.4.1
- v1.4
- 1.3.1
- v1.3
- v1.2
- v1.1
- 1.0
- v0.10
- v0.9
- v0.8
- v0.7
- v0.6
- v0.5
- v0.4
- 0.3
- dev-fixing_empty_tierprices
- dev-fixing_master
- dev-fixing_migration_prepend
This package is auto-updated.
Last update: 2024-08-31 01:23:01 UTC
README
Sylius 阶梯价格插件
此插件为Sylius添加阶梯定价功能,一个产品可以根据数量不同设置不同的价格。
安装
- 使用Composer安装该包
composer require brille24/sylius-tierprice-plugin
- 在您的
bundles.php
中注册该包
return [ //... Brille24\SyliusTierPricePlugin\Brille24SyliusTierPricePlugin::class => ['all' => true], ];
- 将
config.yml
添加到您的本地config/config.yml
imports: ... - { resource: '@Brille24SyliusTierPricePlugin/Resources/config/config.yml'}
- 为了API功能,将包的
routing.yml
添加到本地app/config/routing.yml
... brille24_tierprice_bundle: resource: '@Brille24SyliusTierPricePlugin/Resources/config/routing.yml'
- 进入您的ProductVariant类,添加以下特质并在构造函数中添加一个方法调用
class ProductVariant extends BaseProductVariant implements \Brille24\SyliusTierPricePlugin\Entity\ProductVariantInterface { use \Brille24\SyliusTierPricePlugin\Traits\TierPriceableTrait; public function __construct() { parent::__construct(); // Your contructor here $this->initTierPriceableTrait(); // "Constructor" of the trait } protected function createTranslation(): ProductVariantTranslationInterface { return new ProductVariantTranslation(); } }
- 最后更新数据库,安装资产并更新翻译
bin/console doctrine:schema:update --force bin/console assets:install bin/console translation:update <locale> --force
集成
- 此包装饰了
sylius.calculator.product_variant_price
服务。如果您想更改它,可以注册一个 编译器传递。 - 此包装饰了
sylius.order_processing.order_prices_recalculator
服务。如果您想使用自己的订单处理器或更改其优先级,可以注册一个 编译器传递。
用法
首先,您必须设置一个产品,其中包含您想要的变体数量。然后在每个变体中,您可以根据渠道设置阶梯定价。表格会自动排序,以提供对所有不同级别的配置的更好概述。
在前端,用户将看到“添加到购物车”按钮旁边的表格,显示不同级别的折扣,如下所示
创建数据
您可以使用类似这样的 fixtures轻松创建阶梯价格。
sylius_fixtures: suites: my_suite: fixtures: tier_prices: options: custom: - product_variant: "20125148-54ca-3f05-875f-5524f95aa85b" channel: US_WEB quantity: 10 price: 5
为此,需要先创建产品,并且产品变体也必须存在。
扩展
如果您想扩展阶梯价格,请注意,此插件使用XML进行配置。这可能与使用注释的项目冲突。