Get Custom properties from ecommerce page type

Faris Rjoub asked on May 26, 2017 18:31

Hi, I have a page type which is represents a product type with custom properties as below.

ECommerce Product

I have also a custom module in Visual Studio 2013 as below image: (Executed after insert a new eCommerce product)

Code

I need to retrieve Custom properties that belong to my page type after insert any SKU eCommerce product. and how to do that in code.

Thanks

Recent Answers


Juraj Ondrus answered on May 26, 2017 18:41 (last edited on May 26, 2017 18:42)

Hi,
The custom properties were added to the page type or to the SKU object?

Anyway, in either case you can use the object.GetValue("FieldName") method to get the value. And then, to set the value, you can use the SetValue("FieldName", value) method.

0 votesVote for this answer Mark as a Correct answer

Faris Rjoub answered on May 26, 2017 18:58

Hi, The custom properties are added to page type.

I tried that code before as below line,

CustomProperties_StartDate = item.GetValue("StartDate").ToString();

Its results with an error : Object reference not set to an instance of an object.

Any other solution will be appreciated.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 26, 2017 19:00

From your code above you are getting the SKU object information. So, you need to get the page object at first. So, you need to either use the page event handler to add the data to the page or add the fields to the SKU class and use the current handler. Or, depending on your goal you may also combine both.

0 votesVote for this answer Mark as a Correct answer

Faris Rjoub answered on May 26, 2017 19:13

If we go with SKU object , and add that custom fields to its class.

What about hotfix to Kentico upgrades in the future. Does that approach will be valid.

For your second approach you mentioned above use page event handler to add the data to the page what is first step to do that , please assist me if possible.

Thanks for your help

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 26, 2017 19:23

Hi,
You can add the custom fields to the SKU class since it is marked as customizable - please see the documentation If there will be any changes in hotfix or upgrade - it will be clearly stated since we expect that this object/class was modified.

For the second approach, it is the same and you will just use the page event handlers (in the API they are still named as "DocumentEvents"), you can see an example here and available events are listed here

0 votesVote for this answer Mark as a Correct answer

Rebecca De Santis answered on July 1, 2017 19:55

Thank you for sharing with us your article, I must admit that I found very useful. Keep sharing such ideas in the future. Thanks for giving me useful information for my website http://www.giochi-delle-winx.com Thanks again admin!

0 votesVote for this answer Mark as a Correct answer

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