i am trying to add custom attribute, product(book) publisher name below product name in PDF invoice & publisher is custom attribute created by me
copy
app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php
to
app/code/local/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php
with following codeadding some codes in default.php but this not working properly & showing attribute id like 250,251 in pdf but i want publisher name
default
i add following code in default.php code
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();
$lines = array();
$Publisher = $this->getPublisherValue($item);
// draw Product name
$lines[0] = array(array(
'text' => Mage::helper('core/string')->str_split($item->getName(), 35, true, true),
'feed' => 35,
));
// draw publisher name
&
$lines[1][] = array(
'text' => Mage::helper('core/string')->str_split($Publisher, 35),
'feed' => 35
);
// draw SKU
$lines[0][] = array(
'text' => Mage::helper('core/string')->str_split($this->getSku($item), 17),
'feed' => 290,
'align' => 'right'
);
// draw QTY
$lines[0][] = array(
'text' => $item->getQty() * 1,
'feed' => 435,
'align' => 'right'
);
// draw item Prices
$i = 0;
$prices = $this->getItemPricesForDisplay();
$feedPrice = 395;
$feedSubtotal = $feedPrice + 170;
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++;
}
// draw Tax
$lines[0][] = array(
'text' => $order->formatPriceTxt($item->getTaxAmount()),
'feed' => 495,
'font' => 'bold',
'align' => 'right'
);
// custom options
$options = $this->getItemOptions();
if ($options) {
foreach ($options as $option) {
// draw options label
$lines[][] = array(
'text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 40, true, true),
'font' => 'italic',
'feed' => 35
);
if ($option['value']) {
if (isset($option['print_value'])) {
$_printValue = $option['print_value'];
} else {
$_printValue = strip_tags($option['value']);
}
$values = explode(', ', $_printValue);
foreach ($values as $value) {
$lines[][] = array(
'text' => Mage::helper('core/string')->str_split($value, 30, true, true),
'feed' => 40
);
}
}
}
}
$lineBlock = array(
'lines' => $lines,
'height' => 20
);
$page = $pdf->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
$this->setPage($page);
}
&
private function getPublisherValue($item)
{
$prod = Mage::getModel('catalog/product')->load($item->getProductId());
if(!($return_publisher = $prod->getPublisher()))
return 'N/A';$return_publisher;
else
return $return_publisher;'N/A';
}
}