【发布时间】:2017-04-13 19:59:06
【问题描述】:
我有一个覆盖 ShippingMethodConverter 类的模块。我在 di.xml 中进行了这样的配置:
<preference for="Magento\Quote\Model\Cart\ShippingMethodConverter"
type="MyNameSpace\MyModule\Quote\Model\Cart\ShippingMethodConverter"/>
<virtualType name="mynamespace_mymodule_quote_mode_cart_shippingmethodconverter" type="\MyNameSpace\MyModule\Quote\Model\Cart\ShippingMethodConverter">
<arguments>
<argument name="shippingMethodConverter" xsi:type="object">\Magento\Quote\Model\Cart\ShippingMethodConverter</argument>
</arguments>
</virtualType>
不幸的是,我收到了以下错误:
1 exception(s):
Exception #0 (Exception): Recoverable Error: Argument 2 passed to
Magento\Quote\Model\ShippingMethodManagement::__construct()
must be an instance of Magento\Quote\Model\Cart\ShippingMethodConverter,
instance of MyNameSpace\MyModule\Quote\Model\Cart\ShippingMethodConverter given,
called in /path_to_magento/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php
on line 93 and defined in
/path_to_magento/vendor/magento/module-quote/Model/ShippingMethodManagement.php on line 62
我的课是这样开始的:
namespace MyNameSpace\MyModule\Quote\Model\Cart;
/**
* Quote shipping method data.
*
*/
class ShippingMethodConverter
{
..
根据我对 virtualType 的正确理解,我想说我的类应该像给定参数一样处理,以保证 magento 核心中没有类型解析错误。
【问题讨论】: