找到你要的答案

Q:Magento Order Export XML

Q:Magento的出口订单的XML

I am looking for a php file, that can export magento orders to XML format. All the orders.

But not into MS-XML, I need a simple XML exactly like this below.

I need it to be grouped, with more levels. I'm stuck with this since weeks :( Someone please help me! Thank you!

<?xml version="1.0" encoding="iso-8859-2" ?>
<Header>
	<Order_datas>
		<Order_nr>MR4001</Order_nr>
		<Datum>2014.01.03 13:15:49</Datum>
		<Payment_method>wire_transf</Payment_method>
		<Shipping_method>posta</Szallitasi_mod>
		<Customer_note></Customer_note>
		<Header_Customer>
			<Customer_name>Minta Péter</Customer_name>
			<Customer_zip>1037</Customer_zip>
			<Customer_city>Budapest</Customer_city>
			<Customer_address>Duna u. 5.</Customer_address>
			<Shipping_name>Minta Péter</Shipping_name>
			<Shipping_zip>1037</Shipping_zip>
			<Shipping_city>Budapest</Shipping_city>
			<Shipping_address>Duna u. 5.</Shipping_address>
			<Telefon></Telefon>
			<Email>mintapeter@mintapeter.hu</Email>
			<VATNR></VATNR>
		</Header_Customer>
		<Items>
			<Ordered_Items>
				<Product_name>Férfi cipő</Product_name>
				<ID>77866684</ID>
				<SKU></SKU>
				<QTY>1</QTY>
				<QTYINC>pár</QTYINC>
				<Netto_price>20000</Netto_price>
				<TAX>27%</TAX>
				<Discount_percentage>0</Discount_percentage>
			</Ordered_Items>
		</Items>
	</Order_datas>
	<Order_datas>
		<Order_nr>MR4002</Order_nr>
		<Datum>2014.01.04 12:05:49</Datum>
		<Payment_method>készpénz</Payment_method>
		<Shipping_method>személyes átvétel</Szallitasi_mod>
		<Customer_note></Customer_note>
		<Header_Customer>
			<Customer_name>Példa Gábor</Customer_name>
			<Customer_zip>5000</Customer_zip>
			<Customer_city>Szolnok</Customer_city>
			<Customer_address>Somos u. 23.</Customer_address>
			<Shipping_name>Példa Gábor</Shipping_name>
			<Shipping_zip>5000</Shipping_zip>
			<Shipping_city>Szolnok</Shipping_city>
			<Shipping_address>Somos u. 23.</Shipping_address>
			<Telefon>06-70-999-8888</Telefon>
			<Email>pelda.gabor@gmail.com</Email>
			<VATNR></VATNR>
		</Header_Customer>
		<Items>
			<Ordered_Items>
				<Product_name>Villanykapcsoló</Product_name>
				<ID>12345687</ID>
				<SKU></SKU>
				<QTY>2</QTY>
				<QTYINC>db</QTYINC>
				<Netto_price>1000</Netto_price>
				<TAX>27%</TAX>
				<Discount_percentage>0</Discount_percentage>
			</Ordered_Items>
		</Items>
	</Order_datas>
	<Order_datas>
		<Order_nr>MR4003</Order_nr>
		<Datum>2014.01.04 16:01:14</Datum>
		<Payment_method>wire_transf</Payment_method>
		<Shipping_method>posta</Szallitasi_mod>
		<Customer_note></Customer_note>
		<Header_Customer>
			<Customer_name>Kitalált Cég Bt.</Customer_name>
			<Customer_zip>1113</Customer_zip>
			<Customer_city>Budapest</Customer_city>
			<Customer_address>Gesztenye u. 45.</Customer_address>
			<Shipping_name>Fodor Anikó</Shipping_name>
			<Shipping_zip>1113</Shipping_zip>
			<Shipping_city>Budapest</Shipping_city>
			<Shipping_address>Dermák u. 11.</Shipping_address>
			<Telefon></Telefon>
			<Email>kitalalt.ceg.bt@gmail.com</Email>
			<VATNR>13781111-2-43</VATNR>
		</Header_Customer>
		<Items>
			<Ordered_Items>
				<Product_name>Férfi cipő</Product_name>
				<ID>77866684</ID>
				<SKU></SKU>
				<QTY>1</QTY>
				<QTYINC>pár</QTYINC>
				<Netto_price>20000</Netto_price>
				<TAX>27%</TAX>
				<Discount_percentage>0</Discount_percentage>
			</Ordered_Items>
			<Ordered_Items>
				<Product_name>Női ruha</Product_name>
				<ID>12345694</ID>
				<SKU></SKU>
				<QTY>1</QTY>
				<QTYINC>db</QTYINC>
				<Netto_price>10000</Netto_price>
				<TAX>27%</TAX>
				<Discount_percentage>0</Discount_percentage>
			</Ordered_Items>
		</Items>
	</Order_datas>
