Magento 1.4.2 - Set Address Fields During Registration - magento

I am trying to populate address fields during registration, using data from another system. In my observer, I am able to use
$customer = $observer->getCustomer();
$customer->setFirstname($value);
$customer->setLastname($value);
and the information is saved in the database, but
$customer->setStreet($value);
$customer->setPostcode($value);
$customer->setTelephone($value);
do not. How would I set address fields?
Thanks!

Addresses are not stored in the Mage_Customer_Model_Customer object. You should instead do something like:
$address = Mage::getModel('customer/address');
$address->setStreet(...);
...
$customer->addAddress($address);

I found some good posts:
this was easier for me:-)
http://www.pauldonnellydesigns.com/blog/magento-display-address-fields-in-create-an-account/
and longer post:
http://www.magentocommerce.com/boards/viewthread/11110/
It's working, I checked.
I need show fields form address in orders, controller: /checkout/onepage on the page with form login and register (I want add fields personal and address in step register)
Do someone saw code to create for this functionality?

Related

How do I call the core content component in my custom component in joomla 2.5?

My custom component has to call the core content component and create an entry in the #__content table with proper values. When I add a new article in the article manger I have to give only a title as mandatory field value and other values will be created automatically. I want to pretend this in my custom component.
Instead of updating the database table directly load the ContentModelArticle from com_content and use the model to create new articles. This will generate the alias for you, do all of ACL etc based on the View Access and let any system or content plugins have a look at the article and do whatever they do.
ContentModelArticle extends from JModelAdmin so you can use it's ->save($data) method. Where $data is the array of content to bind to the new ContentModelArticle in the save() method.
So, a basic example would be :
// Create our data with some sample code
$data['title'] = 'My Title';
$data['catid'] = 10; /* NB. this is just an example category Id obviously you'll need to provide a suitable catid for your site */
$data['articletext'] = 'Starting text...'; /* From memory you can't have an empty article.*/
// Get the Article model
$articleModel = $this->getModel('Article', 'ContentModel', array());
// Then save it:
$articleModel->save($data);
Obviously you can populate as many fields as you want, including state, publish_up, publish_down, create_by and lots of others — just look at the structure of the content table in the database #__content to see the various columns and their type.
NB: This is untested code just typed into the browser. It's also been a while since I did any 2.x stuff.
Finally, as this question is about Joomla specific implementation details, you may get a better result if you, try asking on the Joomla Q&A StackExhange site

Deleting customer addresses in magento

I need to delete customer addresses programmatically, but I didn't find a function to do that.
$recordedAddresses = array();
foreach ($customer->getAddresses() as $address)
{
$recordedAddresses = $address->toArray();
}
I already took the addresses' collection as showed above, I just wanna delete them by id.
Curiously I didn't find examples but using API.
Could someone gimme a hand with that?
Somehow Magento keeps empty entities after using $address->delete() in my case. There were empty addresses on account preventing admin from saving the customer form when using this method.
Only way I've found to actually remove the address from user account is by changing the protected $_isDeleted flag to true:
$address = Mage::getModel('customer/address')->load($addressId);
$address->isDeleted(true);
Hope it saves some time for anyone who will stumble uppon same Magento behaviour.
Have a look at the Mage_Customer_AddressController controller class and deleteAction() method. Essentially all you need to is load the address by it's id:
$address = Mage::getModel('customer/address')->load($addressId);
and then delete it:
$address->delete();
delete() is a standard method you can run against all models (see Mage_Core_Model_Abstract), you can also set the _isDeleted flag and call save() which will have the same result.

Get Customer Address Details on Magento Backend

