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

Edit the shipping price on an order? 
 
i960
Guru
 
Avatar
Total Posts:  633
Joined:  2007-10-01
Bakersfield, CA
 

Tested and works.  Use matrixrate_0.  Instructions updated to reflect this.

 
Magento Community Magento Community
Magento Community
Magento Community
 
davedavedave
Sr. Member
 
Avatar
Total Posts:  238
Joined:  2007-08-31
 
tandylacker - 21 May 2009 01:25 PM

I am having an issue getting this to work…

I added the code, everything appeared.  I added a custom rate for an order with title and pressed save.  The new rate did not add to the total, but did allow me to place the order without even choosing a shipping method.  As if it had a method chosen, but the value didn’t appear.  Anyways, the custom price never showed up on the total…

I’m using the Auctionmaid shipping extension rather than flat rate or table rate.  I imagine this is my issue… What would I write instead of the two options that you offered on the shipping.php file?

Thanks for all your help on this i960!  I’m actually having the same issue as above, but I’m using USPS as my main shipping module.  Do I need to do something in addition to your original two steps/

 
Magento Community Magento Community
Magento Community
Magento Community
 
i960
Guru
 
Avatar
Total Posts:  633
Joined:  2007-10-01
Bakersfield, CA
 
DavePit.com - 02 June 2009 12:24 PM

Thanks for all your help on this i960!  I’m actually having the same issue as above, but I’m using USPS as my main shipping module.  Do I need to do something in addition to your original two steps/

Yes, you have to change flatrate_flatrate to whatever it is your shipping method uses.  Easiest way I’ve found to do it is to use the Firefox extension Firebug

Once installed, start creating an order in Admin, and then scroll down to where you would select a shipping method. Click on “Get shipping methods and rates”.  Now you need to click on the little Firebug icon down in the bottom right hand side of the Firefox window.  This will bring up the main Firebug window.  From there, click on the “Inspect” button on the left hand side of the Firebug toolbar.  And finally, click on the radio button for the shipping method you want to overwrite.  What this will do is highlight the HTML code for that radio button you selected in the Firebug window.  Look at that HTML code and it will tell you what you need to use in place of flatrate_flatrate.  For instance, this is the HTML code for table rate shipping:

<input id="s_method_tablerate_bestway" type="radio" value="tablerate_bestway" onclick="order.setShippingMethod(this.value)" name="order[shipping_method]"/>

Specifically what I am looking for is value="tablerate_bestway”.  That will tell you what you need to use in place of flatrate_flatrate.

I can’t possibly check and verify all the various shipping methods out there, and any shipping methods with custom modifications may not work at all.  So if you do find the code for a shipping method I haven’t listed, please post it in this thread and I will add it to the list.

What would be really nice is if this was all packaged up in an extension and something was written to automatically get the appropriate code for any shipping method being used.  I have no idea how to do that and I wouldn’t have the time to support an extension anyway.  If someone else can do it, please feel free to do so.

 
Magento Community Magento Community
Magento Community
Magento Community
 
i960
Guru
 
Avatar
Total Posts:  633
Joined:  2007-10-01
Bakersfield, CA
 
i960 - 07 June 2009 10:26 AM

What would be really nice is if this was all packaged up in an extension and something was written to automatically get the appropriate code for any shipping method being used.

Ok guys, I got this one figured out.  I’ve found a way to automatically set the shipping code so it shouldn’t matter at all what method you use, and you don’t have to edit anything. I will post in a few how I did this.  Stay tuned.

 
Magento Community Magento Community
Magento Community
Magento Community
 
i960
Guru
 
Avatar
Total Posts:  633
Joined:  2007-10-01
Bakersfield, CA
 

Here is the new and better way of doing this.  Please ignore the previous method I posted.

1. /app/design/adminhtml/default/default/template/sales/order/create/shipping/method/form.phtml

