PHP Fatal error: Cannot use object of type stdClass as array in /Users/alistairmcclymont/Sites/dl7artfo/sites/all/modules/commerce_email/theme/commerce-order-email.tpl.php on line 15

just got this error after upgrading - this error is produced when i complete checkout (i'm using paypal) and get returned to the site, I get a whitescreen and this error is in the log. I did have a bunch of test data being printed out in my email by inserting some php code in the order email. But i've since deleted all of that and still have the error.

Comments

paul.linney’s picture

Assigned: Unassigned » paul.linney

The reference to the customer name needs updated, as $customer_profile (object) now contains the full profile not just the customer address. This allows for custome data in the profile. Try dumping out $customer_profile in the template to see whats available.

I'll update the template to reflect the changes, as I missed them in last commit.

Paul

amcc’s picture

how do you debug the emails - i'd like to do what you say and see what does what, but the only way i can see to test is buy buying something (in the sandbox) and getting an email, i'm sure there's a better method.

paul.linney’s picture

In the commerce_email.rules.inc, after Line 78 put in:

print '<pre>';
print_r($customer_profile);
exit;

I'll add in the basic options in the template comments when I update next time.

Paul

amcc’s picture

How do i test what this is printing out. I'm struggling to work out how i can see the results of the bits of code i put into the email, and also the lines you've suggested about without completing an order and generating an email. Is there a debug method to generate this email or print on screen the results without going through the order process

thanks for the the help
(i'm using the latest version of all the modules by the way)

paul.linney’s picture

This may work (untested). Get an order id and put this on a template in your theme, say bottom of page.tpl.php:

<?php
$order = commerce_order_load(ORDER_ID);
$customer_profile = commerce_email_customer_profile($order);
print '<pre>';
print_r($customer_profile);
exit;
?>

Replace ORDER_ID with any valid order.

Apologies for the inconvenience
Paul

amcc’s picture

sorry its taken a couple of days to test this. your instructions in #3 produces this after completing checkout

stdClass Object
(
    [revision_id] => 29
    [revision_uid] => 1
    [status] => 1
    [log] => 
    [revision_timestamp] => 1324516671
    [data] => 
    [profile_id] => 29
    [type] => billing
    [uid] => 1
    [created] => 1324516671
    [changed] => 1324516671
    [commerce_customer_address] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [country] => GB
                            [administrative_area] => ali
                            [sub_administrative_area] => 
                            [locality] => asdfasd
                            [dependent_locality] => 
                            [postal_code] => asdaea
                            [thoroughfare] => ali
                            [premise] => 
                            [sub_premise] => 
                            [organisation_name] => 
                            [name_line] => ali
                            [first_name] => 
                            [last_name] => 
                            [data] => 
                        )

                )

        )

    [rdf_mapping] => Array
        (
        )

)

without that code i get a whitescreen, thanks for the help so far!

amcc’s picture

Status: Active » Fixed

uninstalling the module, deleting the rule it creates and re-installing fixes this issue.

starsinmypockets’s picture

Was a patch committed for this? As far as I can see, replacing the array notation with object notation fixes this problem...

Status: Fixed » Closed (fixed)

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

Isostar’s picture

I had the same issue when downgrading from 2.x. Uninstalling the module and deleting the rules as suggested in #6 didn't help.
I used own defined fields in the customer profile, maybe that is causing this error.