Overriding Magento 1.9 interface

by Dany Khalife   Last Updated August 21, 2016 08:03 AM

I've just started writing Magento 1.9 plugins and I started with a basic example of writing a basic Shipping Method plugin that will return static rates.

Here is what the structure of the model file looks like :

class X_Y_Model_Carrier
extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface {

protected $_code = 'x_y';

public function collectRates(Mage_Shipping_Model_Rate_Request $request){
    $result = Mage::getModel('shipping/rate_result');

    [...]
    $address = $request->$request->getDestStreet();
    $city = $request->getDestCity();
    [...]

    $rate = Mage::getModel('shipping/rate_result_method');
    $rate->setCarrier($this->_code);
    $rate->setCarrierTitle('Carrier');
    $rate->setMethod('x_y_1');
    $rate->setMethodTitle('Method 1');
    $rate->setPrice(12.34);
    $rate->setCost(1.23);

            [...]
    return $result;
}

[...]
}

I noticed that i don't have the detailed address in the $request so getDestCity returns null for example.

I've done some research and according to this answer in order to have such details, I would need to override EstimateAddressInterface.

Could anyone guide me on how to achieve that? How exactly does one override an interface (the proper way) in Magento 1.9



Answers 1


You try to pick getDestStreet wrong way and should get an fatal error. Correct code as

class X_Y_Model_Carrier
extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface {

protected $_code = 'x_y';

public function collectRates(Mage_Shipping_Model_Rate_Request $request){
    $result = Mage::getModel('shipping/rate_result');

    [...]
    $address = $request->getDestStreet();
    $city = $request->getDestCity();
    [...]

    $rate = Mage::getModel('shipping/rate_result_method');
    $rate->setCarrier($this->_code);
    $rate->setCarrierTitle('Carrier');
    $rate->setMethod('x_y_1');
    $rate->setMethodTitle('Method 1');
    $rate->setPrice(12.34);
    $rate->setCost(1.23);

            [...]
    return $result;
}

[...]
}

Check request class which is app/code/core/Mage/Shipping/Model/Rate/Request.php

Following fields you should get:

/**
 * Fields:
 * - orig:
 *   - country_id: UK
 *   - region_id: 1
 *   - postcode: 90034
 * - dest:
 *   - country_id: UK
 *   - region_id: 2
 *   - postcode: 01005
 * - package:
 *   - value: $100
 *   - weight: 1.5 lb
 *   - height: 10"
 *   - width: 10"
 *   - depth: 10"
 * - order:
 *   - total_qty: 10
 *   - subtotal: $100
 * - option
 *   - insurance: true
 *   - handling: $1
 * - table (shiptable)
 *   - condition_name: package_weight
 * - limit
 *   - carrier: ups
 *   - method: 3dp
 * - ups
 *   - pickup: CC
 *   - container: CP
 *   - address: RES
 */

Following getter methods are available:

/* @method int getStoreId()
 * @method Mage_Shipping_Model_Rate_Request setStoreId(int $value)
 * @method int getWebsiteId()
 * @method Mage_Shipping_Model_Rate_Request setWebsiteId(int $value)
 * @method string getBaseCurrency()
 * @method Mage_Shipping_Model_Rate_Request setBaseCurrency(string $value)
 *
 * @method Mage_Shipping_Model_Rate_Request setAllItems(array $items)
 * @method array getAllItems()
 *
 * @method Mage_Shipping_Model_Rate_Request setOrigCountryId(string $value)
 * @method string getOrigCountryId()
 * @method Mage_Shipping_Model_Rate_Request setOrigRegionId(int $value)
 * @method int getOrigRegionId()
 * @method Mage_Shipping_Model_Rate_Request setOrigPostcode(string $value)
 * @method string getOrigPostcode()
 * @method Mage_Shipping_Model_Rate_Request setOrigCity(string $value)
 * @method string getOrigCity()
 *
 * @method Mage_Shipping_Model_Rate_Request setDestCountryId(string $value)
 * @method string getDestCountryId()
 * @method Mage_Shipping_Model_Rate_Request setDestRegionId(int $value)
 * @method int getDestRegionId()
 * @method Mage_Shipping_Model_Rate_Request setDestRegionCode(string $value)
 * @method string getDestRegionCode()
 * @method Mage_Shipping_Model_Rate_Request setDestPostcode(string $value)
 * @method string getDestPostcode()
 * @method Mage_Shipping_Model_Rate_Request setDestCity(string $value)
 * @method string getDestCity()
 * @method Mage_Shipping_Model_Rate_Request setDestStreet(string $value)
 * @method string getDestStreet()
 *
 * @method Mage_Shipping_Model_Rate_Request setPackageValue(float $value)
 * @method float getPackageValue()
 * @method Mage_Shipping_Model_Rate_Request setPackageValueWithDiscount(float $value)
 * @method float getPackageValueWithDiscount()
 * @method Mage_Shipping_Model_Rate_Request setPackagePhysicalValue(float $value)
 * @method float getPackagePhysicalValue()
 * @method Mage_Shipping_Model_Rate_Request setPackageQty(float $value)
 * @method float getPackageQty()
 * @method Mage_Shipping_Model_Rate_Request setPackageWeight(float $value)
 * @method float getPackageWeight()
 * @method Mage_Shipping_Model_Rate_Request setPackageHeight(int $value)
 * @method int getPackageHeight()
 * @method Mage_Shipping_Model_Rate_Request setPackageWidth(int $value)
 * @method int getPackageWidth()
 * @method Mage_Shipping_Model_Rate_Request setPackageDepth(int $value)
 * @method int getPackageDepth()
 * @method Mage_Shipping_Model_Rate_Request setPackageCurrency(string $value)
 * @method string getPackageCurrency()
 *
 * @method Mage_Shipping_Model_Rate_Request setOrderTotalQty(float $value)
 * @method float getOrderTotalQty()
 * @method Mage_Shipping_Model_Rate_Request setOrderSubtotal(float $value)
 * @method float getOrderSubtotal()
 *
 * @method boolean getFreeShipping()
 * @method Mage_Shipping_Model_Rate_Request setFreeShipping(boolean $flag)
 * @method float getFreeMethodWeight()
 * @method Mage_Shipping_Model_Rate_Request setFreeMethodWeight(float $value)
 *
 * @method Mage_Shipping_Model_Rate_Request setOptionInsurance(boolean $value)
 * @method boolean getOptionInsurance()
 * @method Mage_Shipping_Model_Rate_Request setOptionHandling(float $flag)
 * @method float getOptionHandling()
 *
 * @method Mage_Shipping_Model_Rate_Request setConditionName(array $value)
 * @method Mage_Shipping_Model_Rate_Request setConditionName(string $value)
 * @method string getConditionName()
 * @method array getConditionName()
 *
 * @method Mage_Shipping_Model_Rate_Request setLimitCarrier(string $value)
 * @method string getLimitCarrier()
 * @method Mage_Shipping_Model_Rate_Request setLimitMethod(string $value)
 * @method string getLimitMethod()
 */
Sohel Rana
Sohel Rana
August 21, 2016 06:19 AM

Related Questions


Dropdown Dependency for Addresses

Updated March 03, 2016 01:04 AM


Creating Quote Address the right way

Updated June 23, 2017 16:09 PM

Free shipping above total amout 30+

Updated February 16, 2016 03:04 AM