Page 1 of 3

Add new field to Details tab of Product

Posted: Fri Jul 26, 2013 4:34 am
by ankitpatni
Hi
I am using Broadleaf DemoSite-2.2 version. I want to get a new field just similar to description and Long Description in the Details section of the Product in the admin.I didnt find any suitable documentation for that in docs and nor any related question in the forum also.So please let me know what are the changes I need to do in order to achieve this.

Re: Add new field to Details tab of Product

Posted: Fri Jul 26, 2013 8:49 am
by phillipuniverse
Look at the fields in ProductImpl. You will want to annotate your field with @AdminPresentation.

Re: Add new field to Details tab of Product

Posted: Mon Jul 29, 2013 2:28 am
by ankitpatni
i found the productimpl class in the broadleaf framework .How i will use that class along with controller so that i add the entry what ever i want to add.

Re: Add new field to Details tab of Product

Posted: Mon Jul 29, 2013 7:36 am
by phillipuniverse
Oh I think I misunderstood your question. You can extend ProductImpl with your own subclass (see http://docs.broadleafcommerce.org/core/ ... g-entities) and then add your own property to that class. Then you can annotate that property with @AdminPresentation for it to show up in the admin.

Re: Add new field to Details tab of Product

Posted: Wed Jul 31, 2013 9:58 am
by ankitpatni
I have done the changes according to this documentation (http://docs.broadleafcommerce.org/core/current/broadleaf-concepts/data-and-service-models/extending-entities).

1)I have created two new .java file MyproductImpl.java and MPproduct.java with the following code

here i'm extending the Product.class file

Code: Select all

package com.marketplace.core.catalog.domain;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.broadleafcommerce.common.vendor.service.type.ContainerShapeType;
import org.broadleafcommerce.common.vendor.service.type.ContainerSizeType;
import org.broadleafcommerce.core.media.domain.Media;
import org.broadleafcommerce.core.catalog.domain.product;

public abstract interface MPproduct extends product {
public abstract String getVersion();
public abstract void setVersion(String paramString);
}


here i'm extending the ProductImpl.class file

Code: Select all

package com.marketplace.product.core.domain;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.broadleafcommerce.common.persistence.ArchiveStatus;
import org.broadleafcommerce.common.persistence.Status;
import org.broadleafcommerce.common.presentation.AdminPresentation;
import org.broadleafcommerce.common.presentation.AdminPresentationAdornedTargetCollection;
import org.broadleafcommerce.common.presentation.AdminPresentationClass;
import org.broadleafcommerce.common.presentation.AdminPresentationCollection;
import org.broadleafcommerce.common.presentation.AdminPresentationToOneLookup;
import org.broadleafcommerce.common.presentation.PopulateToOneFieldsEnum;
import org.broadleafcommerce.common.presentation.RequiredOverride;
import org.broadleafcommerce.common.presentation.client.AddMethodType;
import org.broadleafcommerce.common.presentation.client.VisibilityEnum;
import org.broadleafcommerce.common.util.BLCMapUtils;
import org.broadleafcommerce.common.util.DateUtil;
import org.broadleafcommerce.common.util.TypedClosure;
import org.broadleafcommerce.common.vendor.service.type.ContainerShapeType;
import org.broadleafcommerce.common.vendor.service.type.ContainerSizeType;
import org.broadleafcommerce.core.media.domain.Media;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Index;
import org.hibernate.annotations.SQLDelete;
import org.broadleafcommerce.core.catalog.domain.ProductImpl;

@Entity
@Table(name="BLC_PRODUCT")

public class MyproductImpl extends ProductImpl implements MPproduct {

private static final long serialVersionUID = 1L;

@Column(name = "Version")
@AdminPresentation(friendlyName="ProductImpl_Product_Version", order=9, group="ProductImpl_Product_Description", prominent=true, groupOrder=1)
private String version;
public String getVersion()
{
return this.version;
}

public void setVersion(String version)
{
this.version = version;
}

}


2) and then i added following bean under core/src/main/resources/META-INF/persistence.xml file

which will make it look like this:

Code: Select all

<persistence-unit name="blPU" transaction-type="RESOURCE_LOCAL">
    <non-jta-data-source>jdbc/web</non-jta-data-source>
    <class>com.mycompany.profile.core.domain.HCCustomerImpl</class>
    <exclude-unlisted-classes/>
</persistence-unit>


3) Then i have added below bean under core/src/main/resources/applicationContext-entity.xml

Code: Select all

<bean id="org.broadleafcommerce.core.catalog.domain.Product" class="com.marketplace.core.catalog.domain.MyproductImpl" scope="prototype"/>


But this thing doesn't work for me

I am getting the HTTP Error:503 in my browser.

Anyone can give me an idea what wrong i did here???

Regards,
Ankit Patni

Re: Add new field to Details tab of Product

Posted: Thu Aug 01, 2013 2:31 am
by Anky
I am also struggling for the same issue..
If you can solve this issue then that will be very beneficial for me..
Please comment if anyone knows the solution.

Re: Add new field to Details tab of Product

Posted: Thu Aug 01, 2013 9:05 am
by phillipuniverse
1) There is probably a stack trace in your logs detailing what the problem is. The 503 is probably because the application did not start up properly
2) Your persistence.xml file is referencing a file that does not exist, assuming that you are actually using 'com.mycompany.profile.core.domain.HCCustomerImpl'. That class was used as an example of how someone might hook up their own class. For you specifically, you should have 'com.marketplace.product.core.domain.MyproductImpl', as that is the fully qualified name of your custom Product extension.
3) You don't really need the interface MPproduct. We recommend simply extending ProductImpl directly in your own project.

Re: Add new field to Details tab of Product

Posted: Thu Aug 01, 2013 10:27 am
by Anky
Thanks Phillip!

I did the changes as you have mention in your post.
But Still I am getting the same error Http 503 error Service unavailable.
Can you please guide me where I am going wrong.

Re: Add new field to Details tab of Product

Posted: Thu Aug 01, 2013 11:03 am
by hiteshsingla
Even I have the same. I also followed the docs provided on the site.
I created the file in Demosite>site>src>main>java>product>core>domain>MyCustomImpl.java
and made the configuration changes in the xml also.I also got this 503 error.
In the Eclipse console i got the following error:
[artifact:mvn] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in resource loaded from byte array: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Foreign key circularity dependency involving the following tables:
[artifact:mvn] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)

Re: Add new field to Details tab of Product

Posted: Thu Aug 01, 2013 2:35 pm
by phillipuniverse
@Anky: can't really help you any further without some sort of stack trace or additional information. Check to see if the server has actually started up successfully

@hiteshsingla - looks like you might have forgotten an @Table annotation in your subclass? http://stackoverflow.com/questions/1562 ... eir-own-ta