Associate Document To Product

Posted by Community Admin on 05-Aug-2018 21:10

Associate Document To Product

All Replies

Posted by Community Admin on 21-Dec-2011 00:00

Is there an easy way to associate a document with a product using custom fields?

Thanks,

-Ben

Posted by Community Admin on 23-Dec-2011 00:00

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

Posted by Community Admin on 28-Dec-2011 00:00

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

Posted by Community Admin on 28-Dec-2011 00:00

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

Posted by Community Admin on 30-Dec-2011 00:00

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

Posted by Community Admin on 03-Jan-2012 00:00

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

Posted by Community Admin on 03-Jan-2012 00:00

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

Posted by Community Admin on 23-Jan-2012 00:00

Hi,

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

Thanks

Posted by Community Admin on 23-Jan-2012 00:00

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

Posted by Community Admin on 07-Feb-2012 00:00

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

Posted by Community Admin on 08-Feb-2012 00:00

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

Posted by Community Admin on 08-Feb-2012 00:00

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.

Posted by Community Admin on 08-Feb-2012 00:00

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

Posted by Community Admin on 08-Feb-2012 00:00

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.

Posted by Community Admin on 08-Feb-2012 00:00

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?

Posted by Community Admin on 08-Feb-2012 00:00

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.


Posted by Community Admin on 08-Feb-2012 00:00

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

Posted by Community Admin on 01-Mar-2012 00:00

How would this work for a product that could have many documents attached, such as multiple PDFs or CAD drawings?

Posted by Community Admin on 02-Mar-2012 00:00

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

This thread is closed