0
votes

I need to include the Configurable Product SKU on all print invoices as the configurable product SKU is human readable but the simple products are 16 digit numerical barcodes which makes for picking products a nightmare.

I've found /app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php which writes the document. In it, it has the following which I believe creates the file.

    $page->drawText(Mage::helper('sales')->__('Product'), 35, $this->y, 'UTF-8');
    $page->drawText(Mage::helper('sales')->__('SKU'), 255, $this->y, 'UTF-8');
    $page->drawText(Mage::helper('sales')->__('Price'), 380, $this->y, 'UTF-8');
    $page->drawText(Mage::helper('sales')->__('Qty'), 430, $this->y, 'UTF-8');
    $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8');
    $page->drawText(Mage::helper('sales')->__('Subtotal'), 535, $this->y, 'UTF-8');

My question is how can I change 'SKU' to be the configurable product SKU. All products in my store are configurable so it's not an issue it overrides the simple product sku.

Thanks.

3

3 Answers

1
votes

Magento saves two order items for each configurable product sold. You can see this in the sales_flat_order_item table. However, you'll notice that the SKU on both of those items is the same... the simple SKU. So, unfortunately, there isn't a simple way to get the configurable product's SKU, but it can be done.

  1. Find where the order items are loaded*. Look for:

    $order/$invoice->getAllItems()

  2. Get the product_id of the configurable product using the product_id stored with the order_item

    $item->getProductId()

  3. Load the configurable product

    $product = Mage::getModel('catalog/product')->load($product_id_from_step2)

  4. Set** the SKU on the order_item to be the SKU from the real product

    $item->setSku($product->getSku())

*- This is somewhere in the file you referenced in your question. Note, however, that the code you have above is actually displaying the table's header row, not the actual product data.

**- This isn't saving anything to the database unless you call $item->save(). You are just modifying the object loaded in memory temporarily

0
votes

Just go to this file app\code\core\Mage\Sales\Model\Order\Pdf\Items\Invoice\Default.php here you can find sku field, print $item array you will get what you needed

0
votes

You could provide your own PDF renderer for product type simple and then lookup the configurable product etc.

Create a custom extension add this to your config.xml

<global>

    <pdf>
        <invoice>
            <simple>invoice/sales_order_pdf_items_invoice_simple</simple>
        </invoice>
    </pdf>
</global>

Create the file in your extension. Sales\Order\Pdf\Items\Invoice\Simple.pdf

<?php
class YourModule_Invoice_Model_Sales_Order_Pdf_Items_Invoice_Simple extends     Mage_Sales_Model_Order_Pdf_Items_Abstract
{

    public function draw()
    {
        $order  = $this->getOrder();
        $item   = $this->getItem();
        $pdf    = $this->getPdf();
        $page   = $this->getPage();
        $lines  = array();

        // Render your PDF. Look in parent class for examples.
    }
}