0

I am trying to create a shipping rule in magento. In this rule I need some functionality like $50 per 3 products will add as shipping rule. If someone added 4 items to 6 items in cart, then the shipping charges should $100 ($50 for first 3 pair of items and other $50 for remain items).

But i am stuck and didn't found any extension or solution for this.

  • if 7 item then shipping cost 150??? – Gopal Patel Feb 25 '17 at 12:01
  • yes...exactly what i want... – Yudi Feb 25 '17 at 12:21
  • magento version ? – Gopal Patel Feb 25 '17 at 13:02
1

Magento 1

Follow this tutorial to create custom shipping method

in config.xml

<default>
        <carriers>
            <customshipping>
                <active>1</active>
                <model>customshipping/carrier_customshipping</model>
                <name>Custom Shipping</name>
                <title>Custom  Shipping </title>
                <description>50 Shipping cost per 3 item</description>
                <sort_order>1</sort_order>
            </customshipping>
        </carriers>
</default>

create shipping model class

<?php  
    class Stackexchange_Customshipping_Model_Carrier_Customshipping     
        extends Mage_Shipping_Model_Carrier_Abstract
        implements Mage_Shipping_Model_Carrier_Interface
    {  
        protected $_code = 'customshipping';  

        /** 
        * 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){  
            $result = Mage::getModel('shipping/rate_result');

             if ($request->getAllItems()) {
                $count=0;
                foreach ($request->getAllItems() as $item) {
                    $count+=$item->getQty();
                }
                $count=ceil($count/3);
                $method = Mage::getModel('shipping/rate_result_method');  
                $method->setCarrier($this->_code);  
                $method->setCarrierTitle($this->getConfigData('title'));
                $method->setMethod($this->_code);  
                $method->setMethodTitle($this->getConfigData('name'));
                $method->setPrice($count*50);
                $method->setCost($count*50);
                $result->append($method);  
            }
            else
            {
                $error = Mage::getModel('shipping/rate_result_error');
                $error->setCarrier($this->_code);
                $error->setCarrierTitle($this->getConfigData('name'));
                $error->setErrorMessage('Shipping Method is not available');
                $result->append($error);
            }
            return $result;
        }  

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

Created module for you.

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.