0

I am working on Magento ver 1.9.2.3, And I want to export a order csv per order in header record and detail record format.

See Image for better Understanding

What i have done till now

I have created a custom module which export csv per order on a click through actions in order grid. i am getting all values whichever I need. but all these values lies in a same line.

My main problem is the format of the csv, these header and detail records(of which i have no knowledge) will be used for godrej Navision.

Here Header Record will hold the user data which will be followed by "H" whereas Detail Record will hold the order details per item and followed by "D".

If someone has any idea about these please help me out.

Regards Lalit

1

What i have done so far, And that make my day.

private function _prepareData($templateLine)
    {
        //$this->_customcsv = array();

        //iterate on the orders selected
        foreach($this->_collectionOrders as $order) {

            $lineItem = "";
            $products_line = "";
            $i = 0;

            // iterate on the itens in template
            foreach($templateLine as $t) {

                // order.increment_id => $order->getData("increment_id");
                // getAttributeByCode($attribute, $order)
                $item = "";
                list($object, $attribute) = explode(".", $t);

                switch($object) {

                    case "order":

                        $item = $order->getData($attribute);
                        $this->_csvname = 'Order-'.$order->getIncrementId().'.csv';
                        break;

                    case "customer":

                        if ($attribute=="name") {
                            $item = $order->getData("customer_firstname") . " " .
                            $order->getData("customer_lastname");
                        } else {
                            $item = $order->getData("customer_{$attribute}");
                        }

                    break;

                    case "address":

                        $address = $order->getShippingAddress();

                        if (strpos($attribute, "street_")!==false) {
                            $street = explode("_", $attribute);
                            $item = $address->getStreet($street[1]);
                        } else {
                            $item = $address->getData($attribute);
                        }

                    break;
                }

               // $lineItem.="{$item},";
              // echo  $lineItem ="{$item},"; exit;
               if($i++ == 0)
               {
                   $lineItem .= '"'."H".'",';
               }
               $lineItem .= '"'."{$item}".'",';
            }
            $this->_contentCSV .= $lineItem ."\n\n";
            //$this->_customcsv[] = $lineItem ."\n\n";
            array_push($this->_customcsv, $lineItem ."\n\n");
            // add products ordered
            $ordered_items = $order->getAllItems();
            $line = array();
            $_prod = array();
            $incriment = 10000;
                foreach($ordered_items as $order_items){
                $_orderId = $order->getIncrementId();
                $_name = $order_items->getName();
                $_sku = $order_items->getSku();
                $_qty = intval($order_items->getQtyOrdered());
                $_tax = $order_items->getTaxAmount();
                $_price = $order_items->getPrice();
                $_discount = $order_items->getDiscountAmount();
                $_price_final = $order_items->getBaseRowTotal();

                //array_push($_prod, $_sku . " - " . $_name . " (" . $_qty . ")");
                //$line[] = implode(",", $_prod)."\n";
                $this->_contentCSV .= '"D","HO",'.'"'.$_orderId.'",'.'"'.$incriment.'",'.'"'.$_sku.'",'.'"'.$_qty.'",'.'"'.$_tax.'",'.'"'.$_price.'",'.'"'.$_discount.'",'.'"'.$_price_final.'"'."\n";
                $dtt = '"D","HO",'.'"'.$_orderId.'",'.'"'.$incriment.'",'.'"'.$_sku.'",'.'"'.$_qty.'",'.'"'.$_price.'",'.'"'.$_price_final.'"'."\n";
                //$this->_contentCSV .= '"D","HO",'.'"'.$_sku.'",'.'"'.$_name.'",'.'"'.$_qty.'",\n'";
                $this->_customcsv['products'][] = $dtt;
                //array_push($this->_customcsv[], $dtt);
                $incriment = $incriment+10000;
            }
            // wrap in quotes to keep in one CSV cell
            //echo '<pre>'; print_r($products_line); exit;

            // endline

        }
    }

this is soo messy, anyone have better idea?

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.