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()
Related
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.
We would like to be able to pull the name and email address of customers who purchased items as a guest. Has anyone had any luck in doing so?
I've seen a few posts of how to pull the names of customers who have used the coupon code, but nothing about non-customers!
Thank you guys very much for your help!
-Jeff
This should work:
$orderCollection = Mage::getModel('sales/order')->getCollection()
->addAttributeToSelect('customer_firstname')
->addAttributeToSelect('customer_lastname')
->addAttributeToSelect('customer_email')
->addAttributeToSelect('customer_group_id')
->addAttributeToFilter('customer_group_id', Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)
;
You can then access the values by iterating over the collection...
foreach($orderCollection as $order) {
$customerFirstname = $order->getData('customer_firstname');
$customerLastname = $order->getData('customer_lastname');
$customerEmail = $order->getData('customer_email');
//Do what you want with the values here
}
EDIT:
The above code answers the first paragraph of your question. The second paragraph suggests you are looking for something different though. Are you looking for guest customers who have used a particular coupon code? If so then you should load the collection like this:
$orderCollection = Mage::getModel('sales/order')->getCollection()
->addAttributeToSelect('customer_firstname')
->addAttributeToSelect('customer_lastname')
->addAttributeToSelect('customer_email')
->addAttributeToSelect('customer_group_id')
->addAttributeToSelect('coupon_code')
->addAttributeToFilter('customer_group_id', Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)
->addAttributeToFilter('coupon_code', 'your_awesome_coupon_code')
;
Drew gave me a SQL statement for names and emails of the existing customers in another similar post. To get all orders including registered users and guests you can use this SQL:
SELECT `customer_firstname`, `customer_lastname`, `customer_email` FROM `sales_flat_order` WHERE `coupon_code` = 'your_awesome_coupon_code'
Worked like a charm! Double-checked in 'salesrule_coupon' and the rows returned in the sql matches the number of times the coupon was used.
I will leave Drew's answer marked as correct, since it is probably better to do it in magento. Anyone looking for the SQL though, use this one!
The SQL statement for registered users only can be found here: How can I see full order details for each time a certain coupon code was used in magento?
I've added the following code to the Magento 1.5.1 order confirmation page (success.phtml):
<?php
$_order_id = Mage::getSingleton('checkout/session')->getLastOrderId(); // here I get the Oreder ID
$_order->load($_order_id);
$customer = Mage::getSingleton('customer/session')->getCustomer();
$email = $customer->getEmail(); // To get Email Address of a customer.
?>
An email confirmation was sent to: <?php echo $email ?>
Unfortunately the email variable is empty/null.
Does anyone know how to efficiently get this data? Obtaining First and Last name would be a bonus.
Keep in mind that guest checkout is allowed, so we may not have a customer record in all cases. In any case, I need the billing email address assosicated with the order (guest checkout or not.)
Thanks!
If you got the Order object maybe you can use:
$order->getBillingAddress()->getEmail();
I think that this method it better because you can use it for Guest Customers too.
You have the order increment number ther so load the order and get the variable from order object
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?
Can Magento view/manage our customers by their business name in addition to their contact names to find them easily? It is being used for B2B, so when emails go out they are pulling the customer’s name, instead of the company name which is more appropriate.
Is this a global setting?
thanks in advance.
Magento stores business name on the customer's address by default, so it's a little harder to get to.
There's no reason you cannot add another customer field to put the company name on the customer record itself. That way you'll have no problem accessing it, and can change other screens in the system to reflect it.
If you don't want to go to those lengths, you could always implement a method that pulls the company name from the default address, and save it into the session by default, for easier retrieval.
EDIT: Better idea.
Looking through the sales email templates, there are two methods that are used to grab a customer's name:
$order->getCustomerName();
$order->getBillingAddress()->getName();
I don't see any separate references to the company name, so you should be able to substitute these two methods for your own and get the desired outcome. You'll need to create your own module and override the models for customer/address and sales/order (others have covered this in depth elsewhere). Then create methods that look something like this:
public function getCustomerName() {
if($this->getBillingAddress()->getCompany()) {
return $this->getBillingAddress()->getCompany();
}
return parent::getCustomerName();
}
That's the example for sales order, modify accordingly for customer. Now your company names will be used whenever available, and when they aren't the fallback will be to the original implementation (customer name).
Hope that helps!
Thanks,
Joe
You are correct about the universal application. If you did want just the emails, the concern is whether you have access to your custom function where you need it. If there's no object handy, I'm not positive that you will be able to call just any method that you need to.
An approach that would work in this case would be to override the two objects mentioned below, but to instead add a getCompanyName method to them. That way, you'll have the right objects to call, and you can edit the emails specifically to taste.