Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9253933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:20:31+00:00 2026-06-18T11:20:31+00:00

When a customer enters an address for the first time than this address serves

  • 0

When a customer enters an address for the first time than this address serves as billing and shipping address. But there is only one entry in the database. So if the customer later decides to alter the shipping address by editing the existing one than the billing address is changed too. To prevent this, I need two separate entries in the database, one for the billing address and one for the shipping address. Therefore,

I wrote an event observer using the event customer_address_save_after to check if the entry for the default billing address is identical to the entry of the default shipping address. If so a copy of this address is saved serving as new shipping address. Well, at least this was the idea,

public function customerAddressSaveAfter($observer)
{
    $session = Mage::getSingleton('customer/session');

    if ($session->getCustomer()->getDefaultBilling()  ==
        $session->getCustomer()->getDefaultShipping())
    {
        $address = $observer->getCustomerAddress();

        $address->unsAddressId()
                ->unsAddressType();           

        Mage::getModel('customer/address')
            ->setData($address->getData())
            ->setIsDefaultShipping('1')
            ->setSaveInAddressBook('1')
            ->save();
    }

    return $this;
}

but running the code seems to result in an infinite loop until the memory is exhausted. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:20:32+00:00Added an answer on June 18, 2026 at 11:20 am

    The problem here is infinite recursion because you are saving a ‘customer/address’ in a ‘customer/address’ save event.

    Set some attribute on your duplicate, and check for it before saving:

    public function customerAddressSaveAfter($observer)
    {
        $address = $observer->getCustomerAddress();
        if ($address->getIsDuplicate()) {
            return $this;
        }
    
        $session = Mage::getSingleton('customer/session'); 
    
        if ($session->getCustomer()->getDefaultBilling()  ==
            $session->getCustomer()->getDefaultShipping())
        {
            $address->unsAddressId()
                    ->unsAddressType();           
    
            Mage::getModel('customer/address')
                ->setData($address->getData())
                ->setIsDefaultShipping('1')
                ->setSaveInAddressBook('1')
                ->setIsDuplicate(true)
                ->save();
        }
    
        return $this;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my code of a sample details gathering page,where once the customer enters
I am validating an email address. But this is not validating whether I am
My customer doesn't want a database but would prefer to update their data in
A customer has asked this morning why he isn't showing up at all in
our customer is loving the Jasper viewer, but we have a problem. It exports
I have a form the contains customer shipping information and card details. I'm using
This is a program that asks the user to input Shipping information about selling
When a customer enters their zip code as text message and text it as
Ok So this code I have below is compiling but I have a logic
I have two sections on my PHP form. One section allows to enter Customer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.