cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 1.9 - How to get ordered qty/invoiced qty/shipped qty on invoice pdf?

Magento 1.9 - How to get ordered qty/invoiced qty/shipped qty on invoice pdf?

I'm trying to get those qty information on invoice pdf. because i edit the quantities on page for new invoice like this,

1.JPG

 

The real quantities we shipped are 3 and 1.

2222.JPG

 

So i want to get the quantity client ordered and the quantity we shipped as well.

Btw i can't get the ordered quantity in invoice pdf!

333.JPG

 

app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/default.php

class Mage_Sales_Model_Order_Pdf_Items_Invoice_Default extends 
Mage_Sales_Model_Order_Pdf_Items_Abstract
{
/**
 * Draw item line
 */
public function draw()
{
    $order  = $this->getOrder();
    $item   = $this->getItem();
    $pdf    = $this->getPdf();
    $page   = $this->getPage();
    //20170412 edit starts
    //$temporder = Mage::getModel('sales/order_item');
    //$tempitems = $temporder->getAllItems();
    //$quote = $this->getQuote();
    //$temp = $quote->getAllItems();
    //$childItem = $item->getChildren();
    $temp = $order->getAllVisibleItems();
    //20170412 edit ends
    $lines  = array();

    // draw Product name


    // draw SKU
    $lines[0][] = array(
        'text'  => Mage::helper('core/string')->str_split($this->getSku($item), 80),
        'feed'  => 50,
        'align' => 'left'
    );

    //20170412 edit starts
    // draw ordered QTY
    $lines[0][] = array(
        'text'  => $_item['qty_ordered'] ,
        'feed'  => 360,
        'align' => 'right'
    );
    //20170412 edit ends

    // draw QTY
    $lines[0][] = array(
        'text'  => $item->getQty() * 1,
        'feed'  => 435,
        'align' => 'right'
    );

    // draw item Prices
    $i = 0;
    $prices = $this->getItemPricesForDisplay();
    $feedPrice = 230;
    $feedSubtotal = $feedPrice + 280;
    foreach ($prices as $priceData){
        if (isset($priceData['label'])) {
            // draw Price label
            $lines[$i][] = array(
                'text'  => $priceData['label'],
                'feed'  => $feedPrice,
                'align' => 'right'
            );
            // draw Subtotal label
            $lines[$i][] = array(
                'text'  => $priceData['label'],
                'feed'  => $feedSubtotal,
                'align' => 'right'
            );
            $i++;
        }
        // draw Price
        $lines[$i][] = array(
            'text'  => $priceData['price'],
            'feed'  => $feedPrice,
            'font'  => 'bold',
            'align' => 'right'
        );
        // draw Subtotal
        $lines[$i][] = array(
            'text'  => $priceData['subtotal'],
            'feed'  => $feedSubtotal,
            'font'  => 'bold',
            'align' => 'right'
        );
        $i++;
    }

I found that the qty_ordered is in sales_flat_order_item table!

i guess i need to chain the quote_item_id to quantity but i can't do it!

 

Please share your opinion! Thank you!

1 REPLY

Re: Magento 1.9 - How to get ordered qty/invoiced qty/shipped qty on invoice pdf?

Changing anything about Magento's built-in PDFs can be difficult.

 

For this reason, whenever I need to customize a PDF printout, I use the Comwrap_Pdf module. It lets you create your PDFs with regular old HTML templates, then renders them to PDF using the mPDF library. It's free on GitHub.

 

You can see in the invoice template how it accesses the orderItem from the invoiceItem to get the productOptions data. You could use the same method to access the qtyOrdered in that context, then echo it into the table below.

 

https://github.com/comwrap/magento-comwrap-pdf