0

I am working on this file:

app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php

I have products with long names. For Example product name is:

loonggggg producttttt nameeeee

I want it like this on the Invoice:

longggggg produc...

Can this be done?

1

Yes it is possible.

Try this way:

$this->helper('core/string')->truncate($product->getName(), 65,'...', $_reminder, false);

Here $product is an object and 65 is letter count. You can try with increasing/decreasing it as per your need.

Hope this helps.

Ref: Take a look at this file/function

//code/core/Mage/Core/Helper/String.php

public function truncate($string, $length = 80, $etc = '...', &$remainder = '', $breakWords = true)
    {
        $remainder = '';
        if (0 == $length) {
            return '';
        }

        $originalLength = $this->strlen($string);
        if ($originalLength > $length) {
            $length -= $this->strlen($etc);
            if ($length <= 0) {
                return '';
            }
            $preparedString = $string;
            $preparedlength = $length;
            if (!$breakWords) {
                $preparedString = preg_replace('/\s+?(\S+)?$/u', '', $this->substr($string, 0, $length + 1));
                $preparedlength = $this->strlen($preparedString);
            }
            $remainder = $this->substr($string, $preparedlength, $originalLength);
            return $this->substr($preparedString, 0, $length) . $etc;
        }

        return $string;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.