Magento Forum

   
Page 1 of 6
Multiple “TABLE RATES”
 
antoni vidal
Jr. Member
 
Total Posts:  18
Joined:  2007-09-03
 

Greetings from http://www.helimania.es

We need to have several shipping method similar to “table rates”, is this possible?

Tank’s

 
Magento Community Magento Community
Magento Community
Magento Community
 
infield
Sr. Member
 
Total Posts:  89
Joined:  2007-11-04
San Francisco
 

I’m looking for the same thing. The possibility to add multiple table rates that can be selected at check out. In our case it we would like the customer to be able to select

- standard shipping
- expedited shipping
- overnight shipping

Each with it’s own rate table.

Thanks,
-marc

 
Magento Community Magento Community
Magento Community
Magento Community
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

nice, i need it either....  geez

I have the same shipping method with @infield,

 
Magento Community Magento Community
Magento Community
Magento Community
 
infield
Sr. Member
 
Total Posts:  89
Joined:  2007-11-04
San Francisco
 

Is TABLE RATES a stand alone module or part of a larger shipping module?

 
Magento Community Magento Community
Magento Community
Magento Community
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

has anyone been created shipping module similar with tableRate module ?

Tell me… thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
antoni vidal
Jr. Member
 
Total Posts:  18
Joined:  2007-09-03
 

@alkarim and @infield We need the sames shipping methods.

@infield the TABLE RATE module is part of the SHIPING module implemented in..\app\code\core\Mage\Shipping\Model\Carrier\Tablerate

 
Magento Community Magento Community
Magento Community
Magento Community
 
infield
Sr. Member
 
Total Posts:  89
Joined:  2007-11-04
San Francisco
 

I really don’t know this stuff so this is a stab in the dark, but . . .

Would something like this work?

- Duplicate app/code/core/Mage/Shipping/Model/Carrier/Tablerate.php and call it app/code/core/Mage/Shipping/Model/Carrier/Tablerate_II.php
- Call it’s class Mage_Shipping_Model_Carrier_Tablerate_II
- Update app/code/core/Mage/Shipping/etc/config.xml and app/code/core/Mage/Shipping/etc/system.xml to reflect the new class

 
Magento Community Magento Community
Magento Community
Magento Community
 
infield
Sr. Member
 
Total Posts:  89
Joined:  2007-11-04
San Francisco
 

@antoni cool site! I’ve wanted to get into RC helicopters since I was a kid. Some day. smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
antoni vidal
Jr. Member
 
Total Posts:  18
Joined:  2007-09-03
 

@infield Thank you for your comment.

We’ve tried to duplicate the method as you commented, there is a new method in backendd but is not applied correctly in front.

Let us hope that someone from the team out of doubt.

 
Magento Community Magento Community
Magento Community
Magento Community
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

yap, I’ve try and try to duplicate it even flat_rate either but there is still something missing in it… and not appear at frontend.

I think this shipping method have different coding each shipping method.

To make new shipping module appear just add the xml code to : config.xml and system.xml at shipping/etc/config.xml and shipping/etc/system.xml

So, I just change the code but nothing happened

 
Magento Community Magento Community
Magento Community
Magento Community
 
lotusseedsD
Mentor
 
Avatar
Total Posts:  1144
Joined:  2007-08-31
 

