0

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++;
        }

1 Answers1

1

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;
Machavity
  • 30,841
  • 27
  • 92
  • 100
  • I know I had to use substr, but I had no idea where/how to use it. This code is from the default paypal express module that comes with opencart. And I already feel like an idiot, but where does the code you gave me go? In place of another section? – Angel Carlson Dec 10 '13 at 13:17
  • Replace the line in your `foreach` starting `$data['L_PAYMENTREQUEST_0_DESC' . $i]` with the block above and that should work – Machavity Dec 10 '13 at 13:26
  • Thank you so much for your help! This is for a nonprofit site I'm creating as a volunteer. I really appreciate your help and quick response! – Angel Carlson Dec 10 '13 at 13:40