1

I am getting this issue now. I can pass the productId but the foreach it looks like it does not work, When customer order 2 items the result i get is just the last item productId.

Here is the code:

class Order_OrderExport_Model_Export
{

    public function exportOrder($order,$sku) 
    {
        $dirPath = Mage::getBaseDir('var') . DS . 'export';

        if (!is_dir($dirPath)) {
            mkdir($dirPath, 0777, true);
        }

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

        $data = array(

            'getIncrementId'        => $order->getIncrementId(),
            'created_at'            => $order->getCreatedAt(),
            'customer_id'           => $order->getCustomerId(),
            'customer_firstname'    => $order->getCustomerFirstname(),
            'customer_lastname'     => $order->getCustomerLastname(),
            'customer_email'        => $order->getCustomerEmail(),

            'telephone'             => $order->getBillingAddress()->getTelephone(),
            'street'                => $order->getBillingAddress()->getStreet(),
            'get_city'              => $order->getBillingAddress()->getCity(),
            'postcode'              => $order->getBillingAddress()->getPostcode(),
            'region'                => $order->getBillingAddress()->getRegion(),
            'get_country'           => $order->getBillingAddress()->getCountry(),

            'tax_amount'            => $order->getTaxAmount(),
            'shipping_amount'       => $order->getShippingAmount(),
            'remote_ip'             => $order->getRemoteIp(),

            'total_qty_ordered'     => $order->getTotalQtyOrdered(),
            'subtotal'              => $order->getSubtotal(),
            'grand_total'           => $order->getGrandTotal(),
            'order_currency_code'   => $order->getOrderCurrencyCode(),

    //Here is the output of the items

            'item'                  => $item->getProductId(),

            );


        $xml = new SimpleXMLElement('<root/>');
        array_walk_recursive($data, array ($xml, 'addChild'));
        file_put_contents(
        $dirPath. DS .$order->getIncrementId().'.xml', 
        $xml->asXML()

        );
     }

}

The XML i am outputting display only on product. Thank you

  • which event is observed by exportOrder? – FlorinelChis Oct 10 '13 at 16:11
  • This event: sales_order_place_after – DanielDake Oct 10 '13 at 16:13
  • do a print_r($order->getData()) ... what do you get in there? Can you see the fields you were looking for? – FlorinelChis Oct 10 '13 at 16:29
  • Try with sales_order_place_before event – Sukeshini Oct 10 '13 at 17:15
  • When i export in xml there are everything beside Address,City,Phone kind of personal information this happen when i print_r($order->getData()) too, i can't even get the product name just the entity_id of the product – DanielDake Oct 10 '13 at 17:35
1

The address details are stored separately. Try with either

$order->getBillingAddress()->getCity()

or

$order->getShippingAddress()->getCity()

depending on your requirements.

|improve this answer|||||
  • you are genius, that worked. What i did til now was this far $order->getShippingAddress() and no result the ->getCity did the trick. I guess is the same thing for product details too? Thank you very much – DanielDake Oct 10 '13 at 20:11
  • For order items you want something like foreach ($order->getAllItems() as $item){ $item->getName();} – Kristof at Fooman Oct 10 '13 at 20:13
  • Do i really need a foreach because i have an event sales_order_place_after or you mean because customer may order more than one item? Thank you – DanielDake Oct 10 '13 at 20:21
  • You asked about the ordered items - so yes the foreach is needed since an order might contain more than 1 ordered item. If you really wanted to get the original product you would additionally need to use $product = Mage::getModel('catalog/product')->load($item->getProductId()); – Kristof at Fooman Oct 10 '13 at 22:04
  • At Fooman, Please i have edited the code and trying to output the productid. I get only the last productid on the xml result not multiple orders. Do you have any idea of this issue Fooeman? I have updated the code above. I must miss something there. Thank you – DanielDake Oct 15 '13 at 14:14

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.