I created a module that calculates the delivery price according to the price of the item and it works well. However promotions (Example: Free Shipping by categories or number of items) and discounts are not applied in my custom shipping method (module).

How can I make the promotions are applied in my custom shipping method?

PS: The promotions are active and work in other shipping methods default.

This is my Model Class:

class Workspace_Transportadora_Model_Carrier_Transportadoracode     
    extends Mage_Shipping_Model_Carrier_Abstract
    implements Mage_Shipping_Model_Carrier_Interface
    protected $_code = 'transportadoracode';

    * Collect rates for this shipping method based on information in $request 
    * @param Mage_Shipping_Model_Rate_Request $data 
    * @return Mage_Shipping_Model_Rate_Result 
    public function collectRates(Mage_Shipping_Model_Rate_Request $request){
        if(!Mage::getStoreConfig('carriers/transportadoracode/active')) {
            return false;

        $result = Mage::getModel('shipping/rate_result');

        $shippingPrice = $this->resultadoValor();

        $method = Mage::getModel('shipping/rate_result_method');  

        $dias = Mage::registry('prazoentrega');
        $method->setMethodTitle($this->getConfigData('name') . ' - Em média '. ($dias ? $dias : $this->getConfigData('diasoff')) .' dias' );

        return $result;  

     * Get allowed shipping methods
     * @return array
    public function getAllowedMethods()
        return array($this->_code=>$this->getConfigData('name'));

    protected function resultadoValor()
        return (($this->getConfigData('porcent')/100) * $this->geraValor()) + $this->getConfigData('adicional');

    protected function geraValor()
        $totals = Mage::getSingleton('checkout/cart')->getQuote()->getTotals();
        $subtotal = $totals["subtotal"]->getValue();

        return $subtotal;

To apply promotions and free shipping you need to specify the setFreeShipping(true) on the item and the freeMethodWeight needs to be 0 for applicable items:


And in your rate request object you need to set the item's weight to zero:

$request = Mage::getModel('shipping/rate_request');
| improve this answer | |
  • So I need use setFreeShipping(true) for all items im my quote? I will try and report here. Thanks – Denis Spalenza Apr 24 '13 at 13:16
  • If the promotion is applicable, that is. – philwinkle Apr 24 '13 at 13:28
  • I got it, but I append this method to do it: $this->_updateFreeMethodQuote($request); Thank you. – Denis Spalenza Apr 24 '13 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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