I am looking to assign imported customers programmatically to another site and store within a multisite. However, each time I attempt to manually set the website id it errors out claiming that it cannot "Call to a member function getId() on a non-object on Customer.php Line 808". First I loop through my websites, if I find a match based on the name I assign a variable the ID. Then I loop through the Stores within those sites getting the ids for them. See the code below...

foreach (Mage::app()->getWebsites() as $website) {
  if ($website->getName() == 'Name'){
   $websiteId = $website->getID();
    foreach ($website->getGroups() as $group) {
        $stores = $group->getStores();
        foreach ($stores as $store) {
          if ($store->getName() == 'Name'){
            $storeId = $store->getID();

Then I attempt to assign the customer to the website and store which causes the error.

$customer = Mage::getModel("customer/customer");
$customer   ->setWebsiteId($websiteId)

Any help would be appreciated. Thanks!



$customer = Mage::getModel("customer/customer");

$websiteId = Mage::app()->getWebsite()->getId();

$store = Mage::app()->getStore();

$customer   ->setWebsiteId($websiteId)


I believe your issue is with setStore($storeId), which should actually be an object rather than an integer.

So, perhaps:

$store = Mage::app()->getStore($storeId); 

will work for you.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.