Magento Create Custom Shipping Method

shipping-mtd
In this blog post, we will see how to create a custom shipping method in magento.

Creating a custom shipping method is very easy, you just need to know all the useful functions to be used inside the shipping method class to put in various configuration options. We will see in this blog many different use cases and functions to use in shipping methods.
So let’s start of by creating the shipping method. I have used a module for this tutorial named Excellence_Ship. You can create your own module and change class names accordingly.
Attached is source code of the module shown in this blog
Module Name: Shipping Method Source


These are the primary areas where the shipping method shows up

  • Admin Magento Admin - Custom Shipping Method
  • Frontend Magento Custom Shipping Method Checkout Page

To achieve this there are 3 things required

  • config.xml entries
  • system.xml entries
  • Shipping Module
  • So lets start of with the steps.

    Step1

    First thing when creating a shipping method is to decide the code for the shipping method. In the current module i am using the code for shipping method as “excellence”. Next we will create the system.xml file for admin entries.

    <?xml version="1.0" encoding="UTF-8"?>
    <config>
    	<sections>
    		<carriers>
    			<groups>
    				<excellence translate="label" module="ship">
    					<label>Excellence Shipping Module</label>
    					<frontend_type>text</frontend_type>
    					<sort_order>99</sort_order>
    					<show_in_default>1</show_in_default>
    					<show_in_website>1</show_in_website>
    					<show_in_store>1</show_in_store>
    					<fields>
    						<active translate="label">
    							<label>Enabled</label>
    							<frontend_type>select</frontend_type>
    							<source_model>adminhtml/system_config_source_yesno</source_model>
    							<sort_order>1</sort_order>
    							<show_in_default>1</show_in_default>
    							<show_in_website>1</show_in_website>
    							<show_in_store>1</show_in_store>
    						</active>
    						<title translate="label">
    							<label>Title</label>
    							<frontend_type>text</frontend_type>
    							<sort_order>2</sort_order>
    							<show_in_default>1</show_in_default>
    							<show_in_website>1</show_in_website>
    							<show_in_store>1</show_in_store>
    						</title>
    						<name translate="label">
    							<label>Method Name</label>
    							<frontend_type>text</frontend_type>
    							<sort_order>2</sort_order>
    							<show_in_default>1</show_in_default>
    							<show_in_website>1</show_in_website>
    							<show_in_store>1</show_in_store>
    						</name>
    						<price translate="label">
    							<label>Price</label>
    							<frontend_type>text</frontend_type>
    							<sort_order>3</sort_order>
    							<show_in_default>1</show_in_default>
    							<show_in_website>1</show_in_website>
    							<show_in_store>0</show_in_store>
    						</price>
    						<specificerrmsg translate="label">
    							<label>Displayed Error Message</label>
    							<frontend_type>textarea</frontend_type>
    							<sort_order>4</sort_order>
    							<show_in_default>1</show_in_default>
    							<show_in_website>1</show_in_website>
    							<show_in_store>1</show_in_store>
    						</specificerrmsg>
    						<sallowspecific translate="label">
                                <label>Ship to Applicable Countries</label>
                                <frontend_type>select</frontend_type>
                                <sort_order>90</sort_order>
                                <frontend_class>shipping-applicable-country</frontend_class>
                                <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
                                <show_in_default>1</show_in_default>
                                <show_in_website>1</show_in_website>
                                <show_in_store>0</show_in_store>
                            </sallowspecific>
    						<specificcountry translate="label">
                                <label>Ship to Specific Countries</label>
                                <frontend_type>multiselect</frontend_type>
                                <sort_order>91</sort_order>
                                <source_model>adminhtml/system_config_source_country</source_model>
                                <show_in_default>1</show_in_default>
                                <show_in_website>1</show_in_website>
                                <show_in_store>0</show_in_store>
                                <can_be_empty>1</can_be_empty>
                            </specificcountry>
    					</fields>
    				</excellence>
    			</groups>
    		</carriers>
    	</sections>
    </config>
    

    So, let me explain this. first we always have to create our shipping method inside

    <sections>
    		<carriers>
    			<groups>
    

    As you can see the field have been created inside the ‘excellence’ tag which is our shipping method code. Next, we have created fields for active,title,name,price. There fields are required for every shipping method created. To know more details of system.xml entries please refer to this blog
    Next, i have included to more fields sallowspecific and specificcountry. This is required, when you want your shipping method to available for only few countries. To implement this restriction in the frontend (i.e suppose if user chooses India as shipping country our shipping doesnt show) we don’t have to do any more programming. Just included these two fields in the xml and country based restrictions start working automatically. Of course, we have to setup the country restriction in System Configuration in admin.
    Next, i have included specificerrmsg field. This field is used whenever there some error in our shipping method and we to show an error message to the user.

    Step2

    Next in our config.xml file of our module we add the below code directly inside the <config>

    <default>
    		<carriers>
    	      <excellence>
    	           <active>1</active>
    	           <model>ship/carrier_excellence</model>
    	           <title>Carrier Title</title>
    	           <name>Method Name</name>
    	           <price>5.00</price>
    	           <specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
    	        </excellence>
    	     </carriers>
           </default>
    

    As we know the <default> tag is used to assign default values to our system.xml fields created. So here we specify default values for active,title,name,price etc. The important field to notice here is the <model> which contains the path of our shipping model. This field is very important, or else the shipping method won’t show on frontend. After this step is over go to Admin -> System -> Configuration -> Shipping Methods and you should see your shipping method there with all the default values pre-filled.

    Magento Admin Custom Shipping Method

    Magento Admin Custom Shipping Method

    Step3

    Now all we need to do is to create our shipping model class. The model class name is Excellence.php and is created Model/Carrier folder.

    <?php
    class Excellence_Ship_Model_Carrier_Excellence extends Mage_Shipping_Model_Carrier_Abstract
    implements Mage_Shipping_Model_Carrier_Interface {
    	protected $_code = 'excellence';
    
    	public function collectRates(Mage_Shipping_Model_Rate_Request $request)
    	{
    		if (!Mage::getStoreConfig('carriers/'.$this->_code.'/active')) {
    			return false;
    		}
    		
    
    		$handling = Mage::getStoreConfig('carriers/'.$this->_code.'/handling');
    		$result = Mage::getModel('shipping/rate_result');
    		$show = true;
    		if($show){ // This if condition is just to demonstrate how to return success and error in shipping methods
    
    			$method = Mage::getModel('shipping/rate_result_method');
    			$method->setCarrier($this->_code);
    			$method->setMethod($this->_code);
    			$method->setCarrierTitle($this->getConfigData('title'));
    			$method->setMethodTitle($this->getConfigData('name'));
    			$method->setPrice($this->getConfigData('price'));
    			$method->setCost($this->getConfigData('price'));
    			$result->append($method);
    
    		}else{
    			$error = Mage::getModel('shipping/rate_result_error');
    			$error->setCarrier($this->_code);
    			$error->setCarrierTitle($this->getConfigData('name'));
    			$error->setErrorMessage($this->getConfigData('specificerrmsg'));
    			$result->append($error);
    		}
    		return $result;
    	}
    	public function getAllowedMethods()
    	{
    		return array('excellence'=>$this->getConfigData('name'));
    	}
    }
    

    The above code is for our shipping model. The code is very basic, let go line by line

    public function collectRates(Mage_Shipping_Model_Rate_Request $request)
    

    This is the function which we need to implement. This function is called by magento for all the shipping methods to find out the shipping rates.

    if (!Mage::getStoreConfig('carriers/'.$this->_code.'/active')) {
      return false;
    }
    

    This line simply checks if the shipping method is enabled from admin.

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

    here we create the result object, which is always returned from the shipping method collectRate function.

    $method = Mage::getModel('shipping/rate_result_method');
    $method->setCarrier($this->_code);
    $method->setMethod($this->_code);
    $method->setCarrierTitle($this->getConfigData('title'));
    $method->setMethodTitle($this->getConfigData('name'));
    $method->setPrice($this->getConfigData('price'));
    $method->setCost($this->getConfigData('price'));
    $result->append($method);
    

    This code is used to return the shipping price. The code is quite clear.

    $error = Mage::getModel('shipping/rate_result_error');
    $error->setCarrier($this->_code);
    $error->setCarrierTitle($this->getConfigData('name'));
    $error->setErrorMessage($this->getConfigData('specificerrmsg'));
    $result->append($error);
    

    The above code is used to return error message.

    After this model is created, the shipping method should be working properly. It will show up on the checkout page and cart page.

    Different Cases and Function to use inside shipping method

    All the function written below are to be implemented in the collectRates function only. I will write down function you can use to put your condition and calculate price, the price needs to be set in the result variable as shown above.
    Shipping Price is Based On Destination Country,State and Zip Code

    //Case1: Price Depends on Country,State and Pin Code
    		echo $destCountry = $request->getDestCountryId().': Dest Country<br/>';
    		echo $destRegion = $request->getDestRegionId().': Dest Region<br/>';
    		echo $destRegionCode = $request->getDestRegionCode().': Dest Region Code<br/>';
    		print_r($destStreet = $request->getDestStreet()); echo ': Dest Street<br/>';
    		echo $destCity = $request->getDestCity().': Dest City<br/>';
    		echo $destPostcode = $request->getDestPostcode().': Dest Postcode<br/>';
    		echo $country_id = $request->getCountryId().': Package Source Country ID<br/>';
    		echo $region_id = $request->getRegionId().': Package Source Region ID<br/>';
    		echo $city = $request->getCity().': Package Source City<br/>';
    		echo $postcode = $request->getPostcode().': Package Source Post Code<br/>';
    

    Use the above function to put conditions and set price based on your business logic.
    Shipping Price is based on total order cost or weight

    //Case2: Price Depends on Total Order Value or Weight
    		echo $packageValue = $request->getPackageValue().': Dest Package Value<br/>';
    		echo $packageValueDiscout = $request->getPackageValueWithDiscount().': Dest Package Value After Discount<br/>';
    		echo $packageWeight = $request->getPackageWeight().': Package Weight<br/>';
    		echo $packageQty = $request->getPackageQty().': Package Quantity <br/>';
    		echo $packageCurrency = $request->getPackageCurrency().': Package Currency <br/>';
    

    Shipping Price Depends on Dimensions

    //Case3: Price Depends on order dimensions
    		echo $packageheight = $request->getPackageHeight() .': Package height <br/>';
    		echo $request->getPackageWeight().': Package Width <br/>';
    		echo $request->getPackageDepth().': Package Depth <br/>';
    

    Shipping Price Depends on Product Attributes
    As example, suppose we want to have shipping price different for each product. So for this, we create a product attribute called ‘shipping_price’ and on each product edit page in admin we assign the shipping price of the product. Now in our shipping method we need to access this shipping_price again and show the total shipping cost.

    //Case4: Price based on product attribute
    		if ($request->getAllItems()) {
    			foreach ($request->getAllItems() as $item) {
    				if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
    					continue;
    				}
    
    				if ($item->getHasChildren() && $item->isShipSeparately()) {
    					foreach ($item->getChildren() as $child) {
    						if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
    							$product_id = $child->getProductId();
    							$productObj = Mage::getModel('catalog/product')->load($product_id);
    							$ship_price = $productObj->getData('shipping_price'); //our shipping attribute code
    							$price += (float)$ship_price;
    						}
    					}
    				} else {
    					$product_id = $item->getProductId();
    					$productObj = Mage::getModel('catalog/product')->load($product_id);
    					$ship_price = $productObj->getData('shipping_price'); //our shipping attribute code
    					$price += (float)$ship_price;
    				}
    			}
    		}
    

    Shipping Price Based on Configurable Product Option Selected
    Example, suppose on our website we have configurable product with Size as the drop down attribute. If user selected selects Size as Small the shipping cost is 15$, Medium is 20$ and Large is 25$.

    //Case5: Shipping option based configurable product option
    		if ($request->getAllItems()) {
    			foreach ($request->getAllItems() as $item) {
    				if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
    					continue;
    				}
    				if ($item->getHasChildren() && $item->isShipSeparately()) {
    					foreach ($item->getChildren() as $child) {
    						if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
    							$product_id = $child->getProductId();
    							$value = $item->getOptionByCode('info_buyRequest')->getValue();
    							$params = unserialize($value);
    							$attributeObj = Mage::getModel('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY,'shirt_size'); // our configurable attribute
    							$attribute_id = $attributeObj->getAttributeId();
    							$attribute_selected = $params['super_attribute'][$attribute_id];
    
    							$label = '';
    							foreach($attributeObj->getSource()->getAllOptions(false) as $option){
    								if($option['value'] == $attribute_selected){
    									$label =  $option['label'];
    								}
    							}
    							if($label = 'Small'){
    								$price += 15;
    							} else if($label = 'Medium'){
    								$price += 20;
    							} else if($label = 'Large'){
    								$price += 22;
    							}
    						}
    					}
    				} else {
    					$product_id = $item->getProductId();
    					$value = $item->getOptionByCode('info_buyRequest')->getValue();
    					$params = unserialize($value);
    					$attributeObj = Mage::getModel('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY,'shirt_size'); // our configurable attribute
    					$attribute_id = $attributeObj->getAttributeId();
    					$attribute_selected = $params['super_attribute'][$attribute_id];
    
    					$label = '';
    					foreach($attributeObj->getSource()->getAllOptions(false) as $option){
    						if($option['value'] == $attribute_selected){
    							$label =  $option['label'];
    						}
    					}
    					if($label = 'Small'){
    						$price += 15;
    					} else if($label = 'Medium'){
    						$price += 20;
    					} else if($label = 'Large'){
    						$price += 22;
    					}
    				}
    			}
    		}
    

    Shipping Price based on Product Custom Options
    Example, suppose we have custom drop down options created for a simple product. The Custom Option is Delivery and values are Express,Normal. If user selects Express when adding product, the shipping cost is 50$ and for normal the cost is 10$.

    //Case6: Price based on custom options
    		if ($request->getAllItems()) {
    			foreach ($request->getAllItems() as $item) {
    				if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
    					continue;
    				}
    				if ($item->getHasChildren() && $item->isShipSeparately()) {
    					foreach ($item->getChildren() as $child) {
    						if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
    							$product_id = $child->getProductId();
    							$value = $item->getOptionByCode('info_buyRequest')->getValue();
    							$params = unserialize($value);
    							$options_select = $params['options'];
    
    							$product = Mage::getModel('catalog/product')->load($product_id);
    							$options = $product->getOptions();
    							foreach ($options as $option) {
    								if ($option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT) {
    									$option_id =  $option->getId();
    									foreach ($option->getValues() as $value) {
    										if($value->getId() == $options_select[$option_id]){
    											if($value->getTitle() == 'Express'){
    												$price += 50;
    											}else if($value->getTitle() == 'Normal'){
    												$price += 10;
    											}
    										}
    
    									}
    								}
    							}
    						}
    					}
    				} else {
    					$product_id = $item->getProductId();
    					$value = $item->getOptionByCode('info_buyRequest')->getValue();
    					$params = unserialize($value);
    					$options_select = $params['options'];
    
    					$product = Mage::getModel('catalog/product')->load($product_id);
    					$options = $product->getOptions();
    					foreach ($options as $option) {
    						if ($option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT) {
    							$option_id =  $option->getId();
    							foreach ($option->getValues() as $value) {
    								if($value->getId() == $options_select[$option_id]){
    									if($value->getTitle() == 'Express'){
    										$price += 50;
    									}else if($value->getTitle() == 'Normal'){
    										$price += 10;
    									}
    								}
    
    							}
    						}
    					}
    				}
    			}
    		}
    
    Hopefully i have added all the information regarding shipping method. If there are any more scenarios on which you want code for shipping method let me know i will add it.
  • http://pulse.yahoo.com/_KSPHEWLB24HSXOSJVZ6C7W7PU4 Rt

    Hello Manish, awesome post like your other post, this is what i’ve been looking for, very informative, im learning so much from this blog. Please continue sharing your knowledge, im sure many other newbies like me is gaining lot of knowledge here.

    Request: custom payment method ( Eg:- with an external payment gateway … just the functionality of interacting with external web service for processing payment and returning success or failure )

    Thanks.

    • Manish Prakash

      Thanks :)

      Payment Method is coming soon, after i finish the checkout customization series 

  • Gerry

    Does this work on 1.6?

    • Manish Prakash

      Yes it does. Have tested it on 1.6 version only

  • http://twitter.com/pantzan Pantelis Zanias

    hello again..:)

    I want to have a custom field in shipping method that when you choice it will appear a dropdown box with all stores which you can select to pick up your product from this store! is that possible with this customization?

    Thanks! :)

    • Manish Prakash

      Ok, yes this is possible. Basically, you want to have form fields in your shipping method.

      I forgot to include this tutorial in this blog. i will have to post another blog for this.

      • http://twitter.com/pantzan Pantelis Zanias

        ok..! i will be waiting for your post..
        i need it too many days now! :)

        Thanks,
         Zanias Pantelis

        • Jimmy

          I would like to request for this feature as well… ^.^

          • Manish Prakash

            I will try to publish the blog in this week.

          • xavi

            me too!!!

      • Algeriano

        I’m very interested in this too !!

        I need the customers to enter a value during checkout which would be incorporated into the total shipping price

        Thank you :)

  • Fabian

    Thank you for this great Blog!

    After following your example i end up with this error (Magento 1.6.0):

    Fatal error: Class ‘Mage_Ship_Helper_Data’ …/app/Mage.php on line 516

    Thank you in advance.

    Best Regards,

    Fabian

    • Manish Prakash

      Did you download the entire module source and upload it to your magento? because this class Mage_Ship_Helper_Data is there in the module source code. 

      Thanks

      • Yaboosa

        Hello Manish, I had the same error as Fabian, however I copied the entire module source.
        Then, I tried to find this class in your module without success. Thank you for your help

        • Manish Prakash

          Let me test it and get back to you soon.

        • Manish Prakash

          I uploaded this module to a fresh magneto installation and it worked fine.

          Can you tell when you get this error, that is which URL you open to get this error?
          Also this should be the location of the Helper file appcodelocalExcellenceShipHelperData.php

          • Yaboosa

            Thank you Manish, in fact it was a problem with the location path.

          • Manish Prakash

            What was the problem? Some problem in the module?

          • G Mencarelli

            Hallo thanks for this post.
            I’m having same  issue when I go to Config->Shipment method
            I get the Class ‘Mage_Ship_Helper_Data’ not found in …
            In the module we have a Excellence_Ship_Helper …
            maybe something missing in xml files ?

            Let’s try to finish this job !

          • G Mencarelli

            Sorry for my previous post ti was an error from my side,
            just uploadinf the ship metho wit no changes works perfectly…

  • Fabian

    Thank you for your great Blog.
    Your post helped me a lot !
    Following you on Twitter is a good idea ;)

    Fabian

    • Manish Prakash

      Thanks J

  • Yogendra M

    I have added it on brand new magento 1.6 magento installation, but on frontend carrier price is appearing $0 instead of the default value set in admin configuration. any clue?

    • Manish Prakash

      Can you send me a screenshot of your system->configuration shipping method box?

    • http://twitter.com/pmit_jelle Jelle Janssens

      This is because in Model/Carrier/Excellence.php there is a line directly under the line that gets the config data. This line is :  $price = 0;  ,, you can find this at rule number 13 in this file, comment it out, so it will not override the price ;)

      Edit: added line number

  • Igor Bobriakov

    Thanks! Very clear and handy article!

  • Alex Mercenary

    Hi Manish.

    I am having the same problem as a couple of the others on here where when i move the files you have packed to the same locations in my current magento 1.6.1.0 directory when i get to the shipping methods part of the checkout a blank page gets returned same on the back end.

    I have just tried to use them on a fresh install of 1.6.1.0 and it works fine. I can’t find anything wrong or different though…

    Any help would be great.

    Thanksss

    • Manish Prakash

      How exactly have you uploaded the module in magento?

      is it possible for you send me ftp access to your store?

      • Alex Mercenary

        i have been doing it on my local server which is exact replica of the live version. but i can give you ftp to live if you would like to try to install yourself? can i have private message email or something similar to send details?

        what seems to be happening is when i click continue from the billing and shipping step on onestep checkout the url is going to checkout/cart/

        Thanks,

        Alex

  • Asmara_azriel

    How do i override the shipping method block? Because i want in my shipping method section to add 2 options, ship by air and ship by land.

    Onchange of the method, it will automatically compute its rate.

    Any idea how? I have my module running in local but i set it to ship by land  in my model. I want the  options to be dynamic. So i need to add options in available.phtml. I want to  know how to override it.

    Thank you

  • http://twitter.com/mosheshperling Moshe Shperling

    hey i have created a shipping module using your example but i canot
    apply a cart rule on it. Could you tell please what could be the
    problem?

    • Manish Prakash

      It shows up for me in magento version 1.6 when creating Shopping Cart Price Rule. are you sure you created the method properly.

  • Manish Prakash

    Yes this possible. Please understand the blog in detail, I am not able to provide you with exact code for doing the above. But if you’re a magento programmer you should be able to figure this out based on the blog.

  • Sohail

    Nice module, however where would i Need to change in case I want the shipping price to be as an attribute with each product. Every product will have its own shipping price. And the shipping cost of the basket will be the highest shipping cost from the shipping costs of products in basket.

    • Manish Prakash

      Please read the section where I have mentioned how to access product attribute values in shipping method. You can access the attribute value using it as shipping price.

  • Hedge

    Thank you very much Manish! This is exactly what I was looking for.
    It is working great for me.

    One question if I may, I am using case #6 with custom options, but when I update the quantity on the cart page, the shipping total does not increase. I assume it’s not checking to see if there are more than one of each product, only counting each product.
    Any thoughts on this?
    Thanks again.

  • Pauvau

    Excellent module and works like a charm.
    Can anyone provide instructions how to duplicate this module?

    I would like to have several simple shipping modules like this one in my magento store but can’t seem to get my duplication to work. When i try to duplicate this module, my new module and excellence module won’t show in frontend at the same time.

  • Edward

    Excellent module!
    If I should rename the module name, what need I change in the xml files?
    Example: I change the modul name Ship -> Localship
    Change I the tags too? Example: -> ?
    And the file names?
    ship.xml
    ->
    localship.xml

    ship_mysql4
    ->
    localship_mysql4
    ???

  • http://twitter.com/Jigafur zloypk

    Crystal module !!! Really thanks for article !

  • http://twitter.com/Jigafur zloypk

    I downloaded the source file, copy and past it to my magento directory, then i see this module in backend and in frontend, but if i check shipping method in my order on frontend – magento drop this “please specify shipping method magento” 

    Help me please …

    • Manish Prakash

      Which magento version are you using

      • http://twitter.com/Jigafur zloypk

        Problem was with “Store pickup” module … Ill delete it and all ok …   magento version 1.6.1

  • vinotha

    Hi 
        I have multi store setup. Created  a shipping module based on the product weight using your code.
    Its working fine except AUD,GBP,CAD and some other currencies. In both site if selected the base currency of the store its working well. if selected other currency it shows the error message like “sorry, there is no shipping method is availabe at this time”.
        Thanks in advance.

  • vinotha

    Hi 
        I have a multi website setup. Created  a shipping module based on the product weight using your code.
    Its working fine except AUD,GBP,CAD and some other currencies. In both site if i selected the base currency of the website its working well. if i selected other currency it shows the error message like “sorry, there is no shipping method is availabe at this time”.
        Thanks in advance.

  • vinotha

    Hi 
        I have a multi website setup. Created  a shipping module based on the product weight using your code.
    Its working fine except AUD,GBP,CAD and some other currencies. In both site if i selected the base currency of the website its working well. if i selected other currency it shows the error message like “sorry, there is no shipping method is availabe at this time”.
        Thanks in advance.

  • http://www.facebook.com/people/Laercio-Silva/100000204721277 Laercio Silva

    Hi Manish! 
    After making some minor modifications to the module and test on localhost, the following error appears in the store server: Fatal error: Call to a member function setId() on a non-object in /app/code/core/Mage/Shipping/Model/Config.php on line 126. 
    Could you help me? I checked and the problem is in $ carrier-> setId ($ code) ->setStore ($ store); Apparently not passing the variable $ code. In the module is $ _codeperfectly named

    • Pallavi

      Hi,
      I am getting same issue. Did you get any solution to this problem??

      -Pallavi

      • Rupesh Yadav

        if still you have that problem then just remove sales/carrier_excellence
        from config.xml

        • Mohammad Faisal

          Perfect. Got it working right after removing it.

      • Mohammad Faisal

        either remove from in your config.xml

        or change to
        Excellence_Ship_Model_Carrier_Excellence

  • Fadzly Othman

    I had the same problem. Your config.xml must include the section, for which it must point to your module’s helper class. And make sure all your tags in config.xml are properly ended. I missed a character in a closing tag and the error showed up.

  • Malcolm Edwards

    Excellent module and works great.

    The module works on a fixed amount. How hard would it be to make the shipping a percentage value of the product price?

  • http://www.facebook.com/diybrewing Michael Bernier

    When I installed this module on 1.7.0.2 CE whenever any shipping module is picked it will not update the onepage checkout. I just uploaded the zip file. Once I deleted the module xml file it worked fine. I would love to use this but it is kind of an important thing to check out. Oh one other thing this was for only new customers not existing customers. Any help would be grateful. Thanks

    • Ivo Nijenhuis

      did you get this to work? I’m having the same issue and can’t get this fixt

  • http://www.facebook.com/ankita.priyadarshini Ankita Priyadarshini

    i want to restrict cash on delivery for some pincodes only.Please tell me .how to do this.
    which function is used for pincodes in magento

  • classical

    Hello!
    In system.xml, I add follow to create 2 fields:

    Title
    text
    2
    1
    1
    1

    Postals Name
    text
    3
    1
    1
    1

    Postal Ship Price
    text
    4
    1
    1
    0

    Parcel Name
    text
    5
    1
    1
    1

    Parcel Ship Price
    text
    6
    1
    1
    0

    And in pickup.php in Model/Carrier, I add follow:

    $totals = Mage::getSingleton(‘checkout/cart’)->getQuote()->getTotals();
    $totalPrice = $totals["subtotal"]->getValue();
    if ($totalPrice >= 4000) {
    $method = Mage::getModel(‘shipping/rate_result_method’);
    $method->setCarrier($this->_code);
    $method->setMethod(‘atmarkcafe_customrate_two’);
    $method->setCarrierTitle($this->getConfigData(‘title’));
    $method->setMethodTitle($this->getConfigData(‘postal_name’));
    $method->setPrice(0);
    $method->setCost(2);
    $result->append($method);

    $method = Mage::getModel(‘shipping/rate_result_method’);
    $method->setCarrier($this->_code);
    $method->setMethod(‘atmarkcafe_customrate_three’);
    $method->setCarrierTitle($this->getConfigData(‘title’));
    $method->setMethodTitle($this->getConfigData(‘parcel_name’));
    $method->setPrice(0);
    $method->setCost(2);
    $result->append($method);

    } else if ($totalPrice = 2000) {
    $method = Mage::getModel(‘shipping/rate_result_method’);
    $method->setCarrier($this->_code);
    $method->setMethod(‘atmarkcafe_customrate_two’);
    $method->setCarrierTitle($this->getConfigData(‘title’));
    $method->setMethodTitle($this->getConfigData(‘postal_name’));
    $method->setPrice(0);
    $method->setCost(2);
    $result->append($method);

    $method = Mage::getModel(‘shipping/rate_result_method’);
    $method->setCarrier($this->_code);
    $method->setMethod(‘atmarkcafe_customrate_three’);
    $method->setCarrierTitle($this->getConfigData(‘title’));
    $method->setMethodTitle($this->getConfigData(‘parcel_name’));
    $method->setPrice($this->getConfigData(‘parcel_price’));
    $method->setCost($this->getConfigData(‘parcel_price’));
    //$method->setPrice(500);
    //$method->setCost(2);
    $result->append($method);

    Mage::log(‘Comehere price: ‘.$totalPrice);

    }

    It’s working good in one page check out.
    But in multishipping it count on total card items. I want it count total base on each address and give correct rate pice. How to do that?
    (Sorry, My E not well :( )

  • Andrew_Felipe

    On part you tell about [Depends on Dimensions] you put echo “$request->getPackageWeight().': Package Width ‘;” i think this would be “$request->getPackageWidth()”. But thanks for this content, really helpfull.

  • Jagesh

    Hi
    I want to change shipping price dynamically on frontend to UPS ground rates based on the weight .
    I created a custom shipping method and i put price is 500 and handing fee 10%.
    but now i want to change this price into ups rates on shopping cart and checkout page magento.
    for eg if ups ground rates is $10 for weight 30.
    if i select weight 30 product then the shipping method should show $10 instead of 500 and also i want to calculate 10% from $10 to add handling fee.
    Please advice

  • sachin

    when i enable Shipping Price is Based On Destination Country,State and Zip Code it shows error.

    how can i specify price

  • Gabriela Davila

    And if the shipping depends on Weight, Destination and Price?
    I always see two of this items, no more than that.

  • Mostafa

    Hello,
    how did you deal the condition with category?

  • rajan

    any buddy help me i want display Handling Fee in my shopping cart

  • Remi

    Hi,

    I have created a shipping module like this with some changes, instead of taking the price from field, we used to take the price from a database(created for specific region with postcode). So i need to update the database using a xls file. Can you please tell me how we can implement an export and import functionality of xls file to update the database ??

    Thanks,

    Remi

  • http://www.facebook.com/lemarz12 Ramil Horca Gonzales

    Hi.. this is good tutorials..What if i add text field on the shipping method and store the value….

  • Nitin Pant

    I am trying to calculate shipping price based on dimensions, post code and type of parcel(regular/express). I am able to calculate that using AUSPOST api but the problem is to save the shipping rate outside of the collectRates method in magento. If I do this…

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

    $method = Mage::getModel(‘shipping/rate_result_method’);
    $method->setCarrier(“excellence_excellence”);
    $method->setMethod(“excellence_excellence”);
    $method->setCarrierTitle(“”);
    $method->setMethodTitle(“”);
    $method->setPrice($myValue);
    $method->setCost($myValue);
    $result->append($method);

    It does not work because the $result has to be saved in the quote. Can anyone help me on this?

  • Nitin Pant

    Hi Manish,

    I am trying to calculate shipping price based on dimensions,
    post code and type of parcel(regular/express). I am able to calculate
    that using AUSPOST api but the problem is to save the shipping rate
    outside of the collectRates method in magento. If I do this…

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

    $method = Mage::getModel(‘shipping/rate_result_method’);
    $method->setCarrier(“excellence_excellence”);
    $method->setMethod(“excellence_excellence”);
    $method->setCarrierTitle(“”);
    $method->setMethodTitle(“”);
    $method->setPrice($myValue);
    $method->setCost($myValue);
    $result->append($method);

    It does not work because the $result has to be saved in the quote. Can you please help me on this?

  • Nitin Pant

    What if the shipping price is based on user selection of shipping type
    i.e. Parcel Post/Express/Gold/Platinum , on the OPC page itself. How do I
    set the shipping price in that case. I have modified
    /template/checkout/onepage/shipping_method/available.phtml where I can
    fetch the user input during OPC and Iam able to pass the value to my
    custom module’s collectRates method too, but it is not saving the
    shipping rate. Instead it takes the value from the admin setting,
    always!

    Please see my Question asked earlier. Help or a little direction would be much appriciated.

  • Manish Prakash

    Hi,

    By adding

    Sort Order
    text
    100
    1
    1
    0

    in system.xml you can set sort order for shipping method.

  • Gus Smith

    Hi, I copied this code and it is working!

    I made the following test. I count all items and use that as shipping price:

    if ($request->getAllItems()) {
    $cnt = 0;

    foreach ($request->getAllItems() as $item) {
    $cnt++;
    $method->setPrice($cnt);
    }
    }

    I think this calculates the shipping price only the 1st time.
    When I update the pieces in the cart and update the cart the old piece count is shown as the shipping price. How do I recalculate automatically the shipping price again?

    e.g. I have 4 pieces in my cart. Shipping is shown as 4.
    When I update to 2 pieces, shipping still remains 4.

    Gus

    • Gus Smith

      My mistake, it is recalculating!

      I needed to test it like this:

      foreach ($request->getAllItems() as $item) {
      $cnt += $item->getQty();
      $method->setPrice($cnt);
      }

      Total shipping is now updated.

  • Gus Smith

    Hi, I need the exact same thing! Every item can come from a different vendor and from a different warehouse in a different country.

    I think it is very much doable with this module. I have already implemented vendor attribute in our products and a seperate weight matrix per vendor for domestic and international deliveries (for simplicity our model has different costs for each continent). In the product there is also an extra shipping cost possible for each continent and domestic.

    So based on customer delivery address, total weight per vendor, it should be fairly easy to calculate total shipping.

  • Gus Smith

    How do you set the tax percentage for th shipping costs?

  • Varun Jyothi

    Hai Manish,

    I have developed the custom shipping method in my module. Also I have created a table called “postal_codes” for saving the postal codes. And in my module I have to display my custom shipping method only if the postal code from “Shipping information” should match the postal code from my table “postal_codes”. Where should I can do the checking?

  • Luciano

    Hi Manish, I have a question, is it possible to call a third party API in the carrier who receives as parameters customer’s zip code,weight and volume. And it returns a json with the shipping price.

    I have a class that handles the api (his connection and configuration), and I can’t calculate the shipping price (said in a better way, get the result from the api. outside from magento. it works fine), its like the checkout is crashing, when it have to go on, stays there in the billiing address.

    can you help me please?

    All The Best !.

    Luciano

    pd: im running Magento 1.7.0.2. excuse my limited english

  • Fahad Adeel Qazi

    Hi Manish!

    I want to add product search widget on my shipping module. Can you guide me how i can add that widget on admin side of my shipping module. Haven’t found any clue yet.

    Thanks

  • Nayan Baraiya

    Hello,
    I have used your custom shipping method module.
    I would have to develop a shipping method module for third party carrier.
    For that i have used third party API to get quotes. there are many carriers available for shipment.
    now in your module we can set only one shipping method and its price in Model/Carrier/Excellence.php [public function collectRates() ]. where we can set only method so my question is how can set many shipping methods in this function.
    can you please guide me as soon as possible.
    Thanks in advance.

  • ayul

    i want to add text under each shipping option. for example when user will choose the “pick up” option under that option will open a text from where and in what time

  • monika choudhary

    Hi,
    i am
    not able to change the price form admin panel.always showing 0 price on frontend.

  • arthur F

    Hi Manish! I installed module . the”ship setting”and”ship methed”disappeared.would you please help me!thanks a lot!

  • Tommy

    How do you add custom properties to the result method? So that we can create a more custom gui in the front end?

  • Bella Paris

    does anyone know how to add a handling time to shipping in magento?

  • Navin

    Hi Manish,
    When i add the shipping method with some price it still displays $0.00
    Can you please help me out with this?

    • Navin

      Looked at the below discussion and got it sorted.