smacx / customer-group-payments
限制在Magento 2中特定客户群体的支付方式。
Requires
- php: ^7.1
- magento/framework: ^102.0
- magento/module-customer: ^102.0
- magento/module-payment: ^100.2
- magento/module-quote: ^101.0
- smaex/additional-payment-checks: ^1.0
Requires (Dev)
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2023-06-04 09:21:00 UTC
README
在Magento 2中限制特定客户群体的支付方式。
简介
在Magento 2中,为支付方式添加额外的检查 - 以确定某种支付方式是否适用于特定客户 - 非常简单直接。
Magento 提供了一个相对简单的接口用于自定义支付方式检查,并使用组合检查来处理这些单独的检查。因此,添加自定义检查只需将其注入到Magento的复合检查中即可。
此扩展实现了一个自定义检查,根据客户群体决定某种支付方式是否适用于客户,并包含相应的系统配置字段用于支付方式。
先决条件
遗憾的是,当前在Magento代码中关于此机制的局限性,需要我们使用一个小型绕道,因此此扩展依赖于另一个提供此绕道的扩展。有关更多信息,请参阅smaex/additional-payment-checks。
如何安装
只需通过Composer要求扩展。
$ composer require smaex/customer-group-payments ^2.0
最后,通过Magento的CLI启用模块。
$ magento module:enable Smaex_CustomerGroupPayments
如何使用
虽然此扩展为您提供了限制支付方式到特定客户群体所需的所有工具,但如果没有您的自定义配置,它将不起作用。这是因为添加系统配置字段是通过在Magento中通过XML配置完成的。
为了正确配置您的支付方式,最好的方法可能是设置自己的自定义模块(例如,Acme_Payment
)在app/code
下。
在您的module.xml
中声明对Magento_Payment
和Smaex_CustomerGroupPayments
的依赖是强制性的,对其他模块(如Magento_OfflinePayments
)的依赖取决于您的项目中实际使用的支付方式。
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Acme_Payment" setup_version="1.0.0"> <sequence> <module name="Magento_OfflinePayments"/> <module name="Magento_Payment"/> <module name="Smaex_CustomerGroupPayments"/> </sequence> </module> </config>
接下来的最后一步是在您的自定义模块中提供自己的system.xml
在etc/adminhtml
下,并扩展您项目中使用的每个支付方式的现有配置。
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> <system> <section id="payment"> <!-- Check / Money Order --> <group id="checkmo"> <field id="customer_groups" type="multiselect" translate="label comment" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1" sortOrder="52"> <include path="Smaex_CustomerGroupPayments::system/customer_groups.xml"/> </field> </group> <!-- Cash On Delivery Payment --> <group id="cashondelivery"> <field id="customer_groups" type="multiselect" translate="label comment" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1" sortOrder="52"> <include path="Smaex_CustomerGroupPayments::system/customer_groups.xml"/> </field> </group> </section> </system> </config>
替代方案
如果您是一个懒惰的树懒,觉得这(即XML配置)工作太多,也有另一个从截然不同角度解决相同问题的扩展:点击这里。
我们正在招聘!
想要为德国领先的Magento合作伙伴之一工作吗?采用敏捷方法、小型团队和大型客户?我们现在正在寻找经验丰富的受虐狂 慕尼黑的PHP & Magento开发者。听起来很有趣?请通过j.scherbl@techdivision.com与我联系。