Skip to Content
author's profile photo Former Member
Former Member

How do I override existing relation?

We want to change 'optional' modifier of warehouse attribute in Consignment type. This attribute is declared through ConsignmentWarehouseRelation relation

         <relation code="ConsignmentWarehouseRelation" autocreate="true"
             generate="false" localized="false">
             <sourceElement type="Consignment" qualifier="consignments"
                 collectiontype="set" cardinality="many" ordered="false">
                 <modifiers read="true" write="true" search="true"
                     optional="true" />
             </sourceElement>
             <targetElement type="Warehouse" qualifier="warehouse"
                 cardinality="one">
                 <modifiers read="true" write="false" initial="true"
                     search="true" optional="false" />
             </targetElement>
         </relation>

We've tried to add own definition that would override OOTB

         <relation code="ConsignmentWarehouseRelation" autocreate="false"
             generate="false" localized="false">
             <sourceElement type="Consignment" qualifier="consignments"
                 collectiontype="set" cardinality="many" ordered="false">
                 <modifiers read="true" write="true" search="true"
                     optional="true" />
             </sourceElement>
             <targetElement type="Warehouse" qualifier="warehouse"
                 cardinality="one">
                 <modifiers read="true" write="false" initial="true"
                     search="true" optional="true" />
             </targetElement>
         </relation>

but it doesn't work. Please advise.

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2014 at 11:39 AM

    It is true that you can only override details of an OOB type in items.xml by extending the type - not just by redeclaring it. Redeclaring can only be used for extending - adding new attributes etc.. Instead you can change the type directly via HMC or via code. In our project we had to make Product.code optional and we made a beanshell which is run after every initialize/update to acomplish this. Note that you need to apply the change after every type update because this will reset it to whatever is defined in items.xml.

    Our BeanShell script is:

     /**
      * The attribute Product.core shall be optional so that users can 
      * leave it empty and let an interceptor generate and set a value for it.
      * This is necessary because a system update will set optional=false on Product.code
      *         as defined in OOB items.xml.
      */
     
     import de.hybris.platform.servicelayer.type.TypeService;
     import de.hybris.platform.servicelayer.model.ModelService;
     import de.hybris.platform.core.model.type.AttributeDescriptorModel;
     
     TypeService typeService = ctx.getBean("typeService");
     ModelService modelService = ctx.getBean("modelService");
     
     AttributeDescriptorModel att = typeService.getAttributeDescriptor("Product", "code");
     if (att.getOptional()) {
         print("Product.code is already optional");
     } else {
         print("Setting Product.code to optional");
         att.setOptional(true);
         modelService.save(att);
     }
    
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2014 at 09:42 PM

    Hello,

    When doing this update in your extension make sure you add basecommerce as requires-extension in the extensioninfo.xml, you probably also need to ant clean first, then after start the server, do a update on essential data in hac.

    Hope this helps,

    Regards,

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2014 at 08:56 PM

    Hi,

    I believe it is not recommended to reuse the OOTB restriction as is, instead you can try creating your custom restriction extending the OOTB restriction and handle it appropriately. Custom restriction gives you more flexibility, so you can change or add any other attribute as required.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.