LeeTaylorDoes

  • Archive
  • RSS
  • Ask me anything
  • Submit

Magento: Create New Payment Method -> Cash On Delivery

About: How To Create a Magento Custom Module and A “Cash On Delivery” Payment Method Who’s Interested: Informative to the semi-technically savvy What: Custom Magento Payment Method   So I’ve seen more and more people raising awareness about desire to create a new payment method that allows orders to be paid via “cash on delivery” or “on pickup” by customer. Is this helpful to companies who sell to local clients? Absolutely.   So in offering a solution, I’ll go ahead and outline what files need to be created and why with hopes to help educate the intigued learner in how to create a Magento Custom Module as well. The benefit in knowing how to do this is modifying existing Magento functionality in a way that it will not be overwritten upon a successful Magento upgrade.   Thus, I’ll jump in. The following 5 files will be created (relative to one’s Magento root folder):  

  • confix.xml
  • system.xml
  • PaymentMethod.php
  • mysql4-install-0.1.0.php
  • NewModule.xml
Here are their contents (with comments) and relative paths:   app/code/local/Mage/NewModule/etc/config.xml (below) [sourcecode language=’xml’] Mage_NewModule_ModelMage_NewModulecore_setupcore_writecore_read1newmodule/paymentMethod1Cash On Delivery [/sourcecode] app/code/local/Mage/NewModule/etc/system.xml (below) [sourcecode language=’xml’] 670110 selectadminhtml/system_config_source_yesno1110 selectadminhtml/system_config_source_order_status4110 allowspecific50adminhtml/system_config_source_payment_allspecificcountries111 multiselect51adminhtml/system_config_source_country111<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>0</show_in_store> [/sourcecode] app/code/local/Mage/NewModule/Model/PaymentMethod.php (below) [sourcecode language=’php’] Custom Payment Module for Cash On Delivery * @category Mage * @package Mage_Local * @author Lee Taylor / Elias Interactive -> lee [at] eliasinteractive [dot] com * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Mage_NewModule_Model_PaymentMethod extends Mage_Payment_Model_Method_Abstract { protected $_code = 'newmodule'; //protected $_formBlockType = 'payment/form_checkmo'; //protected $_infoBlockType = 'payment/info_cod'; /** * Assign data to info model instance * * @param mixed $data * @return Mage_Payment_Model_Method_Checkmo */ public function assignData($data) { $details = array(); if ($this->getPayableTo()) { $details['payable_to'] = $this->getPayableTo(); } if ($this->getMailingAddress()) { $details['mailing_address'] = $this->getMailingAddress(); } if (!empty($details)) { $this->getInfoInstance()->setAdditionalData(serialize($details)); } return $this; } public function getPayableTo() { return $this->getConfigData('payable_to'); } public function getMailingAddress() { return $this->getConfigData('mailing_address'); } } [/sourcecode] app/code/local/Mage/NewModule/sql/newmodule_setup/mysql4-install-0.1.0.php (below) [sourcecode language='php'] app/etc/modules/NewModule.xml (below) [sourcecode language='xml'] truelocal0.1.0 [/sourcecode] Again, this serves as a basic configuration for a new payment method that allows Cash On Delivery and is written as a Magento Custom Module. Modifying these files may be necessary, though this should be a good outline to get you started. Any help needed, post here and we’ll get some dialogue going to find solutions for your needs. Or simply download the files here:

Elias: Cash On Delivery (Magento Payment Method)

 

  • 3 years ago
  • Comments
  • Permalink
  • Share
    Tweet

Recent comments

Blog comments powered by Disqus
← Previous • Next →

About

technology, communication, and simplistic innovations to share wealth and opportunities globally and socially.

Pages

  • Contact

Me, Elsewhere

  • @timothyltaylor on Twitter
  • My Skype Info
  • Linkedin Profile
  • leetaylordoes on github

Twitter

loading tweets…

  • RSS
  • Random
  • Archive
  • Ask me anything
  • Submit
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr