Developer forum

Forum » Ecommerce - Standard features » Folder as a custom field for products

Folder as a custom field for products

Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi

We have an ecommerce solution that we want to be able to select a folder as a custom field, but from what I can see - it is not possible to create a folder custom field. Is this correct?

What we want to use the folder for, is because the products will often have 25+ images each, and in stead of adding 25+ images one by one, we want to make a select folder field, where all images will be looped in the rendering. How could this be done?

 

Regards, Hans


Replies

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply
This post has been marked as an answer

Hi Hans,

I don;t think this is possible from what I know about the custom fields options in DW.

I would use the regular image fields and just drop the file name.

We are usually doing this by using name conventions. Like for example define a general folder in which you will putt all images. Then create a subfolder with the same name as ProductID or ProductName (whichever you control or it's relevant). Inside that folder you can use Razor functions or methods to select all files with a specific name or with a specific extension.

If you wanna go creative, you can also use the Details loop. This is donne in Media section where you can add additional links or images. You can select a file in here and in the template you can just remove the file name and use the Path to retrieve the images inside that path.

Please let me know if this makes sense.

Adrian 

Votes for this answer: 1
 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Thank you very mutch Adrian. Do you have an example/template where you do this, that you wouldn´t mind sharing?

 

br. Hans

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Hans,

I am sorry for this late reply.

Here are a few examples:

1. Assuming you want a specific path and also want to use the metadata on the file:

@{

List<Dictionary<string, string>> documentsList = GetDocumentFiles("/Files/Documents/" + productId + "/");

 

foreach (System.Collections.Generic.Dictionary<String, String> fileStr in documentsList)
                    {
                        string file = fileStr["file"];
                        var metadata = Dynamicweb.Content.Files.Metadata.EditorFactory.GetMetadataForFile(file);
                        string temp = @".",
                               metafield = "title",
                               fileName = file.Substring((file.LastIndexOf("/") + 1), (file.Length - file.LastIndexOf("/") - 1)),
                               fileTitle = metadata != null && metadata.GetValue(metafield).ToString() != "" ? metadata.GetValue(metafield).ToString() : fileName,
                               substringFile = file.Substring((file.LastIndexOf(temp) + 1), (file.Length - file.LastIndexOf(temp) - 1)),
                            <li>
                                <a class="downloadFile" href="@file"><i class='fa fa-file'></i> @fileTitle</a>
                             </li>
                      }

}

2. If you want to use the convention in the details loop:

@if (GetLoop("Details").Any())
                    {
                      @*Shared files*@  
                    foreach (LoopItem detail in GetLoop("Details").Where(x => x.GetString("Ecom:Product:Detail.Image.Clean").StartsWith("your_path/NamingConvention/")))
                    {
                        string file = detail.GetString("Ecom:Product:Detail.Image.Clean");
                        var metadata = Dynamicweb.Content.Files.Metadata.EditorFactory.GetMetadataForFile(file);
                        string temp = @".",
                               metafield = "title",
                               fileTitle = metadata != null ? metadata.GetValue(metafield).ToString() : Translate("download", "Download"),
                               substringFile = file.Substring((file.LastIndexOf(temp) + 1), (file.Length - file.LastIndexOf(temp) - 1)),

                        <li>
                          <a class="downloadFile" href="@file"><i class='fa fa-file'></i> @fileTitle</a>
                        </li>
                        }

                    }

 

The code might be rough on the edges but I am confident it can help you go in the right direction.

Adrian

 

You must be logged in to post in the forum