After the second <?php endforeach; ?> (should be line 62)
Insert this:

<dt><br/><hr/><br/></dt>
        <
dd>
            <
p><strong><?php echo $this->__('Custom Shipping Rate:'); ?></strong>&nbsp;&nbsp;<input id="custom-shipment-rate" type="text" style="width: 100px;" /></p>
            <
p><strong><?php echo $this->__('Title:'); ?></strong>&nbsp;&nbsp;<input id="custom-shipment-title" type="text" style="width: 200px;" />&nbsp;&nbsp;<button id="custom-shipping-button" type="button" class="scalable " onclick="order.setShippingMethod('custom-shipping-rate'+document.getElementById('custom-shipment-rate').value+':custom-shipping-title'+document.getElementById('custom-shipment-title').value+':custom-shipping-code<?php echo $_code ?>')"><span>Save</span></button></p>
            <
ul class="messages">
                <
li class="notice-msg"><?php echo $this->__('Note: This will override any shipping method selected above.'); ?></li>
            </
ul>
        </
dd>

2. /app/code/core/Mage/Sales/Model/Quote/Address/Total/Shipping.php

Copy this file to /app/code/local/Mage/Sales/Model/Quote/Address/Total/Shipping.php.

You will need to create these folders if they do not already exist. They are case sensitive, so make sure you create them exactly as shown.

Find this:

