aligent / orocommerce-fees-bundle
OroCommerce 结账时收费的捆绑包
Requires
- oro/commerce: ~5.0.6
Requires (Dev)
- friendsofphp/php-cs-fixer: ~2.18.2 || ~2.19.0
- phpmd/phpmd: ^2.12
- phpstan/phpstan: ^1.7
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.6
- symfony/phpunit-bridge: ~4.4.24 || ~6.1.0
This package is auto-updated.
Last update: 2024-09-04 07:02:09 UTC
README
此捆绑包增加了在结账过程中动态注入 '费用' 作为新行项的能力。
例如,如果订单金额低于 100 美元需要收取 '处理费'。
此捆绑包利用了 OroCommerce 的 '自由表单项' 功能,可以在结账时添加行项而不必将其链接到产品。
它还支持对整个订单添加作为小计的费用。
要求
- OroCommerce 5.0
重要注意事项/警告
- 此捆绑包目前仅添加了支付处理费,任何其他费用必须使用提供的抽象类/接口手动实现。
- 添加到购物车的行项 不是 真实的产品。我们利用了 Oro Checkouts 中的 '自由表单项' 功能。这使得价格和描述可以由费用本身设置,并避免了任何可能的库存/可见性问题。
- 下起新订单的过程(购物车 => 结账 => 订单)与重新下单现有订单的过程(订单 => 结账 => 订单)略有不同。因此,我们的
CreateCheckoutListener
需要手动持久化/刷新结账,以便保存新的行项。
安装和使用
注意:根据您的本地环境调整说明
安装
通过 Composer 安装
composer require aligent/orocommerce-fees-bundle
安装后,运行平台更新以执行安装
php bin/console oro:platform:update --env=prod
配置
- 登录到 Oro Admin
- 访问 系统配置 => 商务 => Aligent => 费用(或网站特定的等效项)
- 设置 默认产品税码
注意:此税码将应用于费用本身。Oro 不会对自由表单项应用税,此配置由我们的 ContextHandler\FreeFormAwareTaxOrderLineItemHandler
用于应用正确的税。
数据库修改
- 向
oro_order
数据库表添加一个新列processing_fee
(并扩展了 OroOrder
实体)
所有配置都存储在系统配置(oro_config_value
)中。
支付处理费
此功能允许 OroCommerce 对通过特定方法进行的支付收取额外百分比。
百分比可以按方法进行配置,例如
- Visa/MasterCard 信用卡支付收取 1.5% 的费用
- AMEX 信用卡支付收取 2.0% 的费用
安装后,访问系统配置(或网站配置以在网站范围内进行配置)。
每个支付方法都将在此处可见。将百分比设置为大于 0
的值以对该方法收取处理费
如果客户在结账时选择该方法,则会计算处理费并将其添加到小计中
注意:当前不支持 PayPal Express 的处理费,因为它们不包括在小计中,这会导致支付验证错误。
此外,PayPal 用户协议 不允许收取支付处理费(见 #13)
添加和注册新的自定义费用
-
创建一个新的捆绑包(或根据需要使用现有的捆绑包)
-
为费用创建一个新类(例如
MyBundle\Fee\HandlingFeeProvider
)。此新类应扩展Aligent\FeesBundle\Fee\AbstractLineItemFee
。 -
为新的费用定义一个新的服务,并将其添加到费用注册表中
services: Acme\MyBundle\Fee\HandlingFeeProvider: parent: '@Aligent\FeesBundle\Fee\Provider\AbstractLineItemFeeProvider' tags: - { name: aligent_fees.fee_provider, priority: 0 }
-
创建一个新的费用提供程序类并实现相应的函数
<?php namespace Acme\MyBundle\Fee\Provider; use Aligent\FeesBundle\Fee\AbstractLineItemFeeProvider; use Oro\Bundle\CheckoutBundle\Entity\Checkout; class HandlingFeeProvider extends AbstractLineItemFeeProvider { const NAME = 'fees.handling_fee'; const TYPE = 'handling_fee'; const LABEL = 'acme.my_bundle.fees.handling_fee.label'; const SKU = 'HF001'; // Shouldn't be a real product const AMOUNT = 10.00; /** * Get Fee name * @return string */ public function getName(): string { return self::NAME; } /** * Return label key * @return string */ public function getLabel(): string { return $this->translator->trans(self::LABEL); } /** * Return SKU of Fee * @return null|string */ public function getSKU(): ?string { return self::SKU; } /** * @param Checkout $checkout * @return float|null */ public function getAmount(Checkout $checkout): ?float { return self::AMOUNT; } /** * Is the fee Supported by this Entity? * @param mixed $entity * @return bool */ public function isSupported($entity): bool { return ($entity instanceof Checkout); } }
值得注意的功能
如果出现问题,首先应该查看哪里
- 方法
EventListener\CreateCheckoutListener::onStartCheckoutConditionCheck()
将费用注入当前结账中作为新的行项目。 - 方法
Fee\AbstractFee::getCheckoutLineItem()
构建并生成费用自由格式行项目,包括价格/货币/SKU/单位等。
核心覆盖和扩展
- 类
ContextHandler\FreeFormAwareTaxOrderLineItemHandler
装饰了核心Oro\Oro\Bundle\TaxBundle\OrderTax\ContextHandler\OrderLineItemHandler
类,使其能够支持自由格式行项目的税务计算。
路线图/剩余任务
- OroCommerce 5.0 支持
- 实现单元测试
- 完成添加对作为小计添加的费用支持
- 添加对支付处理费用的本地支持
-
添加对PayPal Express处理费用的支持(见 #13) - 重新实现对行项目消息的支持
- 将产品税务代码配置转换为选择字段
- 对处理费用有更细粒度的控制(例如,排除某些客户群体被收费)
- (待定)添加对表达式语言的支持