Magento View 'Company Name' Instead Of First/Last Name

a 夏天 提交于 2020-01-04 04:43:11

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/3673533/magento-view-company-name-instead-of-first-last-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!