0

I have defined customer attributes for my customers, and have not had a problem calling upon those attributes until today. I have a custom text attribute for an outside account number. I can see it on the admin backend and edit it, works fine. However, when I try to call it on the front end it fails, while other attributes I set up the exact same way work fine. I have two attributes, outside_account (text/string), and on_terms (true/false boolean).

In order to get the values of these attributes on the frontend, I wrote a couple methods based on a guide I found. In /app/code/core/Mage/Checkout/Model/Type/Abstract.php I defined the methods:

public function getOnTerms()
{
 $onTerms = $this->getData('on_terms');
 if(is_null($onTerms){
 $onTerms = FALSE;
 }
}
public function getOutsideAccount()
{
 return $this->getData('outside_account');
}

Then two more methods in /app/code/core/Mage/Customer/Helper/Data.php:

public function getCustomerOnTerms()
{
 $onTerms = $this->getCustomer()->getOnTerms();
 if(is_null($onTerms)){
 $onTerms = FALSE;
 }
 return $onTerms;
}
public function getCustomerOutsideAccount()
{
 return $this->getCustomer()->getOutsideAccount();
}

Now when I call Mage::helper('customer')->getCustomerOnTerms() it works fine and I get the value of on_terms. However, when I call Mage::helper('customer')->getCustomerOutsideAccount() it fails and returns a null, even when values are entered for the customer.

I'm not sure if there is additional code I need to add because its a string instead of a boolean, but I've tried lots of things and have been unsuccessful each time. Any assistance would be wonderful! Thank you! And I know a lot of the code is ugly I will clean it up more once I have it all working properly!

asked Sep 3, 2014 at 23:51

2 Answers 2

1

This is wrong at all levels.

First: do not change core files. Next time Magento releases an update your change will be overwritten.

Second: create a module and with an installer create an attribute for the customer object. That way you will be able to retrieve it just like any other attribute, with the magic get function.

There are several guides to achieve this, here is one i think might work.

Rajeev K Tomy
17.3k6 gold badges64 silver badges104 bronze badges
answered Sep 4, 2014 at 0:45
0

Why did you add described methods in /app/code/core/Mage/Checkout/Model/Type/Abstract.php when this class is not have anything common with Mage_Customer? You should get customer attributes through Mage_Customer entity but not through any other. So that, it is expectable behaviour as it works in the helper.

Rajeev K Tomy
17.3k6 gold badges64 silver badges104 bronze badges
answered Sep 4, 2014 at 0:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.