cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Extending Cart as new itemtype and setting values throws ClassCastException

shaktimohanty
Explorer
0 Kudos
930

Going by the ideal approach of extending OOB itemtypes, I tried below to extend my OOB Cart Itemtype

 < itemtype code="MyCart" extends="Cart" jaloclass="com.core.MyCart" autocreate="true" generate="true" > 
 
     <description> Extending Cart type with additional attributes < /description >
     < attributes >
         < attribute autocreate="true" qualifier="myAttribute" type="java.lang.String" >
             < description >Custom Attribute in the cart model< /description >
             < persistence type="property" />
         < /attribute >
     < /attributes >
 < /itemtype >

While trying to set the value in my extended DefaultCartFacade as below, I am getting Classcastexception.

 final CartModel cartModel = defaultCartService.getSessionCart();
 ((MyCartModel)cartModel).setMyAttribute("str");

Is it required to instantiate an instance of MyCartModel by extending DefaultCartService#internalGetSessionCnd return MyCartModel object. Am I missing on something?

Accepted Solutions (1)

Accepted Solutions (1)

svintha
Explorer
0 Kudos

Hi Instead of creating a new item type by extending the cart use the existing cnd add attribute as follows where

autocreate="false"

then it might work and do not create a new item type. Hope this might help.

      <itemtype code="Cart" autocreate="false" generate="false">
                 <description> Extending Cart type with additional attributes < /description >
      < attributes >
          < attribute autocreate="true" qualifier="myAttribute" type="java.lang.String" >
              < description >Custom Attribute in the cart model< /description >
              < persistence type="property" />
          < /attribute >
      < /attributes >
             </itemtype>    

shaktimohanty
Explorer
0 Kudos

Exactly thats what I followed in my previous projects where there were hardly 1-2 additional attributes and were common to all Business processes, but with the new requirements I have a number of attributes >5 to be added and was considering the approach to create a new item type to extend the OOB itemtype. Eventually, understanding the extent of customization required, we thought of going ahead with the known approach.

Answers (2)

Answers (2)

former_member1573
Participant
0 Kudos

shaktimohanty Let me know how you implemented.As i want to extend cart itemtype.

Can you help me what all customization required.

former_member704915
Participant
0 Kudos

You have just created an item type. But you need to set the Mycart in JaloSession and then try to retrieve it . Infact, when you create a new cart, you should create a new cart of type mycnd not cart.