Overridding a Shipping Method - What am I missing

后端 未结 5 1161
生来不讨喜
生来不讨喜 2021-01-12 17:53

I\'ve written many many modules before but for some reason my shipping module won\'t override an exsiting Magneto shipping method. Is that allowed? What am I missing here?

相关标签:
5条回答
  • Check first that the model is being overridden at all. Try this:

    var_dump(get_class(Mage::getModel("shipping/carrier_tablerate")));
    
    0 讨论(0)
  • 2021-01-12 18:39

    If anyone else is facing this problem and came here for solution, it looks like OP have used codepool in module file where it should be codePool (notice the capital P).

    0 讨论(0)
  • 2021-01-12 18:47

    There is a way but it is not obvious and required me to browse the shipping module source:

    If you look at Mage_Shipping_Model_Config, you will discover that the code used as parameter for Mage::getModel() is taken from the store configuration. This code is NOT the standard code like 'shipping/carrier_tablerate', so it does not help overriding as usual.

    Now you have to find out first what this code is. For example I wanted to override the matrixrate carrier, so I tested it like that:

    $carrierConfig = Mage::getStoreConfig('carriers/matrixrate')
    var_dump($carrierConfig['model']);
    

    Yes, you can put this code anywhere on the page temporary but it is useful to have a separate file for such things that can be run from the command line (starting with Mage::app() to initialize Magento)

    In my case the code was matrixrate_shipping/carrier_matrixrate so I had to change my config.xml like that:

    <global>
        <models>
            <matrixrate_shipping>
                <rewrite>
                    <carrier_matrixrate>my_class_name</carrier_matrixrate>
                </rewrite>
            </matrixrate_shipping>
        </models>
    

    instead of

    <global>
        <models>
            <matrixrate>
                <rewrite>
                    <carrier_matrixrate>my_class_name</carrier_matrixrate>
                </rewrite>
            </matrixrate>
        </models>
    

    Good Luck!

    0 讨论(0)
  • 2021-01-12 18:50

    After working through this one a bit, I found that the only way to override the shipping controller was to make a duplicate of the file (and directory structure) in the local code folder. Then I could basically tweak the code.

    Not sure why Magento doesn't seem to allow the standard overriding of these shipping functions, but a least there is a work around.

    0 讨论(0)
  • 2021-01-12 18:52

    it's been a while but I had the same problem the last days. I wanted to override freeshipping and flatrate shipping methods and in addition to the answer of fab I had to add the following code in etc/config.xml. In my case the original values are located in app/code/core/Mage/Shipping/etc/config.xml.

    <?xml version="1.0"?>
    <config>
        ...
        <default>
            <carriers>
                <flatrate>
                    <model>your_module/shipping_carrier_flatrate</model>
                </flatrate>
                <freeshipping>
                    <model>your_module/shipping_carrier_freeshipping</model>
                </freeshipping>
            </carriers>
        </default>
    </config>
    

    The model values are examples. You have to replace them with your correct paths.

    0 讨论(0)
提交回复
热议问题