开发者

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

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 n开发者_如何学Pythoname, 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