Same here :(

I got USPS, one standard, one flat rate and one free shipping showed up. But this is not enough and doesn’t like a good way.

 
Magento Community Magento Community
Magento Community
Magento Community
 
alkarim
Guru
 
Total Posts:  368
Joined:  2008-04-10
 

hi moshe.. give us your enlightment :D

 
Magento Community Magento Community
Magento Community
Magento Community
 
infield
Sr. Member
 
Total Posts:  89
Joined:  2007-11-04
San Francisco
 

I am going to pick this up over at the Programming Questions area as I think that’s where this is headed.

 
Magento Community Magento Community
Magento Community
Magento Community
 
antoni vidal
Jr. Member
 
Total Posts:  18
Joined:  2007-09-03
 

Greetings, is a pleasure for us to send you this good new’s. We already have multiple Table Rates on our website. http://www.helimania.es

Will try to repeat the process we have followed. Sorry for for my bad English.

Table rates keeps your information in a table of the database and this is created in: app\code\core\Mage\Shipping\sql\shipping_setup/mysql4-install-0.7.0.php here we must duplicate the code to create as many tables as we want to have . Note that we create (2) TableRate2 and Tablerate3.

<?php

$installer 
$this;
/* @var $installer Mage_Core_Model_Resource_Setup */

$installer->startSetup();

$installer->run("

-- DROP TABLE IF EXISTS {
$this->getTable('shipping_tablerate')};
CREATE TABLE {
$this->getTable('shipping_tablerate')} (
  `pk` int(10) unsigned NOT NULL auto_increment,
  `website_id` int(11) NOT NULL default '0',
  `dest_country_id` varchar(4) NOT NULL default '0',
  `dest_region_id` int(10) NOT NULL default '0',
  `dest_zip` varchar(10) NOT NULL default '',
  `condition_name` varchar(20) NOT NULL default '',
  `condition_value` decimal(12,4) NOT NULL default '0.0000',
  `price` decimal(12,4) NOT NULL default '0.0000',
  `cost` decimal(12,4) NOT NULL default '0.0000',
  PRIMARY KEY  (`pk`),
  UNIQUE KEY `dest_country` (`website_id`,`dest_country_id`,`dest_region_id`,`dest_zip`,`condition_name`,`condition_value`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS {
$this->getTable('shipping_tablerate2')};
CREATE TABLE {
$this->getTable('shipping_tablerate2')} (
  `pk` int(10) unsigned NOT NULL auto_increment,
  `website_id` int(11) NOT NULL default '0',
  `dest_country_id` varchar(4) NOT NULL default '0',
  `dest_region_id` int(10) NOT NULL default '0',
  `dest_zip` varchar(10) NOT NULL default '',
  `condition_name` varchar(20) NOT NULL default '',
  `condition_value` decimal(12,4) NOT NULL default '0.0000',
  `price` decimal(12,4) NOT NULL default '0.0000',
  `cost` decimal(12,4) NOT NULL default '0.0000',
  PRIMARY KEY  (`pk`),
  UNIQUE KEY `dest_country` (`website_id`,`dest_country_id`,`dest_region_id`,`dest_zip`,`condition_name`,`condition_value`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- DROP TABLE IF EXISTS {
$this->getTable('shipping_tablerate3')};
CREATE TABLE {
$this->getTable('shipping_tablerate3')} (
  `pk` int(10) unsigned NOT NULL auto_increment,
  `website_id` int(11) NOT NULL default '0',
  `dest_country_id` varchar(4) NOT NULL default '0',
  `dest_region_id` int(10) NOT NULL default '0',
  `dest_zip` varchar(10) NOT NULL default '',
  `condition_name` varchar(20) NOT NULL default '',
  `condition_value` decimal(12,4) NOT NULL default '0.0000',
  `price` decimal(12,4) NOT NULL default '0.0000',
  `cost` decimal(12,4) NOT NULL default '0.0000',
  PRIMARY KEY  (`pk`),
  UNIQUE KEY `dest_country` (`website_id`,`dest_country_id`,`dest_region_id`,`dest_zip`,`condition_name`,`condition_value`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    "
);

$installer->endSetup();
Now we must duplicate and rename:
\app\code\core\Mage\Shipping\Model\Carrier\Tablerate.php to \app\code\core\Mage\Shipping\Model\Carrier\Tablerate3.php or (n) version.
Change all the code that refers to TableRate as in this example.

In the next post

 
Magento Community Magento Community
Magento Community
Magento Community
 
antoni vidal
Jr. Member
 
Total Posts:  18
Joined:  2007-09-03
 

<?php 
class Mage_Shipping_Model_Carrier_Tablerate3
    
extends Mage_Shipping_Model_Carrier_Abstract
    
implements Mage_Shipping_Model_Carrier_Interface
{

    
protected $_code 'tablerate3';
    protected 
$_default_condition_name 'package_weight';

    protected 
$_conditionNames = array();

    public function 
__construct()
    
{
        parent
::__construct();
        foreach (
$this->getCode('condition_name') as $k=>$v{
            $this
->_conditionNames[] $k;
        
}
    }

    
/**
     * Enter description here...
     *
     * @param Mage_Shipping_Model_Rate_Request $data
     * @return Mage_Shipping_Model_Rate_Result
     */
    
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
    
{
        
if (!$this->getConfigFlag('active')) {
            
return false;
        
}

        
if (!$request->getConditionName()) {
            $request
->setConditionName($this->getConfigData('condition_name') ? $this->getConfigData('condition_name') : $this->_default_condition_name);
        
}

        $result 
Mage::getModel('shipping/rate_result');
        
$rate $this->getRate($request);
        if (!empty(
$rate) && $rate['price'>= 0{
            $method 
Mage::getModel('shipping/rate_result_method');

            
$method->setCarrier('tablerate3');
            
$method->setCarrierTitle($this->getConfigData('title'));

            
$method->setMethod('bestway');
            
$method->setMethodTitle($this->getConfigData('name'));

            
$shippingPrice $this->getFinalPriceWithHandlingFee($rate['price']);

            
$method->setPrice($shippingPrice);
            
$method->setCost($rate['cost']);

            
$result->append($method);
        
}

        
return $result;
    
}

    
public function getRate(Mage_Shipping_Model_Rate_Request $request)
    
{
        
return Mage::getResourceModel('shipping/carrier_tablerate3')->getRate($request);
    
}

    
public function getCode($type$code='')
    
{
        $codes 
= array(

            
'condition_name'=>array(
                
'package_weight' => Mage::helper('shipping')->__('Weight vs. Destination'),
                
'package_value'  => Mage::helper('shipping')->__('Price vs. Destination'),
                
'package_qty'    => Mage::helper('shipping')->__('# of Items vs. Destination'),
            ),

            
'condition_name_short'=>array(
                
'package_weight' => Mage::helper('shipping')->__('Weight (and above)'),
                
'package_value'  => Mage::helper('shipping')->__('Order Subtotal (and above)'),
                
'package_qty'    => Mage::helper('shipping')->__('# of Items (and above)'),
            ),

        );

        if (!isset(
$codes[$type])) {
            
throw Mage::exception('Mage_Shipping'Mage::helper('shipping')->__('Invalid Table Rate code type: %s'$type));
        
}

        
if (''===$code{
            
return $codes[$type];
        
}

        
if (!isset($codes[$type][$code])) {
            
throw Mage::exception('Mage_Shipping'Mage::helper('shipping')->__('Invalid Table Rate code for type %s: %s'$type$code));
        
}

        
return $codes[$type][$code];
    
}

    
/**
     * Get allowed shipping methods
     *
     * @return array
     */
    
public function getAllowedMethods()
    
{
        
return array('bestway'=>$this->getConfigData('name'));
    
}

}

We do the same with the following files and folders:
app\code\core\Mage\Shipping\Model\Mysql4\Carrier\Tablerate3.php
app\code\core\Mage\Shipping\Model\Mysql4\Carrier\Tablerate3\Collection.php
---> No change the name of file.

Now add the code necessary for the configuration files:

app\code\core\Mage\Shipping\etc\config.xml

......
    <global>
        <
models>
            <
shipping>
                <class>
Mage_Shipping_Model</class>
                <
resourceModel>shipping_mysql4</resourceModel>
            </
shipping>
            <
shipping_mysql4>
                <class>
Mage_Shipping_Model_Mysql4</class>
                <
entities>
                    <
tablerate>
                        <
table>shipping_tablerate</table>
                    </
tablerate>
                    <
tablerate2>
                        <
table>shipping_tablerate2</table>
                    </
tablerate2>
                    <
tablerate3>
                        <
table>shipping_tablerate3</table>
                    </
tablerate3>
                </
entities>
            </
shipping_mysql4>
        </
models>
        <
resources>
            <
shipping_setup>
              .......
<
carriers>
..........
            <
tablerate2>
                <
active>0</active>
                <
sallowspecific>0</sallowspecific>
                <
condition_name>package_weight</condition_name>
                <
model>shipping/carrier_tablerate2</model>
                <
name>Table Rate two</name>
                <
title>Best Way</title>
                <
specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping methodplease contact us.</specificerrmsg>
                <
handling_type>F</handling_type>
            </
tablerate2>
         .....
</
carriers>
    </default>
</
config>

 
Magento Community Magento Community
Magento Community
Magento Community
 
antoni vidal
Jr. Member
 
Total Posts:  18
Joined:  2007-09-03
 

the same for
app\code\core\Mage\Shipping\etc\system.xml

....
<
carriers translate="label" module="shipping">
           .....
            <
groups>
                <
tablerate translate="label">
                    .....
               </
tablerate>
                <
tablerate2 translate="label">
                    <
label>Table rates two</label>
                    <
frontend_type>text</frontend_type>
                    <
sort_order>2</sort_order> ...........
                     ................
                <
condition_name translate="label">
                            <
label>Condition</label>
                            <
frontend_type>select</frontend_type>
                            <
source_model>adminhtml/system_config_source_shipping_tablerate2</source_model>
                            <
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>
                        </
condition_name>
                        <
export translate="label">
                            <
label>Export</label>
                            <
frontend_type>export</frontend_type>
                            <
sort_order>5</sort_order>
                            <
show_in_default>0</show_in_default>
                            <
show_in_website>1</show_in_website>
                            <
show_in_store>0</show_in_store>
                        </
export>
                        <
import translate="label">
                            <
label>Import</label>
                            <
frontend_type>import</frontend_type>
                            <
backend_model>adminhtml/system_config_backend_shipping_tablerate2</backend_model>
                            <
sort_order>6</sort_order>
                            <
show_in_default>0</show_in_default>
                            <
show_in_website>1</show_in_website>
                            <
show_in_store>0</show_in_store>
                        </
import>.........................
                         ........................................
                        </
tablerate2>

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 6