Search code examples
phpmagentomagento-1.4

Overridding a Shipping Method - What am I missing


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? The module name shows up in the advanced tab of the configuration area, so it's getting loaded, but nothing is happening. Any hints?

Code

etc/modules/Ssi_Shipping.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Ssi_Shipping>
            <active>true</active>
            <codepool>local</codepool>
        </Ssi_Shipping>
    </modules>
</config>

local/Ssi/Shipping/etc.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Ssi_Shipping>
      <version>0.1.0</version>
    </Ssi_Shipping>
  </modules>
  <global>
    <models>
      <shipping>
        <rewrite>
          <carrier_tablerate>Ssi_Shipping_Model_Carrier_Tablerate</carrier_tablerate>
        </rewrite>
        
      </shipping>
    </models>
  </global>
</config>

local/Ssi/Shipping/Model/Carrier/Tablerate.php

<?php
class Ssi_Shipping_Model_Carrier_Tablerate 
  extends Mage_Shipping_Model_Carrier_Tablerate {
      
      public function isActive()
      {
        Mage::log("here! Ssi_Shipping_Model_Carrier_Tablerate");
        
        // check to see if it's disabled
        if (parent::isActive() == false)
          return false;
        
        // check in the shopping cart
        foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item ){
          if ($item->getDeliveryFlag() == "test")
            return true;
      }

      // if nothing is found then disable this option.
        return false;
      }
  }

Solution

  • 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.