开发者

Adding more information to Magento packingslip or Invoice PDF

How can i add additional information to the Magento Packingslip PDF. I am using integrated label paper, so i would like to add repeat the customers delivery address at the footer and also, some details like total quantity of items in the order and the cost of the items in the order. I am currently modifying local files in: Mage/S开发者_如何转开发ales/Model/Order/Pdf/ but I have only managed to change to font.

EDIT:

Okay, i have made good progress and added most of the information i need, however, i have now stumbled across a problem.. I would like to get the total weight of all items in each order and Quantity.

I am using this code in the shipment.php:

Under the foreach (This is useful in case an order has a split delivery - as you can have one order with multiple "shipments" So this is why I have the code after here:

foreach ($shipment->getAllItems() as $item){
    if ($item->getOrderItem()->getParentItem()) {
        continue;
...

then I have this further down:

$shippingweight=0;
$shippingweight= $item->getWeight()*$item->getQty();
$page->drawText($shippingweight . Mage::helper('sales'), $x, $y, 'UTF-8');

This is great for Row totals. But not for the whole shipment. What I need to do is have this bit of code "added up" for each item in the shipment to create the total Weight of the whole shipment. It is very important that I only have the total of the shipment - not the order as I will be splitting shipments.


Almost at the end of getPdf(...) in Mage_Sales_Model_Order_Pdf_Shipment you will find the code that inserts new pages (lines 93-94 in 1.5.0.1)

if($this->y<15)
   $page = $this->newPage(....)

happening in a for-loop.

You can change the logic here to make it change page earlier to make room for your extra information and then add it before the page shift. You should also place code after the for-block if you want it to appear on the last page as well.

Note: You should not change files in app/code/code/Mage directly. Instead, you should place your changed files under app/code/local/Mage using the same folder structure. That way your changes won't accidently get overwritten in an upgrade.

This should get you the total number of items in your order (there might be a faster way but don't know it off the top of my head):

$quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
$itemsCount = $quote->getItemsSummaryQty();


For invoice PDF

at app/code/local/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php add this before $lineBlock

 $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $this->getSku($item), array('weight'));

     $lines[][] = array(
       'text'  => 'Weight: '. $product->getData('weight')*1 .'Kg/ea.  Total: ' .$product->getData('weight')*$item->getQty() . 'Kg',
       'feed'  => 400
      );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