(On a D6.26 installation with predominantly only Ubercart modules.)

I am trying to create some conditional actions on the default status of the addresses (specifically, modify the charge for people not sending to their default address). I am able to get to the default_status field in the conditional actions, but the default_status is not acting as expected (if I use a different field, it works as expected). In reviewing the stack trace on the invoice, I see that the AID is -2 and default_shipping and default_billing are 0 regardless of if the address used is new or not or even if it is the address that I had created in the user profile section (prior to creating the order) and marked as default. I understand that is supposed to happen when the AID is new, but these shouldn't be new AIDs if they were created well in advance.
Thanks for any help!


[uc_addresses] => Array
        (
            [shipping] => UcAddressesAddress Object
                (
                    [addressBook:UcAddressesAddress:private] => UcAddressesAddressBook Object
                        (
                            [performanceHint:UcAddressesAddressBook:private] => 1
                            [uid:UcAddressesAddressBook:private] => 1
                            [addresses:UcAddressesAddressBook:private] => Array
                                (
                                    [-1] => UcAddressesAddress Object
 *RECURSION*
                                    [-2] => UcAddressesAddress Object
                                        (
                                            [addressBook:UcAddressesAddress:private] => UcAddressesAddressBook Object
 *RECURSION*
                                            [schemaAddress:UcAddressesSchemaAddress:private] => stdClass Object
                                                (
                                                    [first_name] => Default  
                                                    [last_name] => Address
                                                    [phone] => 999-999-9999
                                                    [company] => 
                                                    [street1] => address 1 for default
                                                    [street2] => 
                                                    [city] => seattle
                                                    [country] => 840
                                                    [zone] => 62
                                                    [postal_code] => 98103
                                                    [address_name] => 
                                                    [default_shipping] => 0
                                                    [default_billing] => 0
                                                    [aid] => -2
                                                    [uid] => 1
                                                    [created] => 
                                                    [modified] => 
                                                )

                                            [dirty:UcAddressesSchemaAddress:private] => 1
                                            [sleep:protected] => Array
                                                (
                                                    [schemaAddress] => stdClass Object
                                                        (
                                                            [first_name] => Default  
                                                            [last_name] => Address
                                                            [phone] => 999-999-9999
                                                            [company] => 
                                                            [street1] => address 1 for default
                                                            [street2] => 
                                                            [city] => seattle
                                                            [country] => 840
                                                            [zone] => 62
                                                            [postal_code] => 98103
                                                            [address_name] => 
                                                            [default_shipping] => 0
                                                            [default_billing] => 0
                                                            [aid] => -2
                                                            [uid] => 1
                                                            [created] => 
                                                            [modified] => 
                                                        )

                                                    [dirty] => 1
                                                )

Comments

megachriz’s picture

Category: bug » support

I think this works as designed (so I'm turning this into a support request). As soon as an address is attached to an order (which technically already happens during checkout), the address no longer belongs to the address book and is in fact a new address, only one that's tied to an order. Though an address attached to an order still has the fields aid, default_billing and default_shipping, they actually have no direct meaning there and should be ignored. They are only being used when the address is saved to the address book, which - for example - happens if a customer completes checkout and the address doesn't look like other addresses in the customer's address book.

If you know a bit of PHP, you could use the method compareAddress() on the address object to check if the supplied address is equal to one of the default addresses. To get the default address you can call the method getDefaultAddress() on the customer's address book object.
The code would then look something like this:

// Get customer's address book.
$address_book = UcAddressesAddressBook::get($order->uid);
// Get customer's default billing address. Can be null if the customer has no default billing address.
$default_billing_address = $address_book->getDefaultAddress('billing');
// Get customer's default shipping address. Can be null if the customer has no default shipping address.
$default_shipping_address = $address_book->getDefaultAddress('shipping');

// Compare supplied addresses against default addresses.
if ($default_billing_address && $order->uc_addresses['billing']->compareAddress($default_billing_address)) {
  // Supplied billing address looks like the default billing address.
  // (perform actions)
}
if ($default_shipping_address && $order->uc_addresses['shipping']->compareAddress($default_shipping_address)) {
  // Supplied shipping address looks like the default shipping address.
  // (perform actions)
}

Let me know if this helps.

megachriz’s picture

Title: AID always -2 » Addresses attached to the order always have a negative address ID

Improved issue title.

megachriz’s picture

Note that by default customers can edit their default address or turn an other address in their address book to be the default. You can lock this down either by turning off the permission "add/edit own addresses" (then they may not edit or add any addresses) or using a custom module in which you implement the hook hook_uc_addresses_may_edit() for not allowing certain addresses to be edited and the hook hook_uc_addresses_address_field_alter() to remove access to the "default" fields. See also the Ubercart Addresses hooks documentation.

megachriz’s picture

Status: Active » Fixed

I assume the question is answered. Feel free to reopen this issue if your question was not answered or open a new issue if you have a different question.

Status: Fixed » Closed (fixed)

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