cancel
Showing results for 
Search instead for 
Did you mean: 

PCM "Product.code" attribute as optional

Former Member
0 Kudos
380

Hi all,

I need to set as optional on the "Product.code" when saving on the PCM How I can do it?

Thanks in advance

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You will need an InitDefaultsInterceptor to set the value before the attribute is validated. The side effect here is that is the user cancels the creation of the item you will have an unused generated code.

Former Member
0 Kudos

This is working fine for me, thank you so much

Answers (3)

Answers (3)

Former Member
0 Kudos

Changing the model constraint / modifiers didn't change nothing so where i can cancel/override this validation on the PCM?

Former Member
0 Kudos

Very bad idea to try and make it optional. You can use a number series generator to generator a unique code as an alternative.

Former Member
0 Kudos
    1. Do not do it, the whole service layer depends on code as a unique key (within a catalog version).

Former Member
0 Kudos

The problem is that i want to apply a generated code in the product model prepare interceptor. So that's why I'm trying to set it as optional. It's perfectly working when saving the product in the hMC. But the code is still required when saving in the PCM.

I redeclared the code like follows to be sure to remove all the constraints:

 <modifiers read="true" write="false" search="true" initial="false" optional="true" unique="false"/>

And it's still not working:

 Caused by: de.hybris.platform.cockpit.services.values.ValueHandlerException: Required attribute is missing: 'Product.code' Required attribute is missing: 'Produ
 ct.catalogVersion'

Former Member
0 Kudos

Looking at the package of the exception:

 de.hybris.platform.cockpit.services.values.ValueHandlerException

I would say this is raised by the cockpit, not the data model level.

So this is the first example that it's not a good idea to remove the unique constraint of "code" because it's assumed to be unique and obviously even enforced in multiple places.

Former Member
0 Kudos

As I already said, removing the constraint didn't work, so that's not the problem. Even more, removing that constraint is not what I need

former_member1336901
Participant
0 Kudos

You are aware that hybris complains about "Product.catalogVersion" now, not "Product.code", right?

Former Member
0 Kudos

You need to remove the "unique" constraint / modifier in the data model. I am unsure if this is possible at all.

Are you very sure you want to do that? Lots of logic and functionalities depend on the code being unique.

Former Member
0 Kudos

Hi, thanks for your reply.

Well, I didn't expect that this behavior depends on the "unique" modifier on the data model.

I'll give it a try, but if you are sure that it depends from this modifier, indeed this could be a problem