0

I am currently adding 2 custom shipping methods to a Magento website.

I have successfully added them using this method:

My/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <My_Shipping2>
            <module>0.0.1</module>
        </My_Shipping2>
    </modules>
    <global>
        <models>
            <my_shipping2>
                <class>My_Shipping2_Model</class>
            </my_shipping2>
        </models>
    </global>
    <default>
        <carriers>
            <my_shipping2>
                <active>1</active>
                <model>my_shipping2/carrier</model>
                <title>My Shipping2 Carrier</title>
                <name>Fixed</name>
                <sort_order>10</sort_order>
                <sallowspecific>0</sallowspecific>
            </my_shipping2>
        </carriers>
    </default>
</config>

My/etc/system.xml

<?xml version="1.0"?>
<config>
    <sections>
        <carriers translate="label" module="shipping2">
            <groups>
                <my_shipping2 translate="label">
                    <label>My Shipping2</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>
                    <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>0</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>3</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>4</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </price>
                        <sort_order translate="label">
                            <label>Sort Order</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>100</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </sort_order>
                        <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>
                        <specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
                    </fields>
                </my_shipping2>
            </groups>
        </carriers>
    </sections>
</config>

My/Model/Carrier.php

<?php
    class My_Shipping2_Model_Carrier extends Mage_Shipping_Model_Carrier_Abstract implements Mage_Shipping_Model_Carrier_Interface {
        protected $_code = 'my_shipping2';
        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){
                $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('my_shipping2'=>$this->getConfigData('name'));
        }
    }
?>

The problem I have is that I wanted to add a description to the frontend:

config.xml

<shipdesc>Shipping 2</shipdesc>

system.xml

<shipdesc translate="label">
    <label>Package Description</label>
    <frontend_type>text</frontend_type>
    <sort_order>120</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</shipdesc>

Carrier.php

$method->setShipDesc($this->getConfigData('shipdesc'));

I know I am missing something.

Do I need to declare anything in another file?

2
  • did you find any way to add custom detail to shipping carrier?
    – Piyush
    Commented Jan 8, 2018 at 10:28
  • @Piyush sorry have not been able to make this work. I am still researching on how to do this.
    – fja3omega
    Commented Jan 9, 2018 at 0:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.