Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

magento2 get full details of order collection

<?php
ini_set('display_errors', 1);
ini_set('memory_limit', '160000M');
ini_set('max_execution_time', 0);

use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';

$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');

$order_coll = $obj->get('MagentoSalesModelOrder')->getCollection();
$order_coll->getSelect()
    ->join(array('order_item' => 'sales_order_item'),
        'order_item.order_id = main_table.entity_id',getColumns('sales_order_item', 'soi_'));
$order_coll->getSelect()
->join(array('sales_grid'=>'sales_order_grid'),
        'sales_grid.entity_id=main_table.entity_id',getColumns('sales_order_grid','sog_'));
foreach ($order_coll as $entity) {
    echo "<pre>";
    print_r($entity->getData());
    echo "</pre>";
}
function getColumns($table,$prefix)
{
    $resource = $GLOBALS['obj']->get('MagentoFrameworkAppResourceConnection');
    $connection = $resource->getConnection();
    $sql = "SHOW COLUMNS FROM `$table`;";
    $result = $connection->fetchAll($sql);
    $columns = array();
    for ($i = 0; $i < count($result); $i++) {
        array_push($columns,$result[$i]['Field']." as ".$prefix.$result[$i]['Field']);
    }
    return $columns;
}
?>
 
PREVIOUS NEXT
Tagged: #full #details #order #collection
ADD COMMENT
Topic
Name
2+8 =