OK, so we have this site that has a lot of custom options and we'd like to ideally have the label and value on the same line when the invoice PDF is created. I have located the file responsible at
app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php
and have made a copy at
app/code/local/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php
but my PHP is not good enough for me to figure out how to have the label and value on the same line.
This is the code in question:
$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
);
}
}
}
}
Ideally, I'd like to keep the checks and just have the 'text' be in this form: 'label' – 'value'
Thanks!
Best Answer
First of all, copying files that can just be overridden from the Core to Local is not best practise as it can possibly give you more work when upgrading Magento.
I have tested your case and found your solution:
First of all I rewrite it in my own extension:
Then I override the function you mentioned above:
What I have done here is just removed the part where you draw the label and added it to the part where you print the value.
If you have long labels/values and you want to keep it on one line, I would increase the value in str_split.