Magento2创建多个自定义配送承运人仅显示一个冲突问题求助
冲突原因
两个自定义承运模块使用了重复的承运人唯一标识码,Magento配置中<carriers>节点下的子节点名即为承运人的唯一标识,你两个模块都使用了<customshipping>作为节点名,后加载的模块配置会直接覆盖先加载的配置,最终只会显示一个承运人选项。
修复步骤
- 修改第二个模块
etc/config.xml文件的承运人节点名,替换为唯一值,比如改为customshipping2,参考修改后的代码:
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd"> <default> <carriers> <customshipping2> <active>0</active> <title>自定义物流2标题</title> <name>自定义物流2名称</name> <shipping_cost>10</shipping_cost> <sallowspecific>0</sallowspecific> <sort_order>20</sort_order> <model>Vendor2\CustomShipping\Model\Carrier\Customshipping</model> </customshipping2> </carriers> </default> </config>
- 同步修改第二个模块承运人模型
Vendor2\CustomShipping\Model\Carrier\Customshipping.php中的$_code属性值,和刚修改的节点名保持一致:
protected $_code = 'customshipping2';
- 如果你为第二个模块单独写了后台配置的
etc/adminhtml/system.xml文件,需要同步把配置路径里的承运人标识替换为新的customshipping2,否则后台配置项无法匹配到对应承运人。 - 最后执行Magento更新命令刷新配置:
php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento cache:flush
修改完成后后台就可以同时看到两个自定义承运人选项。
内容的提问来源于stack exchange,提问作者zaba
相关产品推荐
相关产品推荐

