Question

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');  
        $method->setCarrier($this->_code);  
        $method->setCarrierTitle($this->getConfigData('title'));
        $method->setMethod($this->_code);

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

        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;
    }
}
Was it helpful?

Solution

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:

$item->setFreeShipping(true);

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

$request = Mage::getModel('shipping/rate_request');
$request->setFreeMethodWeight(0);
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top