if ($method{
            
foreach ($address->getAllShippingRates() as $rate{
                
if ($rate->getCode()==$method{
                    $amountPrice 
$address->getQuote()->getStore()->convertPrice($rate->getPrice(), false);
                    
$address->setShippingAmount($amountPrice);
                    
$address->setBaseShippingAmount($rate->getPrice());
                    
$address->setShippingDescription($rate->getCarrierTitle().' - '.$rate->getMethodTitle());
                    break;
                
}
            }
        }

And after that insert:

if (substr($method020)=="custom-shipping-rate"{
        
list($customShippingRate$customShippingDescription$customShippingCode) = explode(":"$method);
        
$custom_method str_replace("custom-shipping-code","",$customShippingCode);
        foreach (
$address->getAllShippingRates() as $rate{
                
if ($rate->getCode()==$custom_method{
                    $amountPrice 
$address->getQuote()->getStore()->convertPrice($rate->getPrice(), false);
                    
$address->setShippingAmount(str_replace("custom-shipping-rate","",$customShippingRate));
                    
$address->setBaseShippingAmount(str_replace("custom-shipping-rate","",$customShippingRate));
                    
$address->setShippingDescription(str_replace("custom-shipping-title","",$customShippingDescription));
                    break;
                
}
            }
        }

You can check the attached pic to see what this looks like.  Notice how I put in a custom shipping title of FedEx Priority Overnight, and that will show up on the customers end as well.  Now you can label the shipping method to match exactly what you are using for that order.

Also keep in mind that it’s best to make a copy of the admin template and edit that instead.  If you do a search you should be able to find instructions on how to do that.  Also, instead of editing this file directly: /app/code/core/Mage/Sales/Model/Quote/Address/Total/Shipping.php I would make a copy of it and place it in /app/code/local/Mage/Sales/Model/Quote/Address/Total/Shipping.php so it doesn’t get overwritten when you do an upgrade.

Image Attachments
custom-shipping-with-title.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
davedavedave
Sr. Member
 
Avatar
Total Posts:  238
Joined:  2007-08-31
 

i960 - I followed the method you used right above (I would recommend going to your other posts and removing them, and reference the updated one, that way people don’t accidentally use the old code).

Even with this new one, do I still need to do the same stuff with Firebug?  I’m assuming so since I’m still not seeing the data populate, but want to be sure.

 
Magento Community Magento Community
Magento Community
Magento Community
 
davedavedave
Sr. Member
 
Avatar
Total Posts:  238
Joined:  2007-08-31
 
DavePit.com - 07 June 2009 04:50 PM

i960 - I followed the method you used right above (I would recommend going to your other posts and removing them, and reference the updated one, that way people don’t accidentally use the old code).

Even with this new one, do I still need to do the same stuff with Firebug?  I’m assuming so since I’m still not seeing the data populate, but want to be sure.

Actually, I just tried doing the code updates for USPS (FYI - it’s “usps_Priority Mail")...and still can’t get it to populate anything.  Any ideas?  Here’s my code (I also tried your code above):

Form.phtml

<dt><br/><hr/><br/></dt>
        <
dd>
            <
p><strong><?php echo $this->__('Custom Shipping Rate:'); ?></strong>&nbsp;&nbsp;<input id="custom-shipment-rate" type="text" style="width: 100px;" /></p>
            <
p><strong><?php echo $this->__('Title:'); ?></strong>&nbsp;&nbsp;<input id="custom-shipment-title" type="text" style="width: 200px;" />&nbsp;&nbsp;<button id="custom-shipping-button" type="button" class="scalable " onclick="order.setShippingMethod('custom-shipping-rate'+document.getElementById('custom-shipment-rate').value+':custom-shipping-title'+document.getElementById('custom-shipment-title').value+':custom-shipping-code<?php echo $_code ?>')"><span>Save</span></button></p>
            <
ul class="messages">
                <
li class="notice-msg"><?php echo $this->__('Note: This will override any shipping method selected above.'); ?></li>
            </
ul>
        </
dd>

Shipping.php

if (substr($method020)=="custom-shipping-rate"{
        $method2
="usps_Priority Mail";
        list(
$customShippingRate$customShippingDescription) = explode(":"$method);
        foreach (
$address->getAllShippingRates() as $rate{
                
if ($rate->getCode()==$method2{
                    $amountPrice 
$address->getQuote()->getStore()->convertPrice($rate->getPrice(), false);
                    
$address->setShippingAmount(str_replace("custom-shipping-rate","",$customShippingRate));
                    
$address->setBaseShippingAmount(str_replace("custom-shipping-rate","",$customShippingRate));
                    
$address->setShippingDescription(str_replace("custom-shipping-title","",$customShippingDescription));
                    break;
                
}
            }
        }
 
Magento Community Magento Community
Magento Community
Magento Community
 
i960
Guru
 
Avatar
Total Posts:  633
Joined:  2007-10-01
Bakersfield, CA
 

I have not tested this with USPS, but I’m wondering if having a space in there is tripping it up.  I will try it out with USPS and see if it works for me.  With the second code I posted you don’t need to use Firebug.  I tested it with the built in flat rate, table rate, and free shipping methods.

 
Magento Community Magento Community
Magento Community
Magento Community
 
i960
Guru
 
Avatar
Total Posts:  633
Joined:  2007-10-01
Bakersfield, CA
 

Ok, I can’t test USPS or any of the other shipping methods right now because I don’t have an account with them.  There’s a quick modification that can be made to the second code I posted which will show the shipping code being used instead of using Firebug.  I’m actually late for dinner right now but as soon as I get back I will post the mod so we can figure out what’s going on here.  For now, try enabling flat rate shipping and see if it works with that just to make sure the code is working at all.

 
Magento Community Magento Community
Magento Community
Magento Community
 
i960
Guru
 
Avatar
Total Posts:  633
Joined:  2007-10-01
Bakersfield, CA
 

Ok, here’s my modification to form.phtml that will display the code so you don’t need to use Firebug.

<dt><br/><hr/><br/></dt>
        <
dd>
            <
p><strong><?php echo $this->__('Custom Shipping Rate:'); ?></strong>&nbsp;&nbsp;<input id="custom-shipment-rate" type="text" style="width: 100px;" /></p>
            <
p><strong><?php echo $this->__('Title:'); ?></strong>&nbsp;&nbsp;<input id="custom-shipment-title" type="text" style="width: 200px;" />&nbsp;&nbsp;<button id="custom-shipping-button" type="button" class="scalable " onclick="order.setShippingMethod('custom-shipping-rate'+document.getElementById('custom-shipment-rate').value+':custom-shipping-title'+document.getElementById('custom-shipment-title').value+':custom-shipping-code<?php echo $_code ?>')"><span>Save</span></button></p>
            <
p><strong><?php echo $this->__('Shipping Code:'); ?></strong>&nbsp;&nbsp;<?php echo $_code ?></p>
            <
ul class="messages">
                <
li class="notice-msg"><?php echo $this->__('Note: This will override any shipping method selected above.'); ?></li>
            </
ul>
        </
dd>

I’ve attached what it looks like.  As you can see, it’s working fine with UPS.  I can’t test USPS, Fedex, or DHL because those require accounts that I don’t have.  The way it works is that it will take whatever shipping method was last, and overwrite that one.  So in my case, UPS 2nd Day Air was the last one displayed, and the code for it is ups_2DA.  I’m not sure why it doesn’t work for USPS.

Image Attachments
custom-shipping.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
davedavedave
Sr. Member
 
Avatar
Total Posts:  238
Joined:  2007-08-31
 

Still nothing.

usps_Express Mail is the last code it’s using, since I allow Priority and Express Mail to be used.

I updated $method2 to “usps_Express Mail” in shipping.php, but still don’t get anything to populate once I save a custom rate.

On one of my orders was freeshipping_freeshipping, and even with that, I’m not getting anything to populate (updated shipping.php to your actual code).  So that I think resolves the potential issue with the space.  Not sure why it’s not working though.

 
Magento Community Magento Community
Magento Community
Magento Community
 
i960
Guru
 
Avatar
Total Posts:  633
Joined:  2007-10-01
Bakersfield, CA
 

Can you set up the built in flat rate shipping as your only shipping method to test?  I’d like to know if the code is even working at all for you before trying to figure out what’s going on with USPS.

 
Magento Community Magento Community
Magento Community
Magento Community
 
davedavedave
Sr. Member
 
Avatar
Total Posts:  238
Joined:  2007-08-31
 
i960 - 08 June 2009 03:20 PM

Can you set up the built in flat rate shipping as your only shipping method to test?  I’d like to know if the code is even working at all for you before trying to figure out what’s going on with USPS.

Yup, as soon as I enable flat rate shipping, it does in fact work.  So sounds like it’s not working with free shipping or USPS.

 
Magento Community Magento Community
Magento Community
Magento Community
 
i960
Guru
 
Avatar
Total Posts:  633
Joined:  2007-10-01
Bakersfield, CA
 

It works fine for me with free shipping.  Picture attached.  I’m at a loss as to why it doesn’t work with USPS.  I’m considering getting myself a USPS account for testing so I can see first hand what’s going on.  I would actually like to get this packaged up as an extension, but not until it works with all of the built in shipping methods.

I think what would be ideal is to create a whole new shipping module just for this mod, and have it only show up in the backend.  That way, this thing will work no matter what other shipping methods are being used.  I just don’t know how to do that, at least not yet.  I’m still learning Magento.

Image Attachments
custom-shipping-free.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
i960
Guru
 
Avatar
Total Posts:  633
Joined:  2007-10-01
Bakersfield, CA
 

Here’s a wiki on creating a custom shipping module: http://www.magentocommerce.com/wiki/how-to/create-shipping-method-module

I’ll bet that could somehow be adapted to make this work.  The trick would be making it work on the backend but not show up on the frontend.  If I have some free time this week I’ll see what I can come up with.  I still have no idea how to create and publish an extension, so if this all ends up working, I will likely contact one of the many extension developers and see if they want to package it up for me and publish it.  I think this mod is useful enough that it should be available to the masses without having to hack a bunch of files.

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