• blog
  • FAQ's
  • Home
  • company
  • services
    • Hire Dedicated Resource
      • Hire PHP Programmer
      • Hire Android Developer
      • Hire I-phone Developer
      • Hire I-pad Developer
      • Hire Open Source Developer
      • Hire Web Designer
    • Content Management System
      • Wordpress Development
      • Joomla Development
      • Drupal Development
      • Modx
    • E-commerce Solution
      • Magento Development
      • Zen-cart Development
      • Os-Commerce Development
      • Shopping Cart Development
      • Custom Shopping Cart
      • Ecommerce Web Design
      • Prestashop
      • X-Cart
      • OpenCart
      • Cart to Cart migration
    • PHP Frameworks
      • Codeignator
      • YIi
      • Zend Framework
      • Cakephp
      • Smarty
    • Mobile Apps Development
      • Android Development
      • Iphone Development
      • Ipad Development
      • Phone Gap Development
    • Multimedia Solutions
      • Logo Design
      • Responsive Design
      • Banner Design
      • JPG to HTML
      • AI to HTML
      • Video Creation
      • Facebook Fan
      • Twitter Fan
      • eBay Store Design
    • PHP/ MYSQL Development
      • PHP
      • MVC
      • Sphinx Search Algorithm
      • Hadoop
    • Packages
      • Ecommerce Packages
      • CMS Packages
  • Portfolio
  • Components
  • contact

Blog

Home > Web Development > create a shipping Method Module In Magento
03
Sep
  • 0
Tags:
shipping Method Module
create a shipping Method Module In Magento
by Harshal Shah

Shipping Method ModuleMagento is one of the best and well-to-do e-commerce platforms where you can find quite a lot of shipping methods. On the other hand, when you are having big e-commerce sites you may need to build up your own custom shipping methods.

Generating a custom shipping method is not so difficult; you just have to get all the necessary information regarding various functions that have to be use inside the shipping method class to put in various configuration selections.

Every shipping method can be prepared as separate module but if some methods could be used together or have same functionality than it can be combined in the same module.

Make sure that app/code/local is in PHP‘s include_path. For doing this, you need to carry out the following code:

<?php echo get_include_path();?>

Be certain you place this code anywhere after Magento was loaded.
Configuration:

You need to form app/code/local/YourCompany/NewModule/etc/config.xml:
<?xml version=”1.0″?>
<config>
<modules>
<!– declare module’s version information –>
<YourCompany_NewModule>
<!– this version number will be used for database upgrades –>
<version>0.1.0</version>
</YourCompany_NewModule>
</modules>
<global>
<!– declare model group for new module –>
<models>
<!– model group alias to be used in Mage::getModel() –>
<newmodule>
<!– base class name for the model group –>
<class>YourCompany_NewModule_Model</class>
</newmodule>
</models>
<!– declare resource setup for new module –>
<resources>
<!– resource identifier –>
<newmodule_setup>
<!– specify that this resource is a setup resource and used for upgrades –>
<setup>
<!– which module to look for install/upgrade files in –>
<module>YourCompany_NewModule</module>
</setup>
<!– specify database connection for this resource –>
<connection>
<!– do not create new connection, use predefined core setup connection –>
<use>core_setup</use>
</connection>
</newmodule_setup>
</resources>
</global>
</config>

Now, create app/etc/modules/YourCompany_NewModule.xml:

<config>
<!– … –>
<modules>
<!– … –>
<!– declare YourCompany_NewModule module –>
<YourCompany_NewModule>
<active>true</active>
<codePool>local</codePool>
</YourCompany_NewModule>
<!– … –>
</modules>
<!– … –>
</config>

Now, create app/code/local/YourCompany/NewModule/Model/Carrier/ShippingMethod.php:

<?php

/**
* Our test shipping method module adapter
*/
class YourCompany_NewModule_Model_Carrier_ShippingMethod extends Mage_Shipping_Model_Carrier_Abstract
{
/**
* unique internal shipping method identifier
*
* @var string [a-z0-9_]
*/
protected $_code = ‘newmodule’;
/**
* 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)
{
// skip if not enabled
if (!Mage::getStoreConfig(‘carriers/’.$this->_code.’/active’)) {
return false;
}
/**
* here we are retrieving shipping rates from external service
* or using internal logic to calculate the rate from $request
* you can see an example in Mage_Usa_Model_Shipping_Carrier_Ups::setRequest()
*/
// get necessary configuration values
$handling = Mage::getStoreConfig(‘carriers/’.$this->_code.’/handling’);
// this object will be returned as result of this method
// containing all the shipping rates of this method
$result = Mage::getModel(‘shipping/rate_result’);
// $response is an array that we have
foreach ($response as $rMethod) {
// create new instance of method rate
$method = Mage::getModel(‘shipping/rate_result_method’);
// record carrier information
$method->setCarrier($this->_code);
$method->setCarrierTitle(Mage::getStoreConfig(‘carriers/’.$this->_code.’/title’));
// record method information
$method->setMethod($rMethod['code']);
$method->setMethodTitle($rMethod['title']);
// rate cost is optional property to record how much it costs to vendor to ship
$method->setCost($rMethod['amount']);
// in our example handling is fixed amount that is added to cost
// to receive price the customer will pay for shipping method.
// it could be as well percentage:
/// $method->setPrice($rMethod['amount']*$handling/100);
$method->setPrice($rMethod['amount']+$handling);
// add this rate to the result
$result->append($method);
}
return $result;
}
/**
* This method is used when viewing / listing Shipping Methods with Codes programmatically
*/
public function getAllowedMethods() {
return array($this->_code => $this->getConfigData(‘name’));
}
}

