This is the last chapter for adding multiple tablerate to Magento system. Now we need to add to our admin panel, so we can edit it.
We need to add two new files (they are duplicated from the original tablerate module):
\app\code\core\Mage\Adminhtml\Model\System\Config\Backend\Shipping\Tablerate(n).php
\app\code\core\Mage\Adminhtml\Model\System\Config\Source\Shipping\Tablerate(n).php
Code:
\app\code\core\Mage\Adminhtml\Model\System\Config\Source\Shipping\Tablerate3.php
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage_Adminhtml
* @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class Mage_Adminhtml_Model_System_Config_Source_Shipping_Tablerate3
{
public function toOptionArray()
{
$tableRate = Mage::getSingleton('shipping/carrier_tablerate3');
$arr = array();
foreach ($tableRate->getCode('condition_name') as $k=>$v) {
$arr[] = array('value'=>$k, 'label'=>$v);
}
return $arr;
}
}
Code:
\app\code\core\Mage\Adminhtml\Model\System\Config\Backend\Shipping\Tablerate3.php
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage_Adminhtml
* @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*//**
* Backend model for shipping table rates CSV importing
*
* @category Mage
* @package Mage_Adminhtml
* @author Magento Core Team <core@magentocommerce.com>
*/class Mage_Adminhtml_Model_System_Config_Backend_Shipping_Tablerate3 extends Mage_Core_Model_Config_Data
{
public function _afterSave()
{
Mage::getResourceModel('shipping/carrier_tablerate3')->uploadAndImport($this);
}
}
If you are following and copied from my code, then you should see the same screenshot that I have.
Please note that I added two extra tables, so you will see tablerate2 and tablerate3 in the xml files and little bit different from yours. And don’t forget to add a new “tablerate” table to your Database. Check here to see the SQL statement to create the tablerate(n) table if you don’t know.
This is own cheat sheet for adding Multiple Tablerate to Magento. It is quite messy, but helpful. 🙂