Page 2 of 2

Re: Adding a new feild to Detail Section in Customer Care Tab

Posted: Fri Aug 10, 2012 11:14 am
by phillipuniverse
Thought I would weigh in on this one. godson: if I'm understanding you correctly, you do not already have an extra column in the database for 'totalFees'. Instead, you have a method called "getTotalFees" that returns you some derived value, correct? So you will actually never be setting a 'totalFees' column explicitly. If this is the case, you do not have to explicitly create a new database field if you don't want (or need) to. If you do this and annotate that field like you have, the getter is actually never called because the admin actually works off of reflection directly on the fields itself and does not use the getters/setters.

You can have derived fields be displayed in the admin (in our terminology we refer to these as 'non-persistent fields') if you actually want to display the result of a getter or any other method. I believe you can actually do this by simply adding @AdminPresentationOverrides to your class.

So, in your case, you would add something like this to the top of your OrderImpl subclass:

Code: Select all

@AdminPresentationOverrides(@AdminPresentationOverride(name="getTotalFees", value=@AdminPresentation(friendlyName="Total Fees", fieldType=SupportedFieldType.MONEY))
public class PBOrderImpl extends OrderImpl implements PBOrder {
...
...

Re: Adding a new feild to Detail Section in Customer Care Tab

Posted: Fri Aug 10, 2012 11:44 am
by phillipuniverse
Just went looking through to code again to confirm a suspicion. This is only half of the story; the other half is the overrides you have to make in the admin code itself. This snippet is copy/pasted from the OrderListDataSourceFactory class that is included in BLC:

Code: Select all

public class OrderListDataSourceFactory implements DataSourceFactory {
    
    public static 
ListGridDataSource dataSource null;
    
    public 
void createDataSource(String nameOperationTypes operationTypesObject[] additionalItemsAsyncCallback<DataSourcecb) {
        if (
dataSource == null) {
            
operationTypes = new OperationTypes(OperationType.ENTITYOperationType.ENTITYOperationType.ENTITYOperationType.ENTITYOperationType.ENTITY);
            
PersistencePerspective persistencePerspective = new PersistencePerspective(operationTypes, new String[]{}, new ForeignKey[]{});
            
DataSourceModule[] modules = new DataSourceModule[]{
                new 
BasicClientEntityModule(CeilingEntities.ORDERpersistencePerspectiveAppServices.DYNAMIC_ENTITY)
            };
            
dataSource = new ListGridDataSource(namepersistencePerspectiveAppServices.DYNAMIC_ENTITYmodules);
            
dataSource.buildFields(nullfalsecb);
        } else {
            if (
cb != null) {
                
cb.onSuccess(dataSource);
            }
        }
    }

}
 


Notice this line here:

Code: Select all


PersistencePerspective persistencePerspective 
= new PersistencePerspective(operationTypes, new String[]{}, new ForeignKey[]{});
 


That second String[] parameter corresponds to nonPersistentFields that you want to add to the list of fields. In your specific case, you would change this line to the following:

Code: Select all


PersistencePerspective persistencePerspective 
= new PersistencePerspective(operationTypes, new String[]{"getTotalFees"}, new ForeignKey[]{});
 


With that change, now the admin will know to check for that field, and it will get the presentation attributes that you defined in the @AdminPresentationOverrides on the OrderImpl entity.

To give a small recap, you will create a new DataSourceFactory that looks like this:

Code: Select all

public class PBOrderListDataSourceFactory implements DataSourceFactory {
    
    public static 
ListGridDataSource dataSource null;
    
    public 
void createDataSource(String nameOperationTypes operationTypesObject[] additionalItemsAsyncCallback<DataSourcecb) {
        if (
dataSource == null) {
            
operationTypes = new OperationTypes(OperationType.ENTITYOperationType.ENTITYOperationType.ENTITYOperationType.ENTITYOperationType.ENTITY);
            
PersistencePerspective persistencePerspective = new PersistencePerspective(operationTypes, new String[]{"getTotalFees"}, new ForeignKey[]{});
            
DataSourceModule[] modules = new DataSourceModule[]{
                new 
BasicClientEntityModule(CeilingEntities.ORDERpersistencePerspectiveAppServices.DYNAMIC_ENTITY)
            };
            
dataSource = new ListGridDataSource(namepersistencePerspectiveAppServices.DYNAMIC_ENTITYmodules);
            
dataSource.buildFields(nullfalsecb);
        } else {
            if (
cb != null) {
                
cb.onSuccess(dataSource);
            }
        }
    }
 


Now, you have to associate this dataSourceFactory in an overridden OrderPresenter. Your overridden setup() method should look like this:

Code: Select all

public void setup() {
        
super.setup();
        
getPresenterSequenceSetupManager().addOrReplaceItem(new PresenterSetupItem("orderDS", new PBOrderListDataSourceFactory(), new AsyncCallbackAdapter() {
            public 
void onSetupSuccess(DataSource top) {
                
setupDisplayItems(top);
                ((
ListGridDataSourcetop).setupGridFields(new String[]{"customer.firstName""customer.lastName""name""orderNumber""status""submitDate"});
                
getDisplay().getListDisplay().getGrid().sort("submitDate"SortDirection.DESCENDING);
            }
        }));
}
 


Notice that the second line of that method instantiates a new PBOrderListDataSOurceFactory.

Once you go through that, you should have what you want.

Re: Adding a new feild to Detail Section in Customer Care Tab

Posted: Mon Aug 27, 2012 7:45 am
by godson2006
On our checkout page there is a field called Government fees that pulls data from our totalFees property in our custom order object that extends the broadleaf order object. The fees populate on the order checkout page, but it does not populate n broadleaf admin. I placed a log4j logging on the method, and it does get called when the order checkout page is rendered. The order checkout page and the broadleaf admin page is calling the same method, so the value should display in broadleaf admin. What am i missing?

Snapshot of code below:
@Column(name = "TOTAL_FEES")
@AdminPresentation(group = "Order", friendlyName = "Order Total Fees", order =20)
protected Money totalFees

@Override
public Money getTotalFees(){
Money feeTotal = new Money(BigDecimal.ZERO);
for (FulfillmentGroupFee fee : fg.getFulfillmentGroupFees()){
feeTotal = Moneyutil.nullSafeAddMoney(feeTotal, fee.getAmount());
}
return feeTotal;
}

Re: Adding a new feild to Detail Section in Customer Care Tab

Posted: Mon Aug 27, 2012 2:31 pm
by phillipuniverse
Why do you need the column there if you are basing it off of the method? Remember, the admin does not normally work off of getters/setters but rather directly modifies the properties of the entity via reflection. Are you sure that you instantiated the DataSource in the DataSourceFactory correctly, and that you are passing in getTotalFees into the nonPersistentProperties parameter that I mentioned earlier?

Re: Adding a new feild to Detail Section in Customer Care Tab

Posted: Mon Jun 30, 2014 2:50 pm
by retaildev
Hi @phillipuniverse,

How to achieve this in latest code when you have PersistencePackageFactoryImpl class and this have the creation of persistenceperspective.

Thanks
Kunal