Page 1 of 1
Add new field to Order section of Details tab
Posted: Tue Aug 21, 2012 7:09 am
by cpeterson
I'm trying to get a new field populated on the Order section of the Details tab.
The field is showing up on the display. I've added a column for the field in the Order table in the db and created a getter/setter for the field. I cannot get any data to show up in the display field.
Can you give me a quick run down of the steps necessary to get the field populated correctly.
Re: Add new field to Order section of Details tab
Posted: Tue Aug 21, 2012 9:07 am
by phillipuniverse
First of all, the admin code does not use getters/setters for those properties; instead it actually runs off of straight reflection. Although in general it's always good to have those on your entities, don't expect the admin to actually call those when displaying/setting fields.
Are you sure that column actually has data in it in the database? You said that you can actually see the field in the admin console, so I assume that you properly annotated the column with @AdminPresentation. So you see it there but it's just blank?
Re: Add new field to Order section of Details tab
Posted: Wed Aug 22, 2012 7:02 am
by cpeterson
Yep
The value isn't in the db. I'll run that down and see if that fixes the issue.
Thanks
Re: Add new field to Order section of Details tab
Posted: Wed Aug 22, 2012 10:05 am
by cpeterson
Ok,
I believe I've been going at this completely wrong. I need to add total fees (which is calculated from the fulfillment groups object) object). Initially I thought that the total fees should be added to our order object, but that won't work. What's the correct way to handle getting the value out of the fulfillment groups object and populating it within the admin tool in the order section of the display?
Thanks
Re: Add new field to Order section of Details tab
Posted: Thu Aug 23, 2012 10:31 am
by phillipuniverse
Unfortunately you'll have to do quite a bit of customization to get this to work in the current version. The steps are:
So I'll assume that you have something like this in your Order subclass:
Code: Select all
@AdminPresentationOverrides(@AdminPresentationOverride(name = "getFulfillmentFees", value=@AdminPresentation(friendlyName="Fulfillment Fees", fieldType=SupportedFieldType.MONEY)))
public class CustomOrderImpl extends Order implements CustomOrder {
protected Money getFulfillmentFees() {
Money result = new Money(BigDecimal.ZERO);
for (FulfillmentGroup group : getFulfillmentGroups()) {
for (FulfillmentGroupFee fee : group.getFulfillmentGroupFees()) {
result = result.add(fee.getAmount());
}
return result;
}
}
- Subclass the CustomerCareModule with your custom module (let's say it's at com.cpeterson.admin.client.MyCustomerCareModule)
- Subclass the OrderPresenter with a custom Presenter (let's say it's called com.cpeterson.admin.client.presenter.MyOrderPresenter)
- Tell the myCompany.gwt.xml file to use your overridden CustomerCare module instead of the OOB Broadleaf one:
Code: Select all
<!-- Commented out because using subclassed module -->
<!-- <inherits name="org.broadleafcommerce.admin.customerCareModule" /> -->
<inherits name="com.cpeterson.admin.client.myCustomerCareModule" />
- In your subclassed CustomerCareModule, override the onModuleLoad method to look like this:
Code: Select all
public class MyCustomerCareModule extends CustomerCareModule {
@Override
public void onModuleLoad() {
super.onModuleLoad();
ModuleFactory.getInstance().put("orderPresenter", "com.cpeterson.admin.client.presenter.MyOrderPresenter");
}
- In your subclassed presenter, provide your own implementation of the OrderListDataSourceFactory. So override the setup() method:
Code: Select all
@Override
public void setup() {
super.setup();
getPresenterSequenceSetupManager().addOrReplaceItem(new PresenterSetupItem("orderDS", new MyCustomOrderListDataSourceFactory(), new AsyncCallbackAdapter() {
@Override
public void onSetupSuccess(DataSource top) {
setupDisplayItems(top);
((ListGridDataSource) top).setupGridFields(new String[]{"customer.firstName", "customer.lastName", "name", "orderNumber", "status", "submitDate"});
getDisplay().getListDisplay().getGrid().sort("submitDate", SortDirection.DESCENDING);
}
}));
}
- In your custom OrderListDataSourceFactory, provide a way to get back the non-persistent fields. This is mostly copy/pasted from the BLC OrderListDataSourceFactory, with a small change:
Code: Select all
public class MyCustomOrderListDataSourceFactory implements DataSourceFactory {
public static ListGridDataSource dataSource = null;
public void createDataSource(String name, OperationTypes operationTypes, Object[] additionalItems, AsyncCallback<DataSource> cb) {
if (dataSource == null) {
operationTypes = new OperationTypes(OperationType.ENTITY, OperationType.ENTITY, OperationType.ENTITY, OperationType.ENTITY, OperationType.ENTITY);
PersistencePerspective persistencePerspective = new PersistencePerspective(operationTypes, new String[]{"getFulfillmentFees"}, new ForeignKey[]{});
DataSourceModule[] modules = new DataSourceModule[]{
new BasicClientEntityModule(CeilingEntities.ORDER, persistencePerspective, AppServices.DYNAMIC_ENTITY)
};
dataSource = new ListGridDataSource(name, persistencePerspective, AppServices.DYNAMIC_ENTITY, modules);
dataSource.buildFields(null, false, cb);
} else {
if (cb != null) {
cb.onSuccess(dataSource);
}
}
}
}
That should be everything you need. It would be nice if you could actually specify these properties via an annotation but that's not available at the moment.
Re: Add new field to Order section of Details tab
Posted: Thu Aug 23, 2012 4:23 pm
by aazzolini
Charlie,
Just to add to Phillip's answer -- you should have most of these customization classes already created. They will just need some data changes I believe.
Re: Add new field to Order section of Details tab
Posted: Fri Aug 24, 2012 9:19 am
by cpeterson
Thanks Andre,
I'll work on getting those changes implemented.
Re: Add new field to Order section of Details tab
Posted: Wed Aug 29, 2012 10:53 am
by godson2006
Hey Andre,
The method name in our class is called getTotalFees. should the text bold below be changed to getTotalFees?
@AdminPresentationOverrides(@AdminPresentationOverride(name = "getFulfillmentFees", value=@AdminPresentation(friendlyName="Fulfillment Fees", fieldType=SupportedFieldType.MONEY)))
Also our class has the following for getTotalFees
@Column(name = "TOTAL_FEES")
@AdminPresentation (group = "Order", friendlyName = "Order Total Fees", order = 20)
protected Money totalFees;
Should the above be changed?
Re: Add new field to Order section of Details tab
Posted: Wed Aug 29, 2012 4:41 pm
by phillipuniverse
Charlie,
If you already have a field called 'totalFees' then you do not need any method called getFulfillmentFees, and in fact, you do not need any of the above customization. However, it's possible that the 'totalFees' column is never actually populated and this was erroneously put there but never used?
The 'getFulfillmentFees' annotation you see on the class will control the display properties for the 'getFulfillmentFees' method. However, the result of this method will never get shown in the admin unless you have the above code for your OrderDataSourceFactory.
All that to say, if you have a method that does this (only returns the result of a property):
Code: Select all
protected Money getTotalFees() {
return this.totalFees;
}
Then you don't have to do anything complicated at all in order to make that show up; just annotate as normal with @AdminPresentation. Only when you have this scenario (add up a few fields and give you a result):
Code: Select all
protected Money getFulfillmentFees() {
Money result = new Money(BigDecimal.ZERO);
for (FulfillmentGroup group : getFulfillmentGroups()) {
for (FulfillmentGroupFee fee : group.getFulfillmentGroupFees()) {
result = result.add(fee.getPrice());
}
}
return result;
}
Will you need the complicated process that I outlined earlier.
Re: Add new field to Order section of Details tab
Posted: Tue Sep 04, 2012 8:12 am
by godson2006
Hey Andre,
Tell the myCompany.gwt.xml file to use your overridden CustomerCare module instead of the OOB Broadleaf one:
In the above statement i noticed that there are two files for pepboys app. One is called PepboysAdmin.gwt.xml and the other is customercare.gwt.xml. i made the below change. but when i do a maven clean and install, it is failing stating that PepboyCustomerCareModule not found in project sources or resources.
The code change was made in customercare.gwt.xml
<!--<entry point class="com.pepboys.ecommerce.admin.client.PepBoysCustomerCareModule" /> -->
<inherits name="com.pepboys.ecommerce.admin.client.PepBoysCustomerCareModule" />
What am i missing?