4

I am trying to get order details by order id in my code. For this I have created a php file and copy that file to a folder in public_html. this is my code :

<?php 
 error_reporting( E_ALL );
 require_once "lib/nusoap.php";
 require_once "../app/Mage.php";
  try {
   $order = Mage::getModel('sales/order')->load('100000234');
   $orderData = $order->getData();
   print_r($orderData);
  } catch (Exception $e) {
echo 'Caught exception: ',  $e->getMessage(), "\n";
  }
   ?>

But when i run this code, it shows "nothing" to me !

I tried to var_dump($order), but it is also showing nothing and no error !

Can any body help me to get order detail and show it ?

Thanks

0

2 Answers 2

4

There is specific loadByIncrementId function for loading using the increment id.

$order = Mage::getModel('sales/order')->loadByIncrementId('100000234');

However I don't believe you are bootstrapping Magento correctly, which would explain why you aren't necessarily getting what you want. Whilst including the app/Mage.php will give you access to the Mage class, it won't actually bootstrap Magento. You need to init the app, something like this:

<?php 
    error_reporting( E_ALL );
    require_once "lib/nusoap.php";
    require_once "../app/Mage.php";
    Mage::app('admin');
    try {
        $order = Mage::getModel('sales/order')->loadByIncrementId('100000234');
        print_r($order->debug());
    } catch (Exception $e) {
        echo 'Caught exception: ',  $e->getMessage(), "\n";
    }
0
2

The number you are using is the increment_id

In magento you have the sequencial inctement_id, which is the visible order id.

Internally magento uses entity_id, which is used to link data.

The ->load uses the entity_id by default.

If you change your code to

$order = Mage::getModel('sales/order')->load($incrementId, 'increment_id');

You should get the order loaded.

2
  • i chenge my code but no thing chenge ! i use try catch for exeptions but there is no error and no result !
    – mahdi
    Commented Oct 12, 2014 at 9:35
  • Maybe I got the syntax wrong. Out and about, on my phone, so is off the top of my head. You got a potential reason, as in using increment id. Google a bit on how to load order using increments id.
    – ProxiBlue
    Commented Oct 12, 2014 at 10:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.