Question

When we have a lot of product options in opencart, it causes the description passed through to paypal express to be longer than 127 characters. Because of this, when we return to the cart to confirm the order, we get error 18112 - "The value of Description parameter has been truncated."

Paypal says "This warning error message is returned if the your cart is passing through a description value that is more than the allowed limit. For PAYMENTREQUEST_0_DESC the character length limitation is 127 characters; hence if your cart passes a value that is greater than this limit, this error will be returned."

I need help figuring out how to truncate the description that paypal express receives so that it is no more than 126 characters.

Here is the section of code that handles the options descriptions. Could anyone help me figure out how to truncate the description sent to paypal down to 126 characters?

    foreach ($this->cart->getProducts() as $item) {
        $data['L_PAYMENTREQUEST_0_DESC' . $i] = '';

        $option_count = 0;
        foreach ($item['option'] as $option) {
            if ($option['type'] != 'file') {
                $value = $option['option_value'];
            } else {
                $filename = $this->encryption->decrypt($option['option_value']);
                $value = utf8_substr($filename, 0, utf8_strrpos($filename, '.'));
            }

            $data['L_PAYMENTREQUEST_0_DESC' . $i] .= ($option_count > 0 ? ', ' : '') . $option['name'] . ':' . (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value);

            $option_count++;
        }
Was it helpful?

Solution

The easiest way to do this is with substr. I'm surprised you didn't think of it since you're using utf8_substr, which appears to do the same thing.

$descr = ($option_count > 0 ? ', ' : '') . $option['name'] . ':' . (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value);
$descr = substr($descr, 0, 126);
$data['L_PAYMENTREQUEST_0_DESC' . $i] = $descr;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top