Magento Forum

[SOLVED] Export orders
 
r3volution11
Jr. Member
 
Total Posts:  20
Joined:  2009-04-12
 

Alright alright alright. How in the pooper do we get the order date? smile

I’ve been searching the internet for all of the potential values we can get from Magento and I can not for the life of me find a full list.

 
Magento Community Magento Community
Magento Community
Magento Community
 
elfling
Enthusiast
 
Avatar
Total Posts:  901
Joined:  2008-10-21
 

return $orderMag->getCreatedAt();
 
Magento Community Magento Community
Magento Community
Magento Community
 
elfling
Enthusiast
 
Avatar
Total Posts:  901
Joined:  2008-10-21
 

Also I’ve added onto line 227 of includes.php so that if in the order address an & appears, it doesn’t break the.

$xml preg_replace('/(&)/'"&"$xml);
 
Magento Community Magento Community
Magento Community
Magento Community
 
elfling
Enthusiast
 
Avatar
Total Posts:  901
Joined:  2008-10-21
 

str_replace("_", “, “,$_GET[’orderlist’])

So after coming back to this, this is what creates the exported id’s.. how do i change this to get the increment id.. or am i going to have to figure this out for myself..

/* START - Export selected orders */
 if ($_GET['type']=="custom"{
 
if ($_GET['orderlist']!=""{
 $orderlist 
split("_",$_GET['orderlist']);  $o=0;  $forNick '';  foreach ($orderlist as $currentorder{
   $o
++;
   
$orderMag Mage::getModel('sales/order')->load($currentorder);
   
$forNick .= $orderMag->getRealOrderId().", ";
   
$xmlString.=
"<$orderTXT>".array2xml($currentsample[$ordersTXT][$orderTXT])."</$orderTXT>";
 
}

       
foreach ($orderMag->getAllItems() as $item{

      }
      
//print_r($item);
 
$msg "<div style=\"background:rgb(255249233);colorrgb(235940);text-align:center;padding:3px;\">Exported orders: ".
substr($forNick0, -2). " with ".$_GET['sample']." sample</div>";

 
saveExportsFile($_GET['sample'],"Exported orders: "substr($forNick0, -2),$filename,getLastId());  else {$msg '<div style="background:rgb(255, 249, 233);color:
rgb(235, 94, 0);text-align:center;padding:3px;">No selected order(s)</div>'
;}  }
 
/* END - Export selected orders */
 
Magento Community Magento Community
Magento Community
Magento Community
 
NylonAdmiral
Jr. Member
 
Total Posts:  9
Joined:  2009-02-04
 

Hi All,

I have got this all working great now except for one last detail whaich I cannot figure out.

I have modified this slightly so that when you click “export orders since last export”, the exported orders are emailed to an email address.  However, I would really like to make this process automated, possibly with a cron job or something so that approximately every 15 minutes or so it would be as if the “export orders since last export” had been pressed.  This would obviously automate my whole process and mean I wouldn’t have to keep logging in to the Admin page to click the button.

Unfortunately I have’nt the slightest idea how to implement this so any help or suggestions on how to effectively automate the “export orders since last export” process would be REALLY appreciated.

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
engine10
Jr. Member
 
Total Posts:  12
Joined:  2009-02-17
 

Hey great work guys have this working great! The odd order seems to die on items that rely on the getbillingaddress() function saying gertName() etc isn’t an object .. but I think that’s some problem with a field in those orders.

My question is, how would I pull customer information from getCustomer() into this export?  I have a custom field added that users enter on signup and would like to export this.. it’s stored in the customer account information pane though and normally would be accessed through:

$this->getCustomer()->getCustomfield();

I know that currently the order is addressed through $orderMag, item through $item etc, but does anyone know how I’d go about pulling customer information into this.. something like $this->getOrder()->getCustomer()?

Any help would be fantastic, thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
NEURVANA Edge
Jr. Member
 
Avatar
Total Posts:  19
Joined:  2010-03-09
 

Does this work for 1.4.0.1?

 
Magento Community Magento Community
Magento Community
Magento Community
 
engine10
Jr. Member
 
Total Posts:  12
Joined:  2009-02-17
 

I’ll bump that question—based on my previous experience with Magento I’m going to err on the side of it breaking with 1.4

 
Magento Community Magento Community
Magento Community
Magento Community
 
SDAdam
Jr. Member
 
Total Posts:  1
Joined:  2010-04-14
 

Hey, this script is awesome!

Thank you so much, and to everyone who has contributed.

I’m hoping one of you guys will be able to help me out, I’m trying to retrieve the SKU for a certain item, but:

case “getsku”:
return $item->getSku();

Returns the parent Item sku instead of the child item I want.

For example I have Black_Shirt as a parent item, and it’s sub items are Black_Shirt_Small, and Black_Shirt_Medium.

Black_Shirt has a SKU of 1234BLK
Black_Shirt_Small has a SKU of 1234BLKSm
Black_Shirt_Medium has a SKU of 1234BLKMe

The customer orders one of the two child products, but the call to getSku() returns 1234BLK instead of the Sm or Me versions of the SKU.

Any thought on how I can access the SKU for the children would be much appreciated. I read the whole thread, and there are mentions to getSku() returning a chain with SKU-SKU but that isn’t happening for me, that would actually be great!

Thank you so much for any help.

Adam

 
Magento Community Magento Community
Magento Community
Magento Community
 
BrunoDG
Jr. Member
 
Total Posts:  1
Joined:  2010-05-21
 

Hi everybody,

I’m new to Magento and I would like to use this export feature but I have to questions about the installation:
STEP3:
create a folder called ‘export’ in the root folder (of the server)

Do I need to create this folder on the C-drive of the server?

(make a htaccess protection on the export folder...)
Can someone tell me what I need to do with this step?

As I said, I’m a newbie so please be patient with me wink

Btw: I see the newly created controls on the “sales/orders” page but so far nothing happens when I try to execute an export. The main screen is shown after I click on the “Export” link…

 
Magento Community Magento Community
Magento Community
Magento Community
 
newebsmith
Jr. Member
 
Total Posts:  5
Joined:  2010-06-02
 

I have read this whole thread and implemented the solution szotyi created and it works fine in our 1.3.2.4 version. As a few others mentioned we also needed to have the data made available in a csv file, so I created a solution for that which I thought I’d share. This is what I did:

1. First I created a file I called xml_parser_multi.php which looks like this:

<?php
// get name of XML file
$file $_GET['if'];

//set path of where to find xml file
$file_path "export/" $file;

//get file name without xml extension to add csv extension to it
$split_file explode('.',$file);

//set csv headers
header("Content-Type: application/csv");
header("Content-disposition: attachment; filename=" $split_file[0] .".csv");
header("Pragma: no-cache");
header("Expires: 0");

// load file
$xml simplexml_load_file($file_path) or die ("Unable to load XML file!");

//create column headers for csv file
$csvData "Order Nbr,Date,Name,Company,Street,City,State,Zip,Gr Total,Shipping,Sku1,Name1,Price1,Qty1,Item Tot1,Sku2,Name2,Price2,Qty2,Item Tot2,Sku3,Name3,Price3,Qty3,Item Tot3,Sku4,Name4,Price4,Qty4,Item Tot4,Sku5,Name5,Price5,Qty5,Item Tot5\n";

//set reverse counter to keep track of number of columns for each record
$col_tot 25;

// access XML data
foreach($xml->order as $odata){    
    $csvData 
.= $odata->orderinfo->oredid ",";
    
$csvData .= $odata->orderinfo->orderdate ",";
    
$csvData .= str_replace(","," -",$odata->orderinfo->billingname) . ",";
    
$csvData .= str_replace(","," -",$odata->orderinfo->ordercompany) . ",";
    
$csvData .= str_replace(","," -",$odata->orderinfo->billingstreet) . ",";
    
$csvData .= $odata->orderinfo->billingcity ",";
    
$csvData .= $odata->orderinfo->billingstate ",";
    
$csvData .= $odata->orderinfo->billingzip ",";
    
$csvData .= number_format($odata->grandtotal,2,'.','') . ",";
    
$csvData .= number_format($odata->shippingamount,2) . ",";
    foreach(
$odata->items->item as $item_data){
        $csvData 
.= $item_data->sku .",";
        
$csvData .= str_replace(","," -",$item_data->name) .",";
        
$csvData .= number_format($item_data->price,2,'.','') .",";
        
$csvData .= number_format($item_data->qty) .",";
        
$csvData .= number_format($item_data->rowtotal,2,'.','') .",";
        
$col_tot $col_tot 5;
        
}
    $i
=0;
    while(
$i $col_tot){
        $csvData 
.= ",";
        
$i++;
        
}    
    $csvData 
.= "\n";
    
$col_tot 25;
    
}

//display the data    
echo $csvData;
?>

I’ve commented it well and thinks it’s fairly self explanatory. One thing I should make note of is I had to use the str_replace() function to remove any commas from any fields that could possible have one. Otherwise any record which has commas in their fields will throw off your csv display.

Also, you will need to edit the file for the fields that you have included in your xml file download.

2. Place this file in the root directory.

3. Open up the includes.php file found in app/design/adminhtml/default/default/template/widget/grid/
and find the following code:

<tr'.$second.'>
     <
td width="250" valign="middle">'. $date. '</td>
     <
td width="100" valign="middle">'. $sample. '</td>
     <
td  valign="middle">'. $desc. '</td>
     <
td width="50" valign="left"><a href="/export/'.$file.'" target="_blank">Download</a></td>
   </
tr>

This can be found around line 290

Change it to:

<tr'.$second.'>
     <
td width="150" valign="middle">'. $date. '</td>
     <
td width="100" valign="middle">'. $sample. '</td>
     <
td width="250" valign="middle">'. $desc. '</td>
     <
td width="50" valign="left"><a href="/xml_parser_multi.php?if='.$file.'" target="_blank">Download csv</a></td>
     <
td width="50" valign="left"><a href="/export/'.$file.'" target="_blank">Download xml</a></td>
   </
tr>

This creates the extra link

Download csv

in sales->orders in the magento admin panel and changes the

Download

link to

Download xml

to differentiate between the two downloads.

Now when you click on

Download csv

it’ll open the download dialog box and will open the file up in an excel spreadsheet.
 
Magento Community Magento Community
Magento Community
Magento Community
 
siemed
Jr. Member
 
Total Posts:  12
Joined:  2010-01-27
 

Hi, I want to thank you very much for this tool. It really saves me a lot of work.

Just one question, maybe somebody can help me.
I want to have an extra column in the XML sheet that has a fixed bit of text.

It probably is very easy to do, but I\’m not very good with PHP.

I tried to put in the Includes.php an extra line with case / echo, but the that does not work.

Any help would be great!

 
Magento Community Magento Community
Magento Community
Magento Community
 
gkadmin
Member
 
Total Posts:  51
Joined:  2009-07-07
 

Hi,
I have a problem with the export mentioned before: The getsku function displays the parent SKU of a configurable product.
Instead of TXX-33 (the ordered simple product) it shows TXX (the configurable product).

So there is no way to know which product really was ordered.

I hope you can help.
-g

 
Magento Community Magento Community
Magento Community
Magento Community
 
gkadmin
Member
 
Total Posts:  51
Joined:  2009-07-07
 

Ok, solved it myself:

In order to export the simple product SKU of configurable products:

in includes.php replace

case "getsku"
return 
$item->getSku();

with

case "getsku"
         if (
$item->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE{
             
return $item->getProductOptionByCode('simple_sku');
        
else {
         
return $item->getSku();}

If you want to show the simple SKU in the sales view grid (in the backend), too:

copy “app\design\adminhtml\default\default\template\sales\items\column\name.phtml”
to “app\design\adminhtml\default\customtheme\template\sales\items\column\name.phtml”

replace code line 35

<?php echo implode('<br />'Mage::helper('catalog')->splitSku($this->htmlEscape($this->getSku()))); ?>

with:

<!--show simple SKUtoo!-->
    
<?php 
    
if ($this->getItem()->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE{
        
echo implode('<br />'Mage::helper('catalog')->splitSku($this->htmlEscape($this->getItem()->getProductOptionByCode('simple_sku'))));            
        
else {
            
echo implode('<br />'Mage::helper('catalog')->splitSku($this->htmlEscape($this->getItem()->getSku())));
       
}
    ?>

Hope someone can use this.
-g

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ed.Madrigal
Jr. Member
 
Avatar
Total Posts:  12
Joined:  2010-06-29
 
NylonAdmiral - 12 February 2010 05:01 AM

Hi All,

I have got this all working great now except for one last detail whaich I cannot figure out.

I have modified this slightly so that when you click “export orders since last export”, the exported orders are emailed to an email address.  However, I would really like to make this process automated, possibly with a cron job or something so that approximately every 15 minutes or so it would be as if the “export orders since last export” had been pressed.  This would obviously automate my whole process and mean I wouldn’t have to keep logging in to the Admin page to click the button.

Unfortunately I have’nt the slightest idea how to implement this so any help or suggestions on how to effectively automate the “export orders since last export” process would be REALLY appreciated.

Thanks.

bump

Has anyone been able to run this with cron?

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