</Header>

我想找一个PHP文件,可以导出为XML格式的Magento订单。所有订单。

但不到ms-xml,我需要一个简单的XML就像下面。

我需要它进行分组,有更多的层次。几个星期以来我一直在坚持:(有人请帮帮我)!谢谢您!

<?xml version="1.0" encoding="iso-8859-2" ?>
<Header>
	<Order_datas>
		<Order_nr>MR4001</Order_nr>
		<Datum>2014.01.03 13:15:49</Datum>
		<Payment_method>wire_transf</Payment_method>
		<Shipping_method>posta</Szallitasi_mod>
		<Customer_note></Customer_note>
		<Header_Customer>
			<Customer_name>Minta Péter</Customer_name>
			<Customer_zip>1037</Customer_zip>
			<Customer_city>Budapest</Customer_city>
			<Customer_address>Duna u. 5.</Customer_address>
			<Shipping_name>Minta Péter</Shipping_name>
			<Shipping_zip>1037</Shipping_zip>
			<Shipping_city>Budapest</Shipping_city>
			<Shipping_address>Duna u. 5.</Shipping_address>
			<Telefon></Telefon>
			<Email>mintapeter@mintapeter.hu</Email>
			<VATNR></VATNR>
		</Header_Customer>
		<Items>
			<Ordered_Items>
				<Product_name>Férfi cipő</Product_name>
				<ID>77866684</ID>
				<SKU></SKU>
				<QTY>1</QTY>
				<QTYINC>pár</QTYINC>
				<Netto_price>20000</Netto_price>
				<TAX>27%</TAX>
				<Discount_percentage>0</Discount_percentage>
			</Ordered_Items>
		</Items>
	</Order_datas>
	<Order_datas>
		<Order_nr>MR4002</Order_nr>
		<Datum>2014.01.04 12:05:49</Datum>
		<Payment_method>készpénz</Payment_method>
		<Shipping_method>személyes átvétel</Szallitasi_mod>
		<Customer_note></Customer_note>
		<Header_Customer>
			<Customer_name>Példa Gábor</Customer_name>
			<Customer_zip>5000</Customer_zip>
			<Customer_city>Szolnok</Customer_city>
			<Customer_address>Somos u. 23.</Customer_address>
			<Shipping_name>Példa Gábor</Shipping_name>
			<Shipping_zip>5000</Shipping_zip>
			<Shipping_city>Szolnok</Shipping_city>
			<Shipping_address>Somos u. 23.</Shipping_address>
			<Telefon>06-70-999-8888</Telefon>
			<Email>pelda.gabor@gmail.com</Email>
			<VATNR></VATNR>
		</Header_Customer>
		<Items>
			<Ordered_Items>
				<Product_name>Villanykapcsoló</Product_name>
				<ID>12345687</ID>
				<SKU></SKU>
				<QTY>2</QTY>
				<QTYINC>db</QTYINC>
				<Netto_price>1000</Netto_price>
				<TAX>27%</TAX>
				<Discount_percentage>0</Discount_percentage>
			</Ordered_Items>
		</Items>
	</Order_datas>
	<Order_datas>
		<Order_nr>MR4003</Order_nr>
		<Datum>2014.01.04 16:01:14</Datum>
		<Payment_method>wire_transf</Payment_method>
		<Shipping_method>posta</Szallitasi_mod>
		<Customer_note></Customer_note>
		<Header_Customer>
			<Customer_name>Kitalált Cég Bt.</Customer_name>
			<Customer_zip>1113</Customer_zip>
			<Customer_city>Budapest</Customer_city>
			<Customer_address>Gesztenye u. 45.</Customer_address>
			<Shipping_name>Fodor Anikó</Shipping_name>
			<Shipping_zip>1113</Shipping_zip>
			<Shipping_city>Budapest</Shipping_city>
			<Shipping_address>Dermák u. 11.</Shipping_address>
			<Telefon></Telefon>
			<Email>kitalalt.ceg.bt@gmail.com</Email>
			<VATNR>13781111-2-43</VATNR>
		</Header_Customer>
		<Items>
			<Ordered_Items>
				<Product_name>Férfi cipő</Product_name>
				<ID>77866684</ID>
				<SKU></SKU>
				<QTY>1</QTY>
				<QTYINC>pár</QTYINC>
				<Netto_price>20000</Netto_price>
				<TAX>27%</TAX>
				<Discount_percentage>0</Discount_percentage>
			</Ordered_Items>
			<Ordered_Items>
				<Product_name>Női ruha</Product_name>
				<ID>12345694</ID>
				<SKU></SKU>
				<QTY>1</QTY>
				<QTYINC>db</QTYINC>
				<Netto_price>10000</Netto_price>
				<TAX>27%</TAX>
				<Discount_percentage>0</Discount_percentage>
			</Ordered_Items>
		</Items>
	</Order_datas>