for my magento backend I need a link which is consiting of different customer informations.
So I want to get the specific Inforamions out of the backend but I don't know how.
I've already looked into the adminhtml/.../template/sales/order/view/info.phtml
and found the following line:
<?php echo $this->htmlEscape($_order->getCustomerName()) ?>
This is fine, but I need diffenent variables for Customer Name, - Street, -Postcode, City to
build up a link like that:
www.domain.de/category&name=CustomerName&Street=CustomerStreet& ....
How can I get these variables?
Thanks a lot for every answer!!
Customers can theoretically have many addresses. If you need the one supplied as the billing address with the order, use
$address = $order->getBillingAddress()
This will return an object of the Mage_Sales_Model_Order_Address type, whose properties you can access via
$address->getCity()
$address->getStreet()
etc.
Otherwise you can fetch the customer's default billing address by calling
$address = $order->getCustomer()->getPrimaryBillingAddress()
You can access to the entire customer address collection as well:
$customerAddresses = $customer->getAddressesCollection()

get joomla registration form variables?

I'm working on getting joomla registration form values that user enters
at the time of registration. After two days of searching I reached to the
file Joomla2.5.7\components\com_users\controllers\registration.php. In the register() method I
tried to echo $data and $requestData variables but didn't see any output, on registering a new entry. I also tried to echo javascript but was unsuccessful. I'm trying to connect joomla database with my own database, so that whenever new user registers , he is also registered to my website. How can I get the registration form variables, any kind of help is really appreciated.
Ty this
On registration controller you can find a function call to model like this
$return = $model->register($data);
after that just
echo "<pre/>";
print_r($data);
Also in the registration model
components\com_users\model\registration.php
register() method is defined you can check that for more info.
In addition if you want to add the users info to the other DB like your website DB.
The best place to write mysql query is :
// Store the data.
if (!$user->save()) {
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError()));
return false;
}else{
//Your custom mysql query to other DB or tables
}
find the above section in the registration model inside register()method.
Hope this may solve your problem..
I hope this tutorial helps you. You will find it explains the process of joomla registration form very well.
http://youtu.be/2AyCzb2vTaU

Extending ion auth to only allow registrations from certain email addresses/domains

I want to extend Ion Auth to only allow certain email addresses to register.
I'm fairly sure I could hack this together and get something working, but as a newbie to codeigniter and ion auth I wish to find out if there is a "proper way" to be doing what I need?
For instance can I "extend" ion auth (so I can update ion auth core files without writing over my changes?).
I noticed there are also hooks including this one (in the register function):
$this->ci->ion_auth_model->trigger_events('pre_account_creation');
Where do these resolve and can I use this one in order to intercept registrations from email addresses which don't match a list of those I wish to register?
If so, how would I do it? I would need access to the $email variable from the register() function.
Or is it just a case of altering the base code from ion auth and not updating it in the future?
Thanks for any help you can give me. Don't worry about the email bit, I'm capable of working out whether an email address matches the required email domains, I'm more interested in what is the best way to go about extending the library.
Tom
EDIT: Hi Ben, thanks for your answer, and thanks for taking the time to have a look at my issue. Unfortunately this hasn't helped.
I guess what you're trying to do there is add a little bit to the sql query a "where in" clause? I guess that the where in bit is incorrect as there isn't a column name.
Also, at this point I can't modify the sql query satisfactorily to produce the required output. e.g. I can add a hook to a function which is literally $this->db->where('1=1') and this outputs this sql in the next query:
SELECT COUNT(*) AS `numrows` FROM (`users`) WHERE `1=1` AND `email` = 'rawr#rawr.com'
The AND email = 'rawr#rawr.com' bit will always still return no rows. It should be OR email = 'rawr#rawr.com', but without editing the Ion Auth core code then I won't be able to change this.
I am starting to suspect (from the last couple of hours of tinkering) that I may have to edit the ion auth core in order to achieve this.
Check out this example: https://gist.github.com/2881995
In the end I just wrote a little form_verification callback function which I put in the auth controller of ion_auth which checked through a list of allowed domains. :)
When you validate your form in the auth controller you add a callback:
$this->form_validation->set_rules('email', 'Email Address', required|callback_validate_email');
You create a method in the controller called validate_email:
function validate_email() {
if (strpos($this->input->post('email'), '#mycompany.com') === false) {
$this->form_validation->set_message('validate_email', 'Not official company email address.');
return false;
} else return true;
}
This will cause the creation of the user to fail, since all rules must pass. You also provide an error message. Just make sure to have this line on the form view side:
echo validation_errors();

Resources