Hello,

I meet a bug with the error message of commerce_coupon_redeem_coupon_code() function. The $error is no sent back.

I made the call like this:

   $error = '';
   if (!empty($code)) {
     $coupon = commerce_coupon_redeem_coupon_code($code, $order, $error);
      ...
   }

I am specially in a error case where my coupon is not available anymore, because a usage per person limit.
So I'm supposed to get back $error = "Unable to redeem coupon."

With the debugger I see that the function is suppose to return the message t('Unable to redeem coupon.'); by the referenced variable error. But after pass in the &drupal_static function, the $error variable is no longer a referenced variable and out of the function commerce_coupon_redeem_coupon_code() my $error variable take his value of empty again.

Add to this, this function calls the commerce_coupon_evaluate_conditions() function, wich use a access to protected member "Type":
$coupon_wrapper->type->value()
With this, my function always return TRUE => and she shouldn't !
I fixed with:
$coupon_wrapper->type()
It solved the error. This error occured 3 times in the commerce_coupon.module file.

CommentFileSizeAuthor
#2 no_error_message_returned-2597566-1.patch1004 bytesparanojik

Comments

Admad created an issue. See original summary.

paranojik’s picture

Status: Active » Needs review
StatusFileSize
new1004 bytes

A tricky combination of pass-by-reference and return-by-reference :)
Here's a patch.

mwisner’s picture

Patch in #2 fixed the issue for me. Thanks!

mdupree’s picture

#2 Works for me also, easy fix!

mdupree’s picture

Status: Needs review » Reviewed & tested by the community

  • mglaman committed 5b2d5f4 on 7.x-2.x authored by paranojik
    Issue #2597566 by paranojik: commerce_coupon_redeem_coupon_code() doesn'...
mglaman’s picture

Status: Reviewed & tested by the community » Fixed

Thanks!

torgospizza’s picture

I forgot to post here, that when this patch is applied the pane no longer updates, but I can't quite understand why. Has anyone else experienced that?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.