Magento PDF Invoices - how do I get custom product

2019-09-06 16:34发布

问题:

With my PDF invoices/shipments/credit memos I have a lot of paper wasted with custom product options and configurable options listed line by line. I would prefer these to be in one block so they don't take up half a page per fully configured product.

Any ideas?

回答1:

In ./Items/Invoice/Default.php I did this:

    // 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']), 70, true, true),
            //    'font' => 'italic',
            //    'feed' => 35
            //);

            if ($option['value']) {
                $_printValue = isset($option['print_value']) ? $option['print_value'] : strip_tags($option['value']);
                $values = explode(', ', $_printValue);
                foreach ($values as $value) {
                    $Mac= Mage::helper('core/string')->str_split(strip_tags($option['label']), 70, true, true);
                    $Guffin = Mage::helper('core/string')->str_split($value, 50, true, true);
                    $lines[][] = array(
                        'text' => htmlspecialchars_decode ($Mac[0]." : ".$Guffin[0]),
                        'feed' =>35 
                    );  
                }       
            }
        }
    }

This is cheating in that it will not work for multi-select but it does for the project in-hand.

Also had to put in the htmlspecialchars_decode as Magento gets that bit wrong.



回答2:

Something like this should also work...

// custom options
$options = $this->getItemOptions();
if ($options) {
    foreach ($options as $key=>$option) {

        $_printValue = isset($option['print_value']) ? $option['print_value'] : strip_tags($option['value']);

        // draw options label
        $lines[][] = array(
            'text' => Mage::helper('core/string')->str_split(strip_tags($option['label'] . ': ' . $_printValue), 70, true, true),
            'feed' => 35
        );

        /*
        if ($option['value']) {
            $_printValue = isset($option['print_value']) ? $option['print_value'] : strip_tags($option['value']);
            $values = explode(', ', $_printValue);
            foreach ($values as $value) {
                $lines[$lineNum][] = array(
                    'text' => Mage::helper('core/string')->str_split($value, 50, true, true),
                    'feed' => 40
                );
            }
        }
        */
    }
}

It will output the comma separated values after the label.



标签: pdf magento