Can we set Track inventory is NO as defautl once adding a new product

Duc Huynh asked on February 6, 2020 04:43

Hi,

I need to set up the Track inventory is No for new product as default.

I checked the document but I don't find anything article about it yet.

Please help.

Correct Answer

David te Kloese answered on February 6, 2020 12:08

Hi,

There is no global setting, and as it's a system table you can't change it from the admin interface:

Image Text

--

Safest option is as Dmitry suggested to use a Global Events Handler. This way you don't adjust any Kentico core objects.

This however never allows the setting to be set to true.

What you could do, but potentially gets overwritten on a Hotfix or upgrades is change the setting anyway.

"easiest/safest" would be to do it directly in the DB:

Image Text

The fields config are stored in XML in the 'ClassFormDefinition'.

Note: only do this when just instructing the editor isn't sufficient, and you understand the impact of what you're doing in the DB. Always create a backup, and document this change for future reference when doing upgrades or such.

result after update: Image Text

Query I used:

UPDATE cms_class
SET ClassFormDefinition = REPLACE(ClassFormDefinition, '<defaultvalue>ByProduct</defaultvalue><fieldcaption>Track inventory</fieldcaption>', '<defaultvalue>Disabled</defaultvalue><fieldcaption>Track inventory</fieldcaption>')
 WHERE ClassName = 'ecommerce.SKU'

NOTE AGAIN: create DB BACKUP FIRST

2 votesVote for this answer Unmark Correct answer

Recent Answers


Dmitry Bastron answered on February 6, 2020 11:41

Hi Duc,

I'm not sure it's configurable. But what you can do is utilize Global Events and in Before Insert event set track inventory field to false so that when a new product is created this setting will be defaulted to "No".

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on February 6, 2020 12:51

Just a qucik addition to David's answer:

This however never allows the setting to be set to true.

If you use only Insert event this will affect only creating new items. It means when you create a new item, regardless what content editor choses from track inventory dropdown the saved value would be "No". But when he edits the existing item - this setting can be changed because it will trigger a different event - Update one.

And yes, if you follow the database changing approach proposed by David - DO A BACKUP.

1 votesVote for this answer Mark as a Correct answer

Duc Huynh answered on February 7, 2020 04:26

Thanks @David for the detail answer.

I appricate it

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.