Developer forum

Forum » Dynamicweb 9.0 Upgrade issues » How to use custom order field of type "File"?

How to use custom order field of type "File"?

Peter Leleulya
Reply

I have a question.

I would like to let a customer to attach a pdf to an order which can be used as a shipment document.
Preferably I would have this file saved as binary in my table, but I don't think that is an option at all.

In the front end I want an input field of type "file" to let the customer select a pdf.
So in the CMS I created a custom order field of type "file" to enable this.

When I use @TemplateTags() in my template it shows the custom order field.
I also see a matching column in the EcomOrder table.
The shown template tag information does NOT give me a string sample of the input field I could use (as it does for all my other custom order fields).
See attachment for custom order field "BlancoDeliveryTemplate" of type file in comparison to custom order field "BlancoDelivery" of type checkbox.

When I create my own input field of type "file" and use the system name as input name and id it doesn't seem to save any information to the EcomOrder table when I select a file and post the form (which is of enctype multipart/form-data).

It just doesn't seem to do anything and I have no idea what it SHOULD do either, because there is no way to select an upload directory or something like that.

Can anyone inform me how I can successfully attach a file (pdf) to an order in a cart step?

I then need to send this file (in my checkout handler) to an external environment alongside the order data.
I don't expect any problems there, as long as I can find this file ...

Capture_TemplateTags.PNG

Replies

 
Nicolai Pedersen
Reply

That type of field gives you a filemanager control in the admin.

The order frontend only takes a string value from the frontend (i.e. a path, /files/system/uploads/orders/whatever.pdf) and that will then be shown in admin.

Why it is like that, I cannot answer - been like that always. So you need to handle the actual upload custom and return the filepath to the field - take care of security when doing that. You might also be able to hook into Notifications.Ecommerce.Cart.BeforeCustomFieldValueIsSet or Notifications.Ecommerce.Cart.AfterCustomFieldValueIsSet and do something there.

BR Nicolai

 
Peter Leleulya
Reply

Hi Nicolai,

Thanks for your response.
The problem is, the frontend control that I have in the template does NOT save anything to the database, not even the filepath of the selected file.
If I hook Notifications.Ecommerce.Cart.BeforeCustomFieldValueIsSet and put a breakpoint in it, it DOES break for the other custom order fields, but it DOES NOT break for the filetype one.
Therefore I can't handle the selected file at all.

In the attached file you see the custom order field in the CMS and my DOM explorer which shows the input in the template.
The input of type file shows and has the correct name.
I can select a PDF file from my system and the form submits.
I do get in the Notifications.Ecommerce.Cart.BeforeCustomFieldValueIsSet notifyer a few times for other custom order fields on the same page, but not for this one.
Now my selected file is gone with the wind ...
 

 

When In a break point on Notifications.Ecommerce.Cart.BeforeCustomFieldValueIsSet notifyer I check the System.Web.HttpContext.Request.Form values, the keys do not even contain  BlancoDeliveryTemplate.

So I might not understand your advice fully.
From your statement I understand that I need to create my own input in the template based on the systemname (which I did) and when a file is selected its path should be saved to the database (which it doesnt) and I have to do the actual saving of the file to disk myself in a notifyer (which I can't)

 

 
Nicolai Pedersen
Reply

Hi Peter

Well, Dynamicweb cannot remove things from the post namevalue collection - so it could indicate that the field is outside the <form> that is surrounding the order form fields. Check that, and take a look at the post with developer tools.

BR Nicolai

 
Peter Leleulya
Reply

Well ... the input is definately within the form tags.
The post values in my dev tools do contain info about the selected file, see beneith.
The Post does not save anything to the database.
In the Notifications.Ecommerce.Cart.BeforeCustomFieldValueIsSet this value is gone.

I'm passing this through to Hans for a code review, maybe he can find the issue.
It is causing me headaches with the current temperatures here (no airco) ...
Thanks for your input so far.

------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="EcomCartShippingmethodID" SHIP1 ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="EcomCartShippingmethod" ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="EcomOrderDeliveryAddress" Adamsweg 31 ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="EcomOrderDeliveryAddress2" ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="EcomOrderDeliveryCity" Hengelo ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="EcomOrderDeliveryCompany" Peter thuis ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="EcomOrderDeliveryCountryCode" NL ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="EcomOrderDeliveryRegion" Overijssel ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="EcomOrderDeliveryZip" 7553KL ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="EcomOrderDeliveryPrefix" NewAddress ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="OrderReference" PETERS TEST 3 ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="ShippingMethodSelector" SHIP1 ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="ShipmentOrDeliveryDate" 5/31/2017 ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="SplitDelivery" on ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="BlancoDeliveryTemplate"; filename="dis5759_regcards_hotels_nl.pdf" Content-Type: application/pdf ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="addressType" NewAddress ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="NewAddress_Name" Peter thuis ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="NewAddress_Address1" Adamsweg 31 ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="NewAddress_Address2" ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="NewAddress_Zip" 7553KL ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="NewAddress_City" Hengelo ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="NewAddress_State" Overijssel ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="NewAddress_Country" NL ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="EcomOrderCustomerAccepted" 1 ------WebKitFormBoundaryYgFxq1POO3P2UdIU Content-Disposition: form-data; name="CartV2.GotoStep2" Verzenden ------WebKitFormBoundaryYgFxq1POO3P2UdIU--

 
Nicolai Pedersen
Reply

Ah, so it is a file upload field. You cannot do that as they are handled much differently - that is why I wrote you should use a regular text field with a reference to the file. Since DW does not look at attachments when updating the cart, it will not work like this.

So, in your subscriber, handle the files and store them some where you can find them again, and update the order field with a path to that file using the API.

BR Nicolai

 
Peter Leleulya
Reply

Ok, I didn't fully understand your response earlier.

I now changed the file type "FILE" to "LONG TEXT" in the Dw back end.
This long text is now a hidden field in my form.
I have a control of type "file" in the template with an on-change event.
This event uses a FileReader to get te file contents, which I put in the hidden field.

Might just work ...

 

You must be logged in to post in the forum