Page 1 of 1

Extending OrderItem

Posted: Sun Jan 26, 2014 9:51 am
by urfan.alimov
Hello,

I have scenario where my products have multiple suppliers. Currently I am able to relate products to suppliers and show suppliers in product.html

After user selects supplier on product.html i have to store it on OrderItem.
Steps i have done so far:
1) I have reimplemented addItem method of OrderServiceImpl to include supplier id selected on product.html and provided this supplier id to addItemWorkflow.doActivities
2) Extended DiscreteOrderItem class, added field Supplier
3) Created new New Activity workflow to be executed after AddOrderItemActivity

4) In this activity i perform a lookup to supplier table and retrieve Supplier entitty.
5) Loop over DiscreteOrderItems and cast it to my extended version of DiscreteOrderItem , set supplier and save OrderItem.

I am having class cast error in this step.
java.lang.ClassCastException: org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl cannot be cast to ...

I am extending DiscreteOrderItem as i have done with Customer.java and Product.java

Any helps would be highly appreciated.

Thansk & Regards,

Re: Extending OrderItem

Posted: Mon Jan 27, 2014 12:16 pm
by phillipuniverse
Make sure that you have this snippet in applicationContext-entity.xml:

Code: Select all

<bean id="org.broadleafcommerce.core.order.domain.DiscreteOrderItem" class="com.mycompany.core.order.domain.CustomOrderItemImpl"


This tells the system to always create an instance of your overridden item whenever it wants to create a discrete order item. Order items work a bit differently than things like Customer as the system is responsible for creating multiple types (like BundleOrderItems).

Re: Extending OrderItem

Posted: Mon Jan 27, 2014 12:43 pm
by urfan.alimov
Hello phillipuniverse,
I have already this in my applicationContext-entity.xml

Code: Select all

        <bean id="org.broadleafcommerce.profile.core.domain.DiscreteOrderItem"
              class="com.cemsteam.core.domain.IsgOrderItemImpl"
              scope="prototype"/>

and this in my persistence.xml under blPU persistence unit.

Code: Select all

<class>com.cemsteam.core.domain.IsgOrderItemImpl</class>

My class looks like

Code: Select all

public class IsgOrderItemImpl extends DiscreteOrderItemImpl implements IsgOrderItem {
}

My interface looks like

Code: Select all

public interface IsgOrderItem extends DiscreteOrderItem, Serializable{
   public Supplier getSupplier ();
   public void setSupplier(Supplier supplier);
}

And i still get the class cast exception. I also suspect OrderItem works in somehow different than other entities.
But cant figure it out.
Thanks & Regards,