I have installed the WebShopApps module with composer hence it is installed in the Vendor folder. Now I want to override model in my custom theme. As we know we can't directly modify in vendor folder since changes will be gone once when we upgrade module.

Please let us know how to override the Model folder.

The file path is that want to override in my theme is


Please help me.

2 Answers 2

  1. You could create another module to override the current one


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
       <preference for="WebShopApps\MatrixRate\Model\Carrier\Matrixrate" type="Vendor\Module\Model\Carrier\Matrixrate" />



namespace Vendor\Module\Model\Carrier;

use Magento\Quote\Model\Quote\Address\RateRequest;

class Matrixrate extends \WebShopApps\MatrixRate\Model\Carrier\Matrixrate
    implements \Magento\Shipping\Model\Carrier\CarrierInterface
    protected $helper;

    public function __construct(
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Shipping\Model\Rate\ResultFactory $rateResultFactory,
        \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $resultMethodFactory,
        \WebShopApps\MatrixRate\Model\ResourceModel\Carrier\MatrixrateFactory $matrixrateFactory,
        array $data = []
        parent::__construct($scopeConfig, $rateErrorFactory, $logger, $rateResultFactory, $resultMethodFactory, $matrixrateFactory, $data);

     * @param \Magento\Quote\Model\Quote\Address\RateRequest $request
     * @return bool|\Magento\Shipping\Model\Rate\Result
    public function collectRates(RateRequest $request)

        // Do some stuff here
        return parent::collectRates($request);



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <module name="Vendor_MatrixRate" setup_version="1.0.0">
            <module name="WebShopApps_MatrixRate"/>


    "name": "vendor/matrixrate",
    "description": "",
    "require": {
        "php": "~5.5.0|~5.6.0|~7.0.0",
        "webshopapps/module-matrixrate": "null",

        "magento/magento-composer-installer": "*"
    "suggest": {

    "type": "magento2-module",
    "version": "1.0.0",
    "license": [

    "autoload": {
        "files": [
        "psr-4": {
            "Vendor\\MatrixRate\\": ""
    "extra": {
        "map": [



  1. You could use composer patcher to patch directly to vendor folder

Reference link


As I could understand from your question, you want to make some customizations in the Model class functions. The file you have mentioned has all public functions, so if you want, you can easily create plugins for the class functions to modify the functionality of the class file you have mentioned.

If you want to modify other functions which are not public, you can use preference to override the functionality.

You can check the difference between a plugin and class rewrite at Magento2: what is the basic difference between plugin and preference?

Please let me know if it helped.

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.