I am trying to create a script for creating a customer programmatically in magento. I am able to store all my fields using the magento's own methods. But I have a custom field called 'landmark' which I need to save it to the customer's account. How do I do it? I am a newbie in Magento. Help needed.
Currently the code for storing all the other fields looks like this$address = Mage::getModel("customer/address"); $address->setCustomerId($customer->getId()) ->setFirstname($customer->getFirstname()) ->setMiddleName($customer->getMiddlename()) ->setLastname($customer->getLastname()) ->setCountryId('IN') ->setRegion($state) ->setPostcode($pincode) ->setCity($city) ->setTelephone($mobile) ->setStreet($addressArray) ->setIsDefaultBilling('1') ->setIsDefaultShipping('1') ->setSaveInAddressBook('1');
How do I store the value of my custom field 'landmark' to the address object?
You can treat custom attributes same as any default magento attribute. Just get the value from customer model and set the value in customer address model.
$address->setLandmark($customer->getLandmark());
You can update your custom field as you update other native fields as below:
$address->setLandMark("Your Land Mark Data Here");
The same way, you can get the landmark data from the address model as below:
$address->getLandMark();
But note that whenever you make any changes in your database table structure, you have to flush out magento cache, and will be best to flush magento cache storage from admin or by deleting all contents of folder mageRoot/var/cache
because magento keep cache of its database structure too.