Free-Minded
Free-Minded

Reputation: 5420

how to redeclare core model attribute type without extending it in Hybris

By default Hybtis gives CreditCardType as a mandatory attribute. I want to make it Optional by using redeclare=true (without extending it with new model). I am wondering why its not updating CreditCardPaymentInfo model. I am doing like this

<itemtype code="CreditCardPaymentInfo" autocreate="false" generate="false" >
        <attributes>
            <attribute qualifier="type" type="CreditCardType" redeclare="true" autocreate="false" generate="true">
                <modifiers read="true" write="true" search="true" optional="true" />
                <persistence type="property"/>
            </attribute>
       </attributes>        
    </itemtype>

My ant build is working fine. But whenever i m updating running system, Hybris is not making this attribute non mandatory.

In case if I am extending it with my custom model and re-declaring it then its working, but that's what i don't need. I just want to make it optional without extending it.

I think its possible with Impex also, but i don't know the way. Please help.

Upvotes: 4

Views: 4556

Answers (1)

user3151168
user3151168

Reputation:

You can't redeclare an attribute without extending a type. The documentation for redeclare says it clearly:

Lets you re-define the attribute definition from an inherited type. In essence, you can use a different type of attribute as well as different modifier combinations than on the supertype.

Impex to the rescue. You can alter attribute modifiers with an impex afterwards. Place following impex script

update AttributeDescriptor;enclosingType(code)[unique=true];qualifier[unique=true];optional
;CreditCardPaymentInfo;type;true

under <your-extension>/resources/impex/essentialdata-<chosse-a-name>.impex.

On each typesystem update (or initialize) this impex gets executed and marks CreditCardPaymentInfo.type as optional. For testing purpose, you can run this script within hac, too.

Upvotes: 6

Related Questions