Skip to main content
replaced http://magento.stackexchange.com/ with https://magento.stackexchange.com/
Source Link

I think you are setting an invalid customer id on customer address entity and hence you are getting this error. Please try below code, which is an alternative solution in this context.

$customer = Mage::getModel('customer/customer')->load($data['customer_id']);

//make sure customer exist
if (isset($customer->getId())) {
    $customerAddress = $customer->getAddressById($data['address_id']);

    //make sure address is really associated with the customer who is editing
    if (isset($customerAddress->getId())) {
        $customerAddress->setWebsiteId(1);
        $customerAddress->setStore(1);      
        $customerAddress->setFirstname('test');
        $customerAddress->save();
    } else {
        Mage::throwException('Address is not associated  with this customer !');
    }

} else {
    Mage::throwException('Customer is not valid customer !');
}

You can also go on with @Adarsh's Answer@Adarsh's Answer as it really checks customer exist or not.

I think you are setting an invalid customer id on customer address entity and hence you are getting this error. Please try below code, which is an alternative solution in this context.

$customer = Mage::getModel('customer/customer')->load($data['customer_id']);

//make sure customer exist
if (isset($customer->getId())) {
    $customerAddress = $customer->getAddressById($data['address_id']);

    //make sure address is really associated with the customer who is editing
    if (isset($customerAddress->getId())) {
        $customerAddress->setWebsiteId(1);
        $customerAddress->setStore(1);      
        $customerAddress->setFirstname('test');
        $customerAddress->save();
    } else {
        Mage::throwException('Address is not associated  with this customer !');
    }

} else {
    Mage::throwException('Customer is not valid customer !');
}

You can also go on with @Adarsh's Answer as it really checks customer exist or not.

I think you are setting an invalid customer id on customer address entity and hence you are getting this error. Please try below code, which is an alternative solution in this context.

$customer = Mage::getModel('customer/customer')->load($data['customer_id']);

//make sure customer exist
if (isset($customer->getId())) {
    $customerAddress = $customer->getAddressById($data['address_id']);

    //make sure address is really associated with the customer who is editing
    if (isset($customerAddress->getId())) {
        $customerAddress->setWebsiteId(1);
        $customerAddress->setStore(1);      
        $customerAddress->setFirstname('test');
        $customerAddress->save();
    } else {
        Mage::throwException('Address is not associated  with this customer !');
    }

} else {
    Mage::throwException('Customer is not valid customer !');
}

You can also go on with @Adarsh's Answer as it really checks customer exist or not.

Source Link
Rajeev K Tomy
  • 17.3k
  • 6
  • 63
  • 103

I think you are setting an invalid customer id on customer address entity and hence you are getting this error. Please try below code, which is an alternative solution in this context.

$customer = Mage::getModel('customer/customer')->load($data['customer_id']);

//make sure customer exist
if (isset($customer->getId())) {
    $customerAddress = $customer->getAddressById($data['address_id']);

    //make sure address is really associated with the customer who is editing
    if (isset($customerAddress->getId())) {
        $customerAddress->setWebsiteId(1);
        $customerAddress->setStore(1);      
        $customerAddress->setFirstname('test');
        $customerAddress->save();
    } else {
        Mage::throwException('Address is not associated  with this customer !');
    }

} else {
    Mage::throwException('Customer is not valid customer !');
}

You can also go on with @Adarsh's Answer as it really checks customer exist or not.