Now you need to facilitate your new shipping method in admin panel (System->Configuration->Shipping Methods).

About the author

Harshal Shah Harshal Shah : I am co-founder of XHTMLJunkies. We are specialized in Database Development, Web Design, Content Management Solutions and Website Development. We have team of experts and professionals who willing to work with new technologies to fulfill all your requirements. You can follow me at Google+

  • More at  
  • logo image
Add a comment
+

Your email address will not be published. Required fields are marked *

Name*
Email*
Website
Comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

Our Services

  • Web Development
    • Wordpress Development
    • Joomla Development
    • Drupal Development
    • Magento Development
    • Zen-cart Development
    • Os-Commerce Development
    • Magento Theme Development
    • Wordpress Components
    • Joomla Components
    • Drupal Components
    • Magento Components
    • Zen Cart Components
    • Zend Framework
    • Modx
    • Prestashop
    • PHP
    • X-Cart
    • Magento Extension Development
    • OpenCart
    • Codeignator
    • Yii
    • Cakephp
    • Smarty
    • PhoneGap Development
    • MVC
    • Ecommerce Packages
    • Cart to Cart migration
    • Sphinx Search Algorithm
    • Hadoop
    • CMS Packages
  • Web Designing
    • Hire Web Designer
    • Logo Design
    • Banner Design
    • JPG to HTML
    • AI to HTML
    • eBay Store Design
    • Responsive Design
  • Mobile Apps
    • Android Development
    • Iphone Development
    • Ipad Development
  • Conversion Services
    • PSD To XHTML
    • PSD To Wordpress
    • PSD To Joomla
    • PSD To Drupal
    • PSD To Magento
    • PSD To osCommerce
    • PSD To ZenCart
    • PSD To Email
    • PSD to HTML5
Categories
  • Wordpress plugin
    (6)
  • Web Development
    (26)
  • Web Designing
    (3)
  • Mobile Application
    (12)
  • Conversion Services
    (5)
  • Popular
  • Recent
A WordPress Plugin is a program and this program...
518 days ago
HTML means HyperText Markup Language. This markup language is...
560 days ago
Magento is an open source based e-commerce web application....
491 days ago
WordPress is an open source blogging tool. WordPress designing...
492 days ago
HTML is useful to create a documents on the...
552 days ago
Have you ever thought that free plugins...
1 day ago
We live in a fast-paced world. And...
6 days ago
The new version of I-gallery extension has...
10 days ago
Magento provides customers with first class online...
12 days ago
Once upon a time, the software development...
14 days ago
Archives
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • January 2012
  • December 2011
  • November 2011
Tweets
  • about 15847 days ago
Tag Cloud
  • AppStore
  • AppStore Links
  • configure magento error page
  • Custom Option Swatch
  • FishPig
  • Magento
  • Magento Customer Group
  • Magento Database
  • Magento Database Repair Tool
  • Magento REST API
  • Sharing Buttons
  • shipping Method Module
  • Social Sharing ROI
  • Stella
  • Stella wordpress plugin
  • WordPress
  • WordPress Integration
  • Wordpress plugin
  • WordPress Shortcodes
 

Conversion Services

  • PSD To XHTML
  • PSD to HTML5
  • PSD To Email
  • PSD To Wordpress
  • PSD To Joomla
  • PSD To Drupal
  • PSD To Magento
  • PSD To osCommerce
  • PSD To ZenCart
 

Services

  • Hire Dedicated Resource
  • Content Management System
  • E-commerce Solution
  • PHP Frameworks
  • Mobile Apps Development
  • Multimedia Solutions
  • PHP/ MYSQL Development
  • Packages
 

Products

  • Customer Relationship Management
  • Domain Management System
 

newsletter

Don`t worry, We don`t spam ever!

XHTMLJUNKIES Media

INDIA (AHMEDABAD)
305,306 Iscon Center,
Shivranjani Cross Road,
Satellite, Ahmedabad.
Gujarat, India.
  • home
  • company
  • portfolio
  • blog
  • contact
  • terms & conditions
  • privacy policy