Refine Post By:

I created a solution to solve the following issue(s) without hacking the core for Magento v1.6. All it does is *extend* the core class and override the corrupted core function with the corrected code.  I stumbled across this error after installing a fresh copy of Magento v1.6, so I figured more people will be having the same issue and I decided to offer some insight in addition to a resolution.

Call to undefined method Mage_Sales_Model_Abstract::getshippingmethod() in app/code/core/Mage/Sales/Model/Order.php on line 1213

This error is generally triggered when you try to “Edit” an order in the administrative backend. Additionally it can be triggered when you try to “Ship” the order. To download my extension and easily fix the error, all you have to do is click this link and follow the directions to install it! It will probably take you less then 5 minutes to do.

For the people that are more adamant about programming and learning Magento, I’ve provided some resources and directions to help guide you through your own resolution.

Warning: If you don’t know how to extend core classes and aren’t interested in taking the time to learn how, you will probably end up hacking the core and I suggest you just download what I provided above. On the flip-side, if you’re interested in learning how to do it the correct way, check out this article (Overriding Core Models with a Custom Model).

The problem lies in the following model class: Mage_Sales_Model_Order (located in /app/code/core/Mage/Sales/Model/Order.php). The function that holds the poison is within this class, starting on line 1212 called getShippingMethod(). Once you understand how to override core model classes, all you have to do is override this function with the new function provided below.

The poison (line 3):

1
2
3
4
5
6
7
8
9
10
11
12
13
public function getShippingMethod($asObject = false)
{
  $shippingMethod = parent::getShippingMethod();
  if (!$asObject) {
    return $shippingMethod;
  } else {
    list($carrierCode, $method) = explode('_', $shippingMethod, 2);
    return new Varien_Object(array(
    'carrier_code' => $carrierCode,
    'method' => $method
    ));
  }
}

The solution (line 3):

3
4
5
6
7
8
9
10
11
12
13
14
15
public function getShippingMethod($asObject = false)
{
  $shippingMethod = $this->getData('shipping_method');
  if (!$asObject) {
    return $shippingMethod;
  } else {
    list($carrierCode, $method) = explode('_', $shippingMethod, 2);
    return new Varien_Object(array(
    'carrier_code' => $carrierCode,
    'method' => $method
    ));
  }
}

25 Comments

  1. Do you mind emailing WHY this is even an issue though? I don’t understnad why its causing this in the first place. Is this a magento bug or what?

  2. Hi Nick –

    It’s a bug in Magento. It’s trying to invoke a method within the parent class that doesn’t exist. If you look in Mage/Sales/Model/Abstract.php (The parent class of Mage/Sales/Model/Order.php) and try to find the function getShippingMethod(), you’ll notice that it’s not there.

    You can’t invoke a method that doesn’t exist, hence the reason for the error “Call to undefined method Mage_Sales_Model_Abstract::getshippingmethod()”.

  3. Well I uploaded the fix to my app/ and I still am receiving the same error.

    Am I supposed to do anything else manually besides upload these files?

    My question basically regarding the issue is, why are people reporting a php version upgrade fixed their issue? I am running a more current version than suggested, but others reported upgrading to 5.2.1 fixing the issue.

  4. Did you install it in the correct directories? Additionally, you may have to log out of the admin backend and log back in to flush the cache in order for Magento to recognize the extension.

    • hey there, thanks for your fix.

      i’m kinda new to magento, so i’m wondering if i’m supposed to somehow “install” the fix inside the magento backend, or just upload the files.

      thanks for your patience.

  5. Your updated solution via email sorted all of my issues — except I receive the same error for an order that totaled $0.00.

  6. Thank you so much! I’ve manually extended Magento with your code and instructions. Worked like a charm.

  7. Works perfectly, nice to see someone recommending the proper way to fix bugs (override the core not hacking it).

    Thanks for the help

  8. Hi Billy

    Thank you for creating this fix. I am trying to understand where to upload to, but the readme.txt file is missing and the link to understanding the override is not working. I get an error when using your folder structure as reference.

    Fatal error: Class ‘Wabism_CoreFix_Sales_Model_Order’ not found in /home/snugglyb/public_html/includes/src/__default.php on line 29548

    I would really appreciate any help.

    Thanks Mark

    • Hi Mark –

      The module starts in the Magento root folder.

      magento_root/app/code/local/Wabism/*
      magento_root/app/etc/modules/*

    • Hey ! Your problem is that you have enabled compilation and it keeps the old files. This is just an idea. I have seen that error before to disable compilation (sources from includes/src…). Hope this helps.

  9. Hi! It works :) I tried first to write my own module but then I put yours. Thank you!

  10. Thank for this fix! Works like a charm.

  11. Hi I have just downloaded your fix zip, but there is no instruction text regarding installation.
    Please advise?
    Kind regards

    Danny

  12. I am getting Fatal error: Call to a member function isShippingLabelsAvailable() on a non-object in /home/movieart/public_html/app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Create/Items.php on line 132
    When I press the ship button in the admin order section.
    I managed to install your fix and I have compilation turned off, plus I have logged out and back in.
    Do I need to flush the cache?

    Also when I have compilation on I get error on the front-end of the site when I click on wishlist, and cart.
    With it turned off it’s fine.

    Don’t I need compilation on though for better performance?
    I have Royal Mail Shipping module installed, could this be the problem?

    Any help would be great.

  13. This saved my bacon. Thanks a bunch!

  14. and now magento vietnam is parked.
    Brick wall.

  15. I had just came across this issue as well, where the core code was working fine on one server, but not on another. Turns out there is a bug in PHP 5.2.9 and less, where the __call() makes the arguments all lowercase. So when making the call getShippingMethod(), PHP changes it to getshippingmethod() where magento then looks for $data['shippingmethod'] instead of $data['shipping_method']. On the working server, we have PHP 5.3, and on the server where it’s broken, our PHP version is 5.2.6. If you upgrade to 5.2.10 or greater, it should start working without having to make an override class or hack the core. Hope this helps.

    https://bugs.php.net/bug.php?id=42937

  16. Thanks,

    works fine in 1.7

  17. Thanks for this fix, makes it easier when troubleshooting to have such a strong support system.

    Keep up the great posting

  18. Hey, thanks for your information !

    I had the same problem and I found a solution without having to change Core classes or install any external module.

    In that case, you can call the function getData() of your order object.

    $orderObject = Mage::getModel(‘sales/order’)->load($order->getRealOrderId(), ‘increment_id’);
    $shipping = $orderObject->getData(‘shipping_method’);

    I hope this will be useful to you.

Leave a comment