I have UC Discount Coupons installed and set up a couple of coupon codes. If I add a product to my cart then go to checkout and apply the code, I see the discount and the confirmation message. All is well.

If I enter a coupon code (the same one or a different one) and hit apply AGAIN, it shows the confirmation message and applies the correct discount(s).

If I refresh the page, the discount is still applied, but if I enter a coupon code again and hit apply, I get this error:

Notice: Undefined property: stdClass::$cost in UcOrderProductController->buildContent() (line 89 of /sites/all/modules/ubercart/uc_order/uc_order.controller.inc).

I also get the confirmation message and the discount is still correct.

If I try to apply a coupon code one more time, the error disappears and the discount is still there.

The error/notice only appears:

1. The first time I try entering a coupon code after a /cart/checkout page refresh
2. If there are already coupons applied to the order

It doesn't seem to break anything, and it's highly unlikely that anyone would refresh the checkout page after already applying a coupon, but I stumbled upon it and though I'd check in.

I also posted this here because I wasn't sure which module was the issue: https://drupal.org/node/2041061

Comments

ennazussuzanne’s picture

I had the same problem until I changed the coupon to applying to all matching products.

This is possible in store->coupons-> change (I can't come up with the English term right now, I'm using a translation)->apply coupon code to-> all matching products

I hope this helps.

hockey2112’s picture

I am getting the same exact error message. Is there any fix available? I tried the fix in comment #1, but it changed nothing.

aniruddhay’s picture

Same here, #1 does not work.

felixbachman’s picture

Here is the issue:
It happens when a coupon is shown as a item in the cart. The uc_coupon module in this case generates a "fake" item in function (_uc_coupon_cart_item) to be shown in the cart. This generated item does not have a 'cost' value assigned.
If ubercart now generates the content of the cart AND the user has the permission 'administer products' then the uc_order.controller assumes that there is a 'cost' parameter. If it isn't there the error occurs.
There are two possible ways how to solve this issue:
1) Just add 'cost' => 0, in the function _uc_coupon_cart_item of the module uc_coupon.module line 1659
2) or, in uc_order.controller.inc line 89 replace
'#price' => $product->cost, with
'#price' => isset($product->cost) ? $product->cost : '',

Hope this help someone
Felix

ryank76’s picture

First fix in #4 worked for me, thanks.

chris.jichen’s picture

#4 first fix works for me as well. I used the first fix because i think it is the bug for uc_coupon module.

chris.jichen’s picture

Issue summary: View changes

Added link to other post.

DrCord’s picture

I had to use both fixes in #4 as I was still getting the error on the checkout page review page if I only used the first one. I agree it is probably really a problem with the coupons module and how it creates a fake product, but it isn't terrible for ubercart to check for a value existing before setting it and relying on it being set...

webservant316’s picture

Issue summary: View changes

#4 worked for me with (1) alone. Hoping this fix gets added to uc_coupon. patches are a pain to maintain.

carlodimartino’s picture

Thanks! #4 2) worked for me.

ytsejam’s picture

#4 worked for me too, thanks!

webservant316’s picture

this fix was not included in the latest release. Reapplied fix as noted in #4