Search code examples
broadleaf-commerce

How to override metadata of an entity using XML in order to add additional gridVisibleFields?


I am using blc.version 5.1.5-GA.

When adding targeted products to a product group, the listgrid only displays defaultSku.name. I would like to add additional information to the listgrid.

Here's the relevant entity definition:

@OneToMany(targetEntity = ProductProductGroupXrefImpl.class, mappedBy = "productGroup",
    cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region="blProducts")
@BatchSize(size = 50)
@AdminPresentationAdornedTargetCollection(friendlyName = "ProductGroup_Products", 
    group = GroupName.Details, order = 3000,
    joinEntityClass = "com.broadleafcommerce.merchandisinggroup.domain.ProductProductGroupXrefImpl",
    targetObjectProperty = "product",
    parentObjectProperty = "productGroup",
    gridVisibleFields = {"defaultSku.name"})
protected List<ProductProductGroupXref> productXrefs = new ArrayList<>();

Here's some things I've tried with no success, each <mo:field> block is a separate thing I tried:

<mo:overrideItem ceilingEntity="org.broadleafcommerce.core.catalog.domain.ProductGroupImpl">
    <mo:field name="defaultSku.ean, defaultSku.name">
        <mo:gridVisibleField value="productXrefs"/>
    </mo:field>

    <mo:field name="productXrefs">
        <mo:gridVisibleField value="defaultSku.name, defaultSku.ean"/>
    </mo:field>

    <mo:field name="defaultSku.ean">
        <mo:gridVisibleField value="productXrefs"/>
    </mo:field>

    <mo:field name="productXrefs">
        <mo:gridVisibleField value="defaultSku.ean"/>
    </mo:field>
</mo:overrideItem>

I was restarting my tomcat server each time to ensure the changes were actually being loaded. Is there anything I can debug into and inspect in order to confirm this?

Someone had a similar question and he was never able to get XML overriding working. This question also needs an answer: How to override the @AdminPresentation for existing attributes.


Solution

  • I believe the correct format would be:

    <mo:overrideItem ceilingEntity="com.broadleafcommerce.merchandisinggroup.domain.ProductGroup">
        <mo:field name="productXrefs">
            <mo:gridVisibleField value="defaultSku.name"/>
            <mo:gridVisibleField value="defaultSku.ean"/>
        </mo:field>
    </mo:overrideItem>
    

    Note that the ceilingEntity is the interface for product group, not the Impl.