+1-888-365-2779
Try Now
More in this section

Forums / Ecommerce / Associate Document To Product

Associate Document To Product

19 posts, 0 answered
  1. Ben
    Ben avatar
    44 posts
    Registered:
    27 Sep 2012
    21 Dec 2011
    Link to this post
    Is there an easy way to associate a document with a product using custom fields?

    Thanks,

    -Ben
  2. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    23 Dec 2011
    Link to this post
    Hello,

    You can create a custom field control with a document selector inside and then use control to register a custom field for the needed product type (can be done from ProductTypes page). Here's how to do that:

    Can you take a look at this KB:
    http://www.sitefinity.com/blogs/slavoingilizov/posts/11-09-09/extend_the_image_selector_for_content_items_with_filtering_by_album.aspx
    It describes how to add a Custom Field control with an Image Selector. You can download the source and inspect it yourself.

    Basically, what you need to do,  is create a button that opens a dialogue with a selector inside. Then when you select the image (or in your case a document) its value gets remembered in the field. You can use the source from the KB with a few changes on it. Most of the implementations are copy/paste  (for example the dialogue and the button template would be the same - what you need to change is only the selector - now it is an image selector and with a few customizations you can turn it into a document selector)
    I am also sending you a working user control which is a document selector (could also become an Image selector by changing the mode property in the template to "Image"). The dialogue that opens this control for the user to select can be changed with the dialogue from the KB and this would do the whole trick (and of course creating the Definition and Element classes so that it can become a Field Control).

    Regards,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Ben
    Ben avatar
    44 posts
    Registered:
    27 Sep 2012
    28 Dec 2011
    Link to this post
    Thanks for getting back to me Svetoslav.

    I added all of the files you sent to a "Controls" folder in my project and set the .js and .ascx files to be embedded resources.

    In the Product Types section I added a custom field of type Short text, my interface widget is Custom with a Type of SitefinityWebApp.Controls.ImageSelectorDialog

    I'm able to save the custom field but once I go back to Products and try and edit one, I get an error: "You must specify either virtual path or the type of the field."

    In my ImageSelectorDialog.cs file I have set the LayoutTemplatePath to "~/Controls/ImageSelectorDialog.ascx" and the simpleImageSelectorDialogScript to "~/Controls/ImageSelectorDialog.js"

    Am I missing something obvious here? Does something need to be in the code behind for SelectorUserControl.ascx?

    Thanks,

    -Ben
  4. Ben
    Ben avatar
    44 posts
    Registered:
    27 Sep 2012
    28 Dec 2011
    Link to this post
    I fiddled with my project a bit and after performing the steps below, I now get "The control of type 'SitefinityWebApp.Controls.ImageSelectorDialog' does not implement IField interface. All fields must implement IField interface." This interface is not implemented in your sample code and it isn't mentioned in the blog post you linked.

    Am I on the right track?

    Thanks,

    -Ben
  5. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    30 Dec 2011
    Link to this post
    Hello,

     I responded in the support ticket, here's the answer (for the community):
    You are not registering the correct class. Can you please take a look at the installation instructions in this blog post and follow them:
    http://www.sitefinity.com/blogs/slavoingilizov/posts/11-02-11/creating_a_thumbnail_selector_for_news_items.aspx  

    All the best,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Ben
    Ben avatar
    44 posts
    Registered:
    27 Sep 2012
    03 Jan 2012
    Link to this post
    Hi Svetoslav,

    Sorry, but I'm still having trouble figuring this out.

    Is the code you sent a stand alone example or am I supposed to use it in conjunction with the code you have in your blog post?

    Thanks,

    -Ben
  7. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    03 Jan 2012
    Link to this post
    Hello,

     I sent you a sample project in your support ticket. Can we keep the communication in one place only, so that the answers can be processed faster. Thanks for the understanding

    Greetings,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. martin
    martin avatar
    36 posts
    Registered:
    30 Nov 2008
    23 Jan 2012
    Link to this post
    Hi,

    Can I get a copy of that sample project or view it somewhere.

    Thanks

  9. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    23 Jan 2012
    Link to this post
    Hi Martin,

     I will soon make this a blog post and you will be able to download the sample from there. Thanks for the interest!

    All the best,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    07 Feb 2012
    Link to this post
    Is that blog post far off? :) 

    Or, can you send me the project file you sent to Ben? I seem to be having trouble getting this working with products. I have the control registered, but I always end up with this error:

    Value cannot be null.
    Parameter name: stream

  11. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    08 Feb 2012
    Link to this post
    Hi Nick,

     The blog post is up now:
    http://www.sitefinity.com/blogs/svetoslavpetsov/posts/12-02-08/selecting_documents_in_field_controls_with_editorcontentmanagerdialog.aspx 
    Check it out and let me know if you have some questions on it.

    Kind regards,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  12. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    08 Feb 2012
    Link to this post
    Regarding step 6 of the instructions: 
    "6) Add the .js file as a web resource in AssemblyInfo.cs of SitefinityWebApp: "

    Is this right? Don't you mean in AssmeblyInfo.cs of the ThumbnailSelectorField project?

    Also step 7, registering a virtual path - this is what the code in global.asax does, no? Is there a need to manually register it through the backend?

    I downloaded your supplied code and have followed the instructions in your blog post, and I've ended up with the same error I had before. "Value cannot be null. Parameter name: stream". I've made no changes to the code and have double checked the installation instructions.
  13. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    08 Feb 2012
    Link to this post
    Hi Nick,

     You are correct about the global.asax - I added this step by mistake and it is not necessary, as the path is already registered. However, about step 6 - you need to add this as a web resource to the SitefinityWebApp assembly, not the ThumbnailSelectorField one. 
    The error you are getting usually pops up when the virtual path does not find the required template. Can you check if the built action of the template is set to EmbeddedResource and if the paths to it are correct? Also, you can always try to put the template directly in SitefinityWebApp and use relative path to it, but I tested this on another machine and it is causing no problems - the paths are found just fine.

    Regards,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  14. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    08 Feb 2012
    Link to this post
    OK, well I'm a bit lost now. The js and ascx files were/are set as embedded, the virtual path is registered, I'm using the code exactly as is from what's been provided, but can't get it working.
  15. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    08 Feb 2012
    Link to this post
    I've just tested this on a new empty project and it works fine, which I guess means there is something wrong with my project. Hmmm... where to start?
  16. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    08 Feb 2012
    Link to this post
    Resolved it, turns out my virtual path wasn't registered properly, due to a previous attempt that didn't work which I'd subsequently removed (although I didn't properly clean the solution or settings afterwards). [/facepalm]

    Thanks for the help and suggestions.


  17. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    08 Feb 2012
    Link to this post
    Hello Nick,

     I'm glad you resolved the issue. If you have any further questions, do not hesitate to ask.

    Kind regards,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  18. Victor
    Victor avatar
    94 posts
    Registered:
    15 Jun 2011
    01 Mar 2012
    Link to this post
    How would this work for a product that could have many documents attached, such as multiple PDFs or CAD drawings?
  19. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    02 Mar 2012
    Link to this post
    Hi Victor,

     If you want to associate multiple documents, you will have to serialize the text field's value to an array of Guids (this will hold the GUID of all selected items). An example of how this can be done you can find here:
    http://www.sitefinity.com/devnet/forums/sitefinity-4-x/developing-with-sitefinity/multiimagefieldelement.aspx 

    The sample is for images, but exactly the same way, it can be implemented for documents.

    All the best,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
19 posts, 0 answered