Magento

eCommerce Software for Online Growth

Magento Forum

From setting up your store to managing your products, pages and promotions to generating detailed reports, the Magento User Guide empowers the user to utilize the platform for all of its vast capacity.
Available in eBook and Print formats – Download Now!!!
   
How do I add attributes to the pdf Invoice? 
 
jklina
Member
 
Avatar
Total Posts:  69
Joined:  2008-06-12
Philadelphia PA
 

Basically I would like to add per unit price and weight to my invoices. I can alter the header easily enough, but I’m not sure how to add the item attributes. Right now I’m poking around in app/code/core/Mage/Sales/Model/Order/Pdf/Items/abstract.php and in particular:

abstract public function draw();

    protected function 
_formatOptionValue($value)
    
{
        $order 
$this->getOrder();

        
$resultValue '';
        if (
is_array($value)) {
            
if (isset($value['qty'])) {
                $resultValue 
.= sprintf('%d'$value['qty']) . ' x ';
            
}

            $resultValue 
.= $value['title'];

            if (isset(
$value['price'])) {
                $resultValue 
.= " " $order->formatPrice($value['price']);
            
}
            
return  $resultValue;
        
else {
            
return $value;
        
}
    }

But the rabbit hole is starting to get a little deep. Can anyone shine some light on this and give me hand?

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
jklina
Member
 
Avatar
Total Posts:  69
Joined:  2008-06-12
Philadelphia PA
 

Okay, so in order to modify the lines on the invoice so that the unit price would show up, I went into app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php and added the bit between “//Added Unit Price” and “Get Row Total” in the following:

/* in case Product SKU is longer than 36 chars - it is written in a few lines */
        foreach (Mage::helper('core/string')->str_split($item->getSku(), 25) as $key => $part{
            $page
->drawText($part380$pdf->y-$shift[2]'UTF-8');
            if (
$key 0{
                $shift[2] 
+= 10;
            
}
        }
        
    
//Added unit price
    
$font $this->_setFontBold();
        
$price $order->formatPriceTxt($item->getOrderItem()->getOriginalPrice());

        
$page->drawText($price490-$pdf->widthForStringUsingFontSize($price$font7), $pdf->y'UTF-8');
        
//$pdf->y -= max($shift)+10;

    //Get Row Total
        
$font $this->_setFontBold();
        
$row_total $order->formatPriceTxt($item->getRowTotal());

        
$page->drawText($row_total565-$pdf->widthForStringUsingFontSize($row_total$font7), $pdf->y'UTF-8');
        
$pdf->-= max($shift)+10;

I still don’t have a clear picture in my head how the class system is laid out, so if anyone can think of a more direct method to access unit price, please post it up.

Now to figure out how to add total weight....

 
Magento Community Magento Community
Magento Community
Magento Community
 
scree
Sr. Member
 
Avatar
Total Posts:  135
Joined:  2008-07-14
Linz
 

could you figure it out?

 Signature 

Online Marketing Consulting, Social Media Marketing & Enterprise Content Management Solutions

GIF Banners, Flash Banners & Online Promotions

Logo Design, Webdesign, Folder Design, Magento Templates

 
Magento Community Magento Community
Magento Community
Magento Community
 
jklina
Member
 
Avatar
Total Posts:  69
Joined:  2008-06-12
Philadelphia PA
 

Hi Scree,

Sorry I didn’t update this thread, but try adding the following to /app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php (I added it after line 315). You may need to adjust the positioning based on your layout.

$page->drawText(Mage::helper('sales')->__('Total Weight (lbs): %s'$order->getWeight()), 300$yShipments'UTF-8');

Hope this helps!

-Josh

 
Magento Community Magento Community
Magento Community
Magento Community
 
romful
Jr. Member
 
Total Posts:  4
Joined:  2008-07-24
 

Hi,

I am trying too to modify the invoice and adding some content like attributes or texts in the bottom of the invoice and I would like if anyone, like you jklina, has succeded to it and how can I do easily.

Thank for your help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
scree
Sr. Member
 
Avatar
Total Posts:  135
Joined:  2008-07-14
Linz
 

just use $page->drawText() in your invoice

 Signature 

Online Marketing Consulting, Social Media Marketing & Enterprise Content Management Solutions

GIF Banners, Flash Banners & Online Promotions

Logo Design, Webdesign, Folder Design, Magento Templates

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
 
© Copyright 2010 Varien. Magento, eCommerce software, is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
177732 users|1023 users currently online|277197 forum posts