</Header>
answer1: 回答1:

Why dont you create your own module with a Model which can be called everywhere (Observer, shell, cron ...) and on this model add a function like above :

public function send() {
    $orders = Mage::getModel('sales/order')->getCollection()
            ->addFieldToFilter('status', array('in' => array('processing', 'paid')));

   $dom = new DOMDocument('1.0', 'utf-8'); 
   $ordersElmt = $dom->createElement('header');
   foreach ($orders as $order) { /** @var $order Mage_Sales_Model_Order */
            $orderElmt = $dom->createElement('Order_datas');
            $orderIdElmt = $dom->createElement('Order_nr', $order->getId());
// And add your other nodes
            $ordersElmt->appendChild($orderElmt);
            }
   $dom->save("/path/to/your/folder/file.xml");
        }

You 'll need to change the order status in the code somewhere if you dont want to have every orders at every launch $order->setStatus("yourstatus");

你为什么不跟一个可以称之为到处模型创建自己的模块(观察员、壳、玉米…),在这个模型中添加一个函数像上面:

public function send() {
    $orders = Mage::getModel('sales/order')->getCollection()
            ->addFieldToFilter('status', array('in' => array('processing', 'paid')));

   $dom = new DOMDocument('1.0', 'utf-8'); 
   $ordersElmt = $dom->createElement('header');
   foreach ($orders as $order) { /** @var $order Mage_Sales_Model_Order */
            $orderElmt = $dom->createElement('Order_datas');
            $orderIdElmt = $dom->createElement('Order_nr', $order->getId());
// And add your other nodes
            $ordersElmt->appendChild($orderElmt);
            }
   $dom->save("/path/to/your/folder/file.xml");
        }

You 'll need to change the order status in the code somewhere if you dont want to have every orders at every launch $order->setStatus("yourstatus");

answer2: 回答2:

<?php
require_once 'abstract.php'; 
class dom_Shell_Import extends Mage_Shell_Abstract {  


public function run() {
    $orders = Mage::getModel('sales/order')->getCollection()
	
	->addFieldToFilter('status', array('in' => array('pending', 'paid')));
	#->addFieldToFilter('increment_id', array('in' => array()));
     
	
            

    $dom = new DOMDocument('1.0', 'UTF-8');
	$header = $dom->createElement("header");
    $header = $dom->appendChild($header);

   foreach ($orders as $order) { 
    
	$Order_number = $dom->createElement("Order_number", $order->getid());
    $Order_number = $header->appendChild($Order_number);
	
	$Customer_firstname = $dom->createElement("Customer_firstname", $order->getFirstname());
    $Customer_firstname = $header->appendChild($Customer_firstname);		
			
            }
   $dom->save("file.xml");
        }
	
	}$shell = new dom_Shell_Import(); $shell->run();

