Developer forum

Forum » Development » Is it possible to make an Item Field of type Product in code first?

Is it possible to make an Item Field of type Product in code first?

Kim Søjborg Pedersen
Reply

Hello, I'm trying to make an Item Field of type Product with code first, but this code don't work. 

   [Group("Product")]
   [Name("Product Link")]
   [Product]
   public string Product_Link { get; set; }

 


Replies

 
Alexander Gubenko
Reply
This post has been marked as an answer

Hello Kim, 

Use FieldAttribute for the property:

[Group("Product")]
[Field("Product Link", typeof(Dynamicweb.Content.Items.Editors.ProductEditor))]   
public string Product_Link { get; set; } 

Votes for this answer: 1
 
Kim Søjborg Pedersen
Reply

Hello Alexander, and it works, thanks

 
Kim Søjborg Pedersen
Reply

I can now pick the produkt, but the selection don't get saved:

Code:

 [Group("Product (Box 1)")]
 [Name("Product Link")]
 [Field("Product Link", typeof(Dynamicweb.Content.Items.Editors.ProductEditor))]
 public string Product_1_Link { get; set; }

 
Alexander Gubenko
Reply

Hello Kim, 

What do you mean when said "but the selection don't get saved"?

Now, I checked the save scenario for my codefirst ItemType - all works well. See my demo video: http://screencast.com/t/DQCePtllBmu

I use:
 - DW Version: 8.6.1.16 
 - CodeFirst entry named "Blog entry" and attached to this post
 - Page frontend template is:
==========
  <table>
  <!--@LoopStart(Item.Product_Link)--> 
  <tr>
    <td>
      <!--@Ecom:Product.Link-->
    </td>
    <td>
      <!--@Ecom:Product.Price-->
    </td>
    </tr>
  <!--@LoopEnd(Item.Product_Link)-->
  </table>

==========

 
Kim Søjborg Pedersen
Reply

Hello Alexander,
I pick a product then save and close, if I open the item again the product i just picked is gone. See video

DW 8.6.1.19

 
Kim Søjborg Pedersen
Reply

I just made a new item with a productlink and here the product get saved, so well I don't know whats wrong with the other item but let us leave it there.. I wonder why the value of the product link is savede with a prefix p_ thats not that usefull, why not just the productID ?

 
Nicolai Høeg Pedersen
Reply

Hi Kim

It can have a list of products (p_*) and groups (g_*) and they can be mixed - that is why. But maybe it should render a cleaned list.

BR Nicolai

 
Kim Søjborg Pedersen
Reply

Hi Nicolai,

I can't pick groups in mine, only products

 
Nicolai Høeg Pedersen
Reply

Yes, but the control it self supports both - in this case, as a product field editor for items, it only able to return products. You will also soon get a group selector for items - it is essentially the same control, but with different settings.

BR Nicolai

 
Kim Søjborg Pedersen
Reply

Hej Nicolai, I found out that I can only have 2 product link fields on a item. If I have more DW only save the last two (see attachment) 

2015-10-08_1300.png
 
Nicolai Høeg Pedersen
Reply

Hi Kim

Hm, not good. I've asked QA to reproduce the issue and get it fixed if this is a bug.

BR Nicolai

 
Oleg Rodionov
Reply

Hi all,

Yes, the bug is reproduced, new TFS 18897 has been created, thanks for cooperating.

BR, Oleg QA

 
Kim Søjborg Pedersen
Reply

Hello Oleg, can you make it as a hotfix?

 
Kim Søjborg Pedersen
Reply

Hello Oleg, can you make it as a hotfix?

 
Oleg Rodionov
Reply

Hi all,

Kim, the bug has just been fixed on version 861 and higher. Probably, will be released with nearest hotfix.

BR, Oleg

 
Kristian Kirkholt
Reply

Hi All

The correction of #18897 Data in product fields lost when the product field quantity is more than two

has now been fixed in version 8.6.1.24

You are able to find this build in the download section:

http://developer.dynamicweb-cms.com/downloads/dynamicweb-8.aspx

Please contact Dynamicweb Support if you need any additional help regarding this.

Kind Regards
Dynamicweb Support
Kristian Kirkholt

 

You must be logged in to post in the forum