2

I'm working with Magento, I have orders and I print them like this:

echo $order->getId();
echo $order->getCustomerEmail();

My problem is that I don't know all the name of the get methods so how or where can I find all the list of get available?

My goal is export all the orders in an external database, is there a faster way to do it without pass for each field?

  • take a look in sales_flat_order table, all field can be accessed via getFieldName (or getData('field_name')) and open the class Mage_Sales_Model_Order doc block help you too – bchatard Nov 30 '15 at 16:34
2

The data on the order (or any object) is being held in a protected member variable _data which is an array. This data comes from the database table(s) (it is being filled by the resource model).

Data array

You can get this array and dump it via:

print_r($order->getData());
// or
var_dump($order->getData());

You will get an output like this with print_r():

Array
(
    [entity_id] => 2
    [state] => new
    [status] => pending
// ...

Getters

Now you can get all of this data with Magento object's magic getters. Each value is retrievable in the form of $object->getValue() where Value is the camel cased version of the key from the array.

For the above values use:

$order->getEntityId();
$order->getState();
$order->getStatus();

And for customer_id for example you can call $order->getCustomerId()

Overrides

The getters can be overridden. The getters construction is defined in the Varien_Object class and each Magento model could override a magic getter method by explicitly defining a method. So you should also check the methods of the model by looking at the code or use hinting in your IDE.

2

You can simply print all available field in your object with:

print_r($order->getData())
  • ok, i used it and it shows a lot of fields but not all that i was looking for. – Luca Caldari Dec 1 '15 at 9:47
1

Orders are not stored in an EAV format so all the data is in a flat table. By loading a sales/order model instance you load a row from the sales_flat_order table so any column you see here, you can pull from the order object, i.e to pull the increment_id column, you can call $order->getIncrementId(). Also be aware that there are some methods in the Mage_Sales_Model_Order class object to build a certain amount of data for you, for instance getCustomerName() which returns the customer name but does not relate to a customer_name column in the sales_flat_order table .

1

Try

foreach($order->getData() as $key => $value)
{
  //$key;
  //$value
}
0

An one line solution:

array_keys($order->getData())
-1
 $resource = Mage::getSingleton('core/resource');
 $readConnection = $resource->getConnection('core_read');  
 /**
  * Get the table name
  */
 $tableName = $resource->getTableName('sales/order');

 $saleafield=$readConnection->describeTable($tableName);
 var_dump($saleafield);

From: https://stackoverflow.com/questions/25245862/get-all-field-names-from-magento-model

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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