Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

A problem related to carriers: $rate and their unique ID / code
 
dreamyguy
Jr. Member
 
Avatar
Total Posts:  18
Joined:  2008-07-09
Oslo, Norway
 

Hi,

It was hard to find a title for this topic… I hired someone to create a condition in the checkout, so I could show only a particular shipping method if at least one of the products in the cart was marked “yes” in a custom attribute (that has “no” as default):

if ($rate->getCode() == 'flatrate_flatrate')

The purpose of the condition is irrelevant on this topic. The point is that Magento has the following shipping methods:

flatrate
tablerate
freeshipping
ups
usps
fedex
dhl

For some reason I don’t understand this particular condition will only work when the rate code is written like ‘flatrate_flatrate’. I have seen such doubled IDs repeat themselves in several places in other files, so I guess it’s me who’s not savvy enough in Magento to get the grip on this one…

As long as I replace ‘flatrate_flatrate’ with:

‘tablerate_tablerate’
‘freeshipping_freeshipping’
‘ups_ups’
‘usps_usps’
‘fedex_fedex’
‘dhl_dhl’

…the condition above will work just fine. And that’s great.

BUT, the ID I need to replace ‘flatrate_flatrate’ with has two words, separated by a underscore, like so:

‘modulename_modulemethodone’

It is that way because this is a module that contains two shipping methods under the same shipping provider. The problem is that I can’t write it like that:

if ($rate->getCode() == 'modulename_modulemethodone_modulename_modulemethodone')

…because then the condition won’t work.

So I would like to know if anyone else has been through something similar and have a solution to this problem.

Any help is appreciated!
Wallace

(PS: I only need to change this one line to get it to work, so please save your offer of a new module for another topic).

 
Magento Community Magento Community
Magento Community
Magento Community
 
dreamyguy
Jr. Member
 
Avatar
Total Posts:  18
Joined:  2008-07-09
Oslo, Norway
 

Just to add more to the context…

I have already tried:

if ($rate->getCode() == 'modulename_modulemethodone')

and:

$theshipper 'modulename_modulemethodone';
if (
$rate->getCode() == ''.$theshipper.'_'.$theshipper.'')

...no love. :(

 
Magento Community Magento Community
Magento Community
Magento Community
 
IgorKalders
Jr. Member
 
Total Posts:  3
Joined:  2011-01-11
 

Just wanted to add to this that I had some problems getting my custom carrier to work. It turned out you better not use an underscore in your own carrier id.

For the most part, it poses no problem, but e.g. Phoenix_CashOnDelivery_Model_CashOnDelivery explodes the shipping method by underscore, which essentially renders the “Disallow specific shipping methods” configuration useless. Note also that after exploding, Phoenix_CashOnDelivery_Model_CashOnDelivery uses the first part to check the shipping method against (which I think just equals the carrier code).

So summary of the above: use an underscore-less name for your own carrier.

After my issues, I took a deeper dive, and it seems that the format of the shipping code is “carrier_method”, which opens up possibility for shipping carriers to implement different methods, “attributed shippings” if you want.

So if you provide your own carrier, you could in theory use “mycompany_tnt” and “mycompany_dhl” to differentiate between your own shipments.

Just thought I’d drop this here in case it might help anyone.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top