Page 1 of 1

how to add custom field

Posted: Thu Aug 30, 2012 4:08 am
by nazrul
Using this http://docs.broadleafcommerce.org/curre ... orial.html link I create a extra text box in Registration Page, and it run ok. But now I want to show this field in the success page.

How can I do that.

I used this
<a class="my-account" th:text="${customer.referralCode}"></a>
but it is giving an error.

and

in the header.html
<a class="my-account" th:href="@{/account}" th:text="${customer.firstName}"></a>
--> it gives the user name.

<a class="my-account" th:text="${customer.lastName}"></a>
use this to print last name.

but
how can I print referralCode

Re: how to add custom field

Posted: Thu Aug 30, 2012 4:10 am
by nazrul
if I print that referralCode in consol it print. But not in the JSP/html page.

So, what I have to do?

Re: how to add custom field

Posted: Thu Aug 30, 2012 9:51 am
by phillipuniverse

Code: Select all

<a class="my-account" th:text="${customer.referralCode}"></a>


Is giving you an error because assumedly you do not have a custom Customer override that has a property called referralCode. If you followed the instruction that you linked, then you would have done this:

Code: Select all


        
// Create the referralCode CustomerAttribute
        
CustomerAttribute referralCodeAttr = new CustomerAttributeImpl();
        
referralCodeAttr.setName("referralCode");
        
referralCodeAttr.setValue(registerCustomerForm.getReferralCode());
        
referralCodeAttr.setCustomer(newCustomer);
        
        
// Update our customer object
        
newCustomer.getCustomerAttributes().add(referralCodeAttr);
        
newCustomer customerService.saveCustomer(newCustomer);
 


Which means that the referral code is available in the customerAttributes property. So, if you are trying to output this on the page, it would look something like this:

Code: Select all

<a class="my-account" th:text="${customer.customerAttributes.get(0).value}"></a>

Re: how to add custom field

Posted: Thu Aug 30, 2012 9:54 am
by phillipuniverse
If you would like this is a first-level property on Customer, consider instead this tutorial: http://docs.broadleafcommerce.org/curre ... orial.html

Re: how to add custom field

Posted: Thu Aug 30, 2012 10:00 am
by nazrul
thank for your help

<a class="my-account" th:text="${customer.customerAttributes.get(0).value}"></a>

and now it run ok