<?php
require_once 'abstract.php'; 
class dom_Shell_Import extends Mage_Shell_Abstract {  


public function run() {
    $orders = Mage::getModel('sales/order')->getCollection()
	
	->addFieldToFilter('status', array('in' => array('pending', 'paid')));
	#->addFieldToFilter('increment_id', array('in' => array()));
     
	
            

    $dom = new DOMDocument('1.0', 'UTF-8');
	$header = $dom->createElement("header");
    $header = $dom->appendChild($header);

   foreach ($orders as $order) { 
    
	$Order_number = $dom->createElement("Order_number", $order->getid());
    $Order_number = $header->appendChild($Order_number);
	
	$Customer_firstname = $dom->createElement("Customer_firstname", $order->getFirstname());
    $Customer_firstname = $header->appendChild($Customer_firstname);		
			
            }
   $dom->save("file.xml");
        }
	
	}$shell = new dom_Shell_Import(); $shell->run();
answer3: 回答3:
<?php

require_once 'abstract.php';

class dom_Shell_Import extends Mage_Shell_Abstract {

public function run() {
    $orders = Mage::getModel('sales/order')->getCollection()
            ->addFieldToFilter('status', array('in' => array('pending', 'paid')));
    #->addFieldToFilter('increment_id', array('in' => array()));

    $dom = new DOMDocument('1.0', 'UTF-8');
    $header = $dom->createElement("header");
    $dom->appendChild($header);

    foreach ($orders as $order) {
        $order_data = $dom->createElement("Order_datas");
        $header->appendChild($order_data);
        /*order Data */
        $Order_number = $dom->createElement("Order_number", $order->getIncrementId());
        $Order_date = $dom->createElement("Datum", $order->getCreatedAt());
        $order_data->appendChild($Order_number);
        $order_data->appendChild($Order_date);

        /* Customer Data */
        $customer_header = $dom->createElement("Header_Customer");
        $order_data->appendChild($customer_header);

        $Customer_name = $dom->createElement("Customer_name", $order->getCustomerName());
        $customer_header->appendChild($Customer_name);
        /* products data */
        $Items = $dom->createElement("Items");
        $order_data->appendChild($Items);
        $ordered_items = $order->getAllItems();
        foreach ($ordered_items as $ordered_item) { /*loop throught the ordered item */
            $Ordered_Items = $dom->createElement("Ordered_Items");
            $Items->appendChild($Ordered_Items);
            $sku = $dom->createElement("SKU", $ordered_item->getSku());
            $Ordered_Items->appendChild($sku);
            $qty = $dom->createElement("QTY", (int) $ordered_item->getQtyOrdered());
            $Ordered_Items->appendChild($qty);
        }
    }
    $dom->save("file.xml");
}

}

$shell = new dom_Shell_Import();
$shell->run();

I added some line to be more readeable. Now with this you should have some more line to your xml file

<?php

require_once 'abstract.php';

class dom_Shell_Import extends Mage_Shell_Abstract {

public function run() {
    $orders = Mage::getModel('sales/order')->getCollection()
            ->addFieldToFilter('status', array('in' => array('pending', 'paid')));
    #->addFieldToFilter('increment_id', array('in' => array()));

    $dom = new DOMDocument('1.0', 'UTF-8');
    $header = $dom->createElement("header");
    $dom->appendChild($header);

    foreach ($orders as $order) {
        $order_data = $dom->createElement("Order_datas");
        $header->appendChild($order_data);
        /*order Data */
        $Order_number = $dom->createElement("Order_number", $order->getIncrementId());
        $Order_date = $dom->createElement("Datum", $order->getCreatedAt());
        $order_data->appendChild($Order_number);
        $order_data->appendChild($Order_date);

        /* Customer Data */
        $customer_header = $dom->createElement("Header_Customer");
        $order_data->appendChild($customer_header);

        $Customer_name = $dom->createElement("Customer_name", $order->getCustomerName());
        $customer_header->appendChild($Customer_name);
        /* products data */
        $Items = $dom->createElement("Items");
        $order_data->appendChild($Items);
        $ordered_items = $order->getAllItems();
        foreach ($ordered_items as $ordered_item) { /*loop throught the ordered item */
            $Ordered_Items = $dom->createElement("Ordered_Items");
            $Items->appendChild($Ordered_Items);
            $sku = $dom->createElement("SKU", $ordered_item->getSku());
            $Ordered_Items->appendChild($sku);
            $qty = $dom->createElement("QTY", (int) $ordered_item->getQtyOrdered());
            $Ordered_Items->appendChild($qty);
        }
    }
    $dom->save("file.xml");
}

}

$shell = new dom_Shell_Import();
$shell->run();

我更readeable添加一些线。现在,您应该有更多的行到您的XML文件

php  xml  magento  order  export