Add a new file upload tab to product edit screen?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
Hello:

Under Admin, in the "Edit Product Details" section are six tabs by default:  Product Info, SEO, Pictures, Product Attributes, etc.

We would like to add a new tab called "admin docs" that would allow administrators to upload zip files and associate them much in the same way the "Pictures" tab allows one to upload multiple image files.

Similarly, we'd like to then associate a product attribute value to a selected "admin doc" from that list of uploaded docs, just as you can now associate "no picture" or other uploaded pictures to a product attribute value.

I'm stuck on how to approach this programmatically. There looks to be a lot of classes, interfaces and services behind the scenes that make the "pictures" functionality work.  I found at least two dozen class, view and model references.  I want the same functionality, only with standard file uploads instead of pictures.  These files would only be visible to administrators on the back end, not to end users.  The ultimate goal is then to be able to attach these files to internal contacts and shoot them an email with the attachment after the user selects that product attribute value and submits the order.

What is the best approach to take with this?  Is there a straightforward way of recreating the pictures tab functionality, but for zip files instead of images?  Is there existing functionality that would achieve a similar result that I may be overlooking?  Thanks in advance.
5 years ago
You could look at the "Downloadable product" functionality and use some of that logic
When you setup a product you can select to attached a file which can be downloaded when purchased  
The download links/files are stored in the dbo_Download table

At present it only allows you to upload one file - but if you could shift it to a new tab and adjust it to allow for multiple files which can be stored in the database
Once they purchase a product rather than allow them to download the file you could automatically email the file to them as you suggested in the plan
5 years ago
Hi Yidna:

Thanks for your feedback!  What I'm confused about is how much of this I need to duplicate to achieve the service.

For example, the _CreateOrUpdate.Picture.cshtml is tied to at least 15 class files and I'm just not sure how much of it is really applicable.

So far I've found references in the files below.  Does that mean that I'd need to basically duplicate all these (and more) references for my new tab?


Nop.Core
--------------------
/Domain/Catalog/Products.cs
/Domain/Catalog/ProductPicture.cs


Nop.Data
--------------------
/Mapping/Catalog/ProductPictureMap.cs
NopMappingDefaults.cs


Nop.Services
---------------------
/Catalog/IProductService.cs
/Catalog/ProductService.cs

Nop.Web
/Areas/Admin
--------------------
Models
-/Catalog/ProductPictureModel.cs
-/Catalog/ProductModel.cs
Controllers
CategoryControl.cs
-Catalog/ProductPictureListModel.cs
-Catalog/ProductPictureSearchModel.cs
- /ProductController.cs
Views
- /Product/_CreateOrUpdate.cshtml
- /Product/_CreateOrUpdate.Picture.cshtml (NEW)
- /Product/_ProductAttributes.cshtml
- /Shared/EditorTemplates/Picture.cshtml

/Factories/IProductModelFactory.cs
/Factories/ProductModelFactor.cs

Database table
-ProductAttributeValue - (pictureid field)

/App_Data/Localization/defaultResources.nopres.xml


Nop.Web.Framework
--------------------
/Infrastructure/AdminWidgetZones.cs
5 years ago
Well some of that code relates to categories not products
Not sure why you are still looking at the picture code ?

Did you have a look at the file saving structure I identified - might be simpler
No sure how important it is to link multiple files per product
If really neded you require a way to implement the one to many relationship = i.e. a new field in the download table.
5 years ago
Hi Yidna!

I was looking at the category areas because the behavior I see for the Picture tab under /Admin/Products is essentially what I want to mimic for the zip file types, so my thought was if I could reverse-engineer that functionality, I could get farther.  

So far I've been able to follow your suggestion and created a new tab with a Kendo grid that uses the downloadable product shared "upload file" dialog.  Now what I need to do is somehow capture the Id value of the uploaded file from the Download SQL table.  I'm not sure how to grab that.  I can see in the rendered HTML that a DownloadGuid is built, but I'd like to pass back the ID so that I can associate it in my new Product_AdminDoc_Mapping table that is basically a duplicate of the Product_Picture_Mapping table.

That way, I can build a grid on the new tab that displays all my downloadable admin docs for this particular product.

Any ideas on how or where to grab that Id value and pass it back to the Ajax POST in the Kendo grid?  The behavior for that would be similar to the ProductPictureAdd() method found in /Admin/Controllers/ProductController.cs

Thanks again!
5 years ago
Not sure I understand - why do you need to get an ID from the grid ?
Normally the grid is showing what has already been stored in the database ?
i.e.
1. Select file to store
2. Store file in tables (along with any exiting files)
3. Update/Display results in the grid

Unless if you mean you want to edit an exising row in the grid - then use the edit button fuctionality
5 years ago
Hi:

I don't need to get the id from a grid --I need to grab the id of the uploaded file so that I can then add that to the mapping table, from which I can then build and display a grid of uploaded zip files associated to that product.

Hope that helps clarify!

Thanks
5 years ago
Yes looking at the code its not so easy to see how it works

The routine that does the upload is
         public virtual IActionResult AsyncUpload() in the Download controller
It the returns the downloadId via Json

I can see when the product is save the Id is in model.DownloadId
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.