Fix Null customer_address_id in sales_flat_order_address Table

customer-addressorderssales-order

Does somebody know why field customer_address_id is null on sales_flat_order_address table? As regards to order for customer who has an address.

In class: Mage_Sales_Model_Order_Address I found this:

protected function _beforeSave()

{
    parent::_beforeSave();

    if (!$this->getParentId() && $this->getOrder()) {
        $this->setParentId($this->getOrder()->getId());
    }

    // Init customer address id if customer address is assigned
    if ($this->getCustomerAddress()) {
        $this->setCustomerAddressId($this->getCustomerAddress()->getId());
    }

    return $this;
}

Best Answer

The field customer_address_id is a reference to the customer_address table.
When placing an order as guest you have to fill in the address manually.
When you do that there is no customer address object to reference in the checkout so customer_address_id is null.
This also happens when you checkout as a customer, but fill in a new address and you DO NOT choose to save the address in your address book.

The field has a value only when you checkout as a logged in customer and select one of the addresses in your address book, or you add a new address and choose to save it in your address book.

Related Topic