Hi Phillip,
i've tried to find more info, below what i have noticed :
When i search for sku to add into the bundle there is a message in the console :
Code: Select all
[ WARN] 17:02:24 NestedPropertyCriteriaBasedConverter - No mappings found for propertyId 'consolidatedProductOptions' within the mapping group 'org.broadleafcommerce.core.catalog.domain.Sku' - skipping property conversion
We need to use a custom criteria when we search for sku because we filter on skus depending on bundle type. So our datasource :
Code: Select all
public class MFBundleSkuSearchDataSourceFactory implements DataSourceFactory {
protected CustomCriteriaListGridDataSource dataSource = null;
public void createDataSource(String name, OperationTypes operationTypes, Object[] additionalItems, AsyncCallback<DataSource> cb) {
operationTypes = new OperationTypes(OperationType.BASIC, OperationType.BASIC, OperationType.BASIC, OperationType.BASIC, OperationType.BASIC);
PersistencePerspective persistencePerspective = new PersistencePerspective(operationTypes, new String[]{}, new ForeignKey[]{});
persistencePerspective.addPersistencePerspectiveItem(PersistencePerspectiveItemType.FOREIGNKEY, new ForeignKey("product", EntityImplementations.PRODUCT, null));
DataSourceModule[] modules = new DataSourceModule[]{
new SkuBasicClientEntityModule(CeilingEntities.SKU, persistencePerspective, AppServices.DYNAMIC_ENTITY),
};
/**
* Not declared as static because this needs to be recreated every time the page is loaded, since
* the actual fields for the DataSource can change based on adding/removing Product Options
*/
CustomCriteriaListGridDataSource dataSource = new CustomCriteriaListGridDataSource(name, persistencePerspective, AppServices.DYNAMIC_ENTITY, modules, true, false, false, false, true);
dataSource.setCustomCriteria(new String[]{"mfProductSkuList","productID"});
dataSource.buildFields(null, false, cb);
}
}
And our custom SkuPersistenceHandler :
Code: Select all
public class MySkuCustomPersistenceHandler extends SkuCustomPersistenceHandler {
@Override
public Boolean canHandleInspect(PersistencePackage persistencePackage) {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
String[] customCriteria = persistencePackage.getCustomCriteria();
return !ArrayUtils.isEmpty(customCriteria) && "mfProductSkuList".equals(customCriteria[0]) && Sku.class.getName().equals(ceilingEntityFullyQualifiedClassname);
}
@Override
public Boolean canHandleFetch(PersistencePackage persistencePackage) {
return canHandleInspect(persistencePackage);
}
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
//Get the criteria for the product ID
String idProduct = persistencePackage.getCustomCriteria()[1];
//Get the selected product
Product selectedProduct = catalogService.findProductById(Long.parseLong(idProduct));
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
//get the default properties from Sku and its subclasses
Map<String, FieldMetadata> originalProps = helper.getSimpleMergedProperties(Sku.class.getName(), persistencePerspective);
//Pull back the Skus based on the criteria from the client
BaseCtoConverter ctoConverter = helper.getCtoConverter(persistencePerspective, cto,
ceilingEntityFullyQualifiedClassname, originalProps);
PersistentEntityCriteria queryCriteria = ctoConverter.convert(cto, ceilingEntityFullyQualifiedClassname);
Criteria criteria = ((HibernateEntityManager) dynamicEntityDao.getStandardEntityManager()).getSession().createCriteria(SkuImpl.class, "sku");
if(((MFProductBundle)selectedProduct).getBundleType().equals(ProductBundleType.PHYSICAL)){
criteria.createAlias("sku.defaultProduct", "defpo");
criteria.add(Restrictions.eq("defpo.type", "PHYSICAL"));
}else if(((MFProductBundle)selectedProduct).getBundleType().equals(ProductBundleType.VIRTUAL)){
criteria.createAlias("sku.defaultProduct", "defpo");
criteria.add(Restrictions.eq("defpo.type", "VIRTUAL"));
}
queryCriteria.apply(criteria);
@SuppressWarnings("unchecked")
List<Serializable> records = criteria.list();
//Convert Skus into the client-side Entity representation
Entity[] payload = helper.getRecords(originalProps, records);
//Communicate to the front-end to allow form editing for all of the product options available for the current
//Product to allow inserting Skus one at a time
ClassMetadata metadata = new ClassMetadata();
if (cto.get("product").getFilterValues().length > 0) {
Long productId = Long.parseLong(cto.get("product").getFilterValues()[0]);
Product product = catalogService.findProductById(productId);
List<Property> properties = new ArrayList<Property>();
for (ProductOption option : product.getProductOptions()) {
Property optionProperty = new Property();
optionProperty.setName(PRODUCT_OPTION_FIELD_PREFIX + option.getId());
properties.add(optionProperty);
}
metadata.setProperties(properties.toArray(new Property[0]));
}
//Now fill out the relevant properties for the product options for the Skus that were returned
for (int i = 0; i < records.size(); i++) {
Sku sku = (Sku)records.get(i);
Entity entity = payload[i];
List<ProductOptionValue> optionValues = sku.getProductOptionValues();
for (ProductOptionValue value : optionValues) {
Property optionProperty = new Property();
optionProperty.setName(PRODUCT_OPTION_FIELD_PREFIX + value.getProductOption().getId());
optionProperty.setValue(value.getId().toString());
entity.addProperty(optionProperty);
}
}
return new DynamicResultSet(metadata, payload, records.size());
} catch (Exception e) {
throw new ServiceException("Unable to perform fetch for entity: "+ceilingEntityFullyQualifiedClassname, e);
}
}
}
[/code]
when the blank popup appear there is a message in the console :
Code: Select all
[my.project.gwt.myProjectAdmin] There were no fields available to show in the form. Rendering a blank DynamicForm.
If i add skuBundleItems directly into the database, fields "quantity" and "itemSalePrice" are not available in the ListGrid of skuBundleItems :
Code: Select all
getPresenterSequenceSetupManager().addOrReplaceItem(new PresenterSetupItem("bundleSkusDS", new SkuBundleItemsDataSourceFactory(), new AsyncCallbackAdapter() {
@Override
public void onSetupSuccess(DataSource result) {
bundleItemsPresenter = new EditableAdornedTargetListPresenter("",getDisplay().getBundleItemsDisplay(), skuSearchView, new String[]{EntityImplementations.PRODUCT_BUNDLE}, BLCMain.getMessageManager().getString("skuSelect"), BLCMain.getMessageManager().getString("editBundleItem"), new String[]{"quantity", "itemSalePrice"});
bundleItemsPresenter.setDataSource((ListGridDataSource) result, new String[]{"name", "quantity", "itemSalePrice"}, new Boolean[]{false, false, false});
}
}));
I also tried by removing our custom view and custom presenter for products but the problem still present
PS : We have extended ProductBundleImpl with MyProductBundleImpl.
Hope it can help you.
Thanks again Phillip