1

Class overwrites should be a last resort option when customising M2. I personally stick by the following order: plugin -> observer -> class rewrite.

I am having an issue in the \Magento\Quote\Model\Cart\ShippingMethodConverter area. I'm trying to write a before plugin but for some reason it doesn't work.

I have the following code: frontend/di.xml

<type name="Magento\Quote\Model\Cart\ShippingMethodConverter">
    <plugin name="Namespace\Quote\Plugin\Quote\Model\Cart\ShippingMethodConverter" type="Namespace\Quote\Plugin\Quote\Model\Cart\ShippingMethodConverter" sortOrder="1" />
</type>

Namespace\Quote\Plugin\Quote\Model\Cart\ShippingMethodConverter.php

<?php

namespace Namespace\Quote\Plugin\Quote\Model\Cart;

class ShippingMethodConverter
{
    public function beforeModelToDataObject($subject, $result, $rate, $quote)
    {
        return $result;
    }
}

Any idea why this is happening I want to avoid class overwrite.

1 Answer 1

0

Found what the issue was. The di.xml should have been in etc/di.xml not etc/frontend/di.xml.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.