0

When i print multiple invoices, i add new PDF page and on that page i print Invoice number, order number, and Total amount. enter image description here And to do this i did code `foreach ($invoices as $invoice) {

        array_push($this::$invs,$invoice);
    }
    $grandtotal = 0;
    for($i=0;$i<sizeof($this::$invs);$i++){

        $order = $this::$invs[$i]->getOrder();
        $amount = $order->getGrandTotal();
        $grandtotal = $grandtotal + $amount;
        $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));

        $page->drawText('Inc#: '.$this::$invs[$i]->getIncrementId().'        Ordr#: '.$this::$invs[$i]->getOrderId().'      Total Amount: '.$amount, 20, $this::$p, 'UTF-8');
        $this::$p=$this::$p-15;
    }`

in app/code/local/Mage/sales/Model/order/pdf/invoice.php and it's working fine. Now i want to add shipping address of every order with it. As you see that i got invoice Id's not Order Id's. If any one can help please.

5
  • Do you have your order id?
    – Mujahidh
    Jan 6, 2017 at 11:31
  • No, i don not have it. And that thing is making problem. @mujas
    – Ali Zaki
    Jan 6, 2017 at 11:47
  • what do you expect to do?
    – Mujahidh
    Jan 6, 2017 at 11:51
  • See the edit please. @mujas
    – Ali Zaki
    Jan 6, 2017 at 12:12
  • 1
    you have your order increment id, you can follow fabian's answer
    – Mujahidh
    Jan 6, 2017 at 12:15

2 Answers 2

1

Using Magento models, you have to take multiple steps:

  1. load the invoice by number $number

    $invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($number);
    
  2. load order from invoice

    $order = $invoice->getOrder();
    
  3. load shipping address from order

    $shipping = $order->getShippingAddress();
    
  4. finally, get the street

    $shipping->getStreet();
    

Update: I see you updated your question with code. You already loaded the order $order, so you can start with step (3).

2
  • I follow your method from step (3). When i draw this on PDF $page->drawText('Address: '.$shipping->getStreet(), 20, $this::$p-200, 'UTF-8');. On PDF it shows "Address: Array"
    – Ali Zaki
    Jan 6, 2017 at 12:21
  • 1
    Oh, the street is returned as array of lines (usually one element, but you can have one or more "additional address" fields). To display it in one line, use implode(' ', $shipping->getStreet()), or to display it in multiple lines in the pdf, foreach over $shipping->getStreet() and call $page->drawText() for each line. Jan 6, 2017 at 12:24
0

Load Invoice using your Invoice Number:

$invoice = Mage::getModel('sales/order_invoice')->load($id); 
$order = $invoice->getOrder();  //Get order details

Then

$address = $order->getShippingAddress();    
$custName = $address->getName();
$custAddr = $address->getStreetFull();
$region = $address->getRegion();
$country = $address->getCountry();
2
  • I am in the situation that i don't have Order ID . I have to get address by Invoice number. Please tell me if you got a solution for this.
    – Ali Zaki
    Jan 6, 2017 at 11:46
  • I updated my answer. Check it , If this helps you.
    – BornCoder
    Jan 6, 2017 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.