3

I'd like to list the item subtotal for the items, and then the grand total beneath - much like the invoice PDF does.

I'm failing to tackle both problems:

  1. I've edited /app/code/local/Mage/Sales/Model/Order/Pdf/Items/Shipment/Default.php from the invoice example but unfortunately $priceData['subtotal'] is zero.

    It appears to me this is because that higher up the stack I need to be adding various calls but it feels wrong to be duplicating so much code when the invoice object has this info already.

  2. Simply adding $this->insertTotals($page, $shipment); just lists zeros, presumably because the subTotals mentioned in -1- are zero.


Can someone help direct me to a solution please?

1

As you have found out there is no easy solution. As it is Magento simply does not calculate any totals for the shipment (which the packing slip pdf is based on). For example if you compare on the database level the tables sales_flat_shipment to sales_flat_invoice you will notice that the shipment does not include any currency amounts.

If you wanted to tackle this completely you would need to do a lot of things including

  1. adding the required database fields to both sales_flat_shipment and sales_flat_shipment_item
  2. write the code that actually runs the total calculation - if you look into app/code/core/Mage/Sales/etc/config.xml

    you will find global/sales/quote/totals
    global/sales/order_invoice/totals
    global/sales/order_creditmemo/totals
    but again nothing for shipments. You would need to implement the calculation classes for each new total as well.

  3. once the above is done you could then pull in the numbers into the packing slip pdf like you have already done

If, and only if, you are always shipping all ordered items you could use a shortcut. Instead of printing the packing slip based on the shipment object you could print the packing slip based on the order item (this way you have access to the calculated figures).

Changing
$this->_drawItem($item, $page, $order);

to
$this->_drawItem($item->getOrderItem(), $page, $order);

in Mage_Sales_Model_Order_Pdf_Shipment should give you a starting point.

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.