Hi!

Um, I was getting an error Fatal error: __clone method called on non-object in /path/to/drupal/sites/all/modules/uc_discount/uc_discount.module on line 111 when I try to view some orders (I can't really remember what those orders were though - whether they have discounts or what) and some pages (for some reason that error comes out when i visit a userpoints page).

I tried doing it like this here http://drupal.org/node/597992#comment-2982582 (the issue was closed so I created a new one). It didn't display any errors anymore although I'm not sure if it's the right solution.

Any help appreciated!

Thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

calbasi’s picture

joekrukosky’s picture

I had the same error after upgrading to UC 2.3 and the 6.x-1.x-dev (2010-Jul-11)

I found the solution in http://drupal.org/node/597992#comment-2982582, but it took me a while because I confused my issue the trigger issue (which I did not have). So I'm just reposting the solution here to simplify the search for others.

Reposted from dsdeiz's post http://drupal.org/node/597992#comment-2982582 :

Hi! Yeah, I believe this is closed though I have a similar problem. It was also displaying Fatal error: __clone method called on non-object in /path/to/drupal/sites/all/modules/uc_discount/uc_discount.module on line 111
I then tried var_dump'ing $context['subject']['node']) and the result was bool(false). Does it mean that it would pass the isset() function?
If so, then I guess it can be changed to if (isset($context['subject']['node']) && is_object($context['subject']['node'])){

grub3’s picture

@coolfiretech

Your fix is extremely important.
it can be changed to if (isset($context['subject']['node']) && is_object($context['subject']['node'])){

haysuess’s picture

This saved me too!!! Any time I added a blank item to my orders it would give me WSOD. This change isn't in the most recent dev version either...that should be fixed ASAP!

smscotten’s picture

Category: support » bug
Priority: Normal » Major

Agreed. Changing to "bug report" because it is a code problem that breaks the functionality of the module.

Rene Hostettler’s picture

Hey had the same issue

Fatal error: __clone method called on non-object in /var/aegir/platforms/pressflow-6.19.92/sites/all/modules/uc_discount/uc_discount.module on line 133

I fixed by changing:

if (isset($context['subject']['node'])){
 to
if (isset($context['subject']['node']) && is_object($context['subject']['node'])){

and also had to change

else if (isset($context['subject']['order_product'])){
to
 else if (isset($context['subject']['order_product']) && is_object($context['subject']['node'])){
ñull’s picture

subscribing

Just to confirm that I see this error too when introducing a blank line in an order. Any fix jet?

jazzitup’s picture

Priority: Critical » Major
Status: Active » Needs review

Confirmed. This issue could be reproduced with the clean D6.20, latest UC 6.x-2.x-dev and latest uc_discount 6.x-1.x-dev. After proposed fixes I still had issues and had to change the block starting from line 127 - instead of:

    case 'cart_item':
       $node = clone $context['subject']['node'];
       $item = $context['subject']['cart_item'];
       $cache = 'cart_item:'. $node->nid .':'. $price_info['price'] .':'. serialize($item->data);
    break;

there should be:

    case 'cart_item':
       if (isset($context['subject']['node']) && is_object($context['subject']['node'])){
              $node = clone $context['subject']['node'];
              $item = $context['subject']['cart_item'];
              $cache = 'cart_item:'. $node->nid .':'. $price_info['price'] .':'. serialize($item->data);
       }
    break;
joachim’s picture

Priority: Major » Critical

Urgh, looks like UC has made API changes :/

The proposed changes need to be posted as a patch file so people can review it -- see http://drupal.org/patch. Only then set the status to 'needs review'.

jazzitup’s picture

Priority: Major » Critical
FileSize
2.58 KB

I hope this helps. The attached patch should integrate all of the proposed changes from above.

EDIT: Even with those patches, module doesn't seem to work properly with the latest Ubercart, probably caused by the API changes mentioned earlier. Reported issue: #1010304: Incompatibility with the latest version of Ubercart

grub3’s picture

Congrats, your patch seems to work.
I did test using two different accounts on our production server.
This seems to be okay.

jazzitup’s picture

@grub3: Are you sure? It seems like this module have some serious issues with the latest Ubercart API changes. It doesn't throw an error, or warning messages, but it just does not seem to work. There are a few cases where it calculates the discount, but there are many different cases where the discount will not be applied after you define the discount's predicate by using CA. At least for me.

Can you confirm everything's ok with this module on your production server, please? What Ubercart version do you use on that setup?

mattman’s picture

Just applied the patch from #10 (production server) and I'm back up and running. Thanks a bunch for the fix! My cart is a very simple one but it seems as if the discount rules (I only have one) is being applied.

joachim’s picture

Thanks for the review!

Be great if we got a couple more reviews for this patch, given how crucial good operation of Ubercart is.

Also, the patch needs a reroll for Drupal coding standards -- whitespace, indentation, and things like 'else if'. Anyone got a few minutes to take a shot at it?

dsdeiz’s picture

FileSize
4.04 KB

I had time! Not entirely sure if I got the patch right though. I haven't tested it either since I can't remember how I got the error originally. I just made the changes mentioned above based from madjoe's patch. And some little changes that the coder module mentioned.

jazzitup’s picture

Can anyone confirm that the module works properly with the latest UC, please?
When I say properly, I need a confirmation on all types of discounts applied to products/total orders.

schackattack’s picture

i applied the patches on the latest dev release. still no order discounts get applied, product discounts do.

jazzitup’s picture

@schackattack: Thanks for the report!

joachim’s picture

Status: Needs review » Needs work

@dsdeiz: Thanks for updating the patch... unfortunately, now it's going too far, sorry! Coder fixes that aren't relevant here shouldn't be in this issue.

Someone could probably fix this by hand, just by stripping out all the patch hunks in the second patch that are not in the first.

I should say that I'm not in a position to test this patch myself -- the site I used to use this module on no longer uses it, so I don't have paid time to work on this module. I'm also really busy with other projects at the moment, so all I can do is keep an eye on this module's issues and when patches get sufficient testing by other users, commit them.

schackattack’s picture

I just tried what joachim suggested, merged the two patches. still to no effect.

joachim’s picture

I didn't say merge them!

joachim’s picture

Patch in #10 needs to be properly formatted code. You *can* use coder module to do this, but make sure to not add other changes that are not relevant here. Though it's simpler to just read up on the coding guidelines...

schackattack’s picture

ok. sorry- wrong choice of words. i stripped out all the lines from the 2nd patch, that weren't in the first. correct?

joachim’s picture

Yup, sounds right. Can you upload it please?

grub3’s picture

Subscribe. Please apply ASAP, hundreds of websites are probably waiting. We can't allow a page of death.

joachim’s picture

@grub3: Anyone can make the patch and upload it, including you. As soon as there's a patch I can apply, I will apply it. I'm sorry to be hardnosed maintainer here but I am extremely busy with client work and none of them need this module.

AaronBauman’s picture

Status: Needs work » Needs review
FileSize
2.65 KB

here is the patch described by shack and joachim.
it resolved the fatal error in my case, but i did not test any further.

torgosPizza’s picture

Subscribing, will test patch when I can.

Rob B’s picture

Thanks aaronbauman (and those who found the fix), I have applied your patch and now I can view/edit my orders again. I will post if I run into any issues.

brettev’s picture

I'm trying to get this to work, and I'm seeing that the patch given makes the fatal error go away, and it shows the correct price on the order's subtotal, but then the order total has the original pre-discounted total. on the cart/checkout page, it shows subtotal as the right price, but total as the full price. If you click on continue, on the cart/checkout/review page, it shows the correct information. So its really just not showing the right total on the cart/checkout page

fcortez’s picture

I was getting the same error as above. I suspect uc_discount module was conflicting with uc_coupons module. I applied the patch in #27, and the error went away. Thank you for the patch.

scotwith1t’s picture

Status: Needs review » Reviewed & tested by the community

Tried patch in #27 and works fine. Please commit to dev whenever you get a chance. Thanks to aaronbauman, shack and joachim!!

joachim’s picture

Status: Reviewed & tested by the community » Needs review
+++ uc_discount/uc_discount.module	2011-01-13 14:40:01.136666784 +0800
@@ -804,7 +807,7 @@ function uc_discount_calculate_discounts
-        if ($predicate['#actions'][$i]['#name'] == 'uc_discount_action_get_order_discount' && $discount) {
+        if ($discount) {
           // Allow successive discounts to inspect this discount by putting
           // it in the order object.
           $order->discounts[$id] = array(
@@ -842,7 +845,7 @@ function uc_discount_calculate_discounts

@@ -842,7 +845,7 @@ function uc_discount_calculate_discounts
       if (ca_evaluate_conditions($predicate, $product_arguments)) {
         $discounts = ca_perform_actions($predicate, $product_arguments);
         foreach ((array) $discounts as $i => $discount) {
-          if ($predicate['#actions'][$i]['#name'] == 'uc_discount_action_get_order_discount' && $discount) {
+          if ($discount) {
             // Allow successive discounts to inspect this discount by putting
             // it in the order object.

I'm a bit alarmed by these two changes. They seem to be a big change and I so out of touch with this module's code I've no idea why they are there and what they do.

Beanjammin’s picture

FileSize
1.56 KB

I have recreated the patch from #27 without the parts highlighted by joachim in #33 that appear to effect how the discount is calculated. All I was after was the ability to view / edit / delete effected orders.

AaronBauman’s picture

#33, #34: makes sense.
not sure why i changed that logic either.

#34 works to address the error for me.
+1 vote for rtbc

ar-jan’s picture

Issue summary: View changes
FileSize
1.56 KB

Here's a reroll (34 applied with offset).