Developer forum

Forum » Development » Pass custom data through orderline, best way

Pass custom data through orderline, best way

Dmitrij Jazel
Reply

Hi guys,

I have a list of orderlines in my shopping basket.

When I list them in razor template. I need to have a textfield - that user will use to enter a code - related to each orderline.

Simmilarly to product custom fields - I need something simmilar like orderline customfield. But I can't seem to find a way to write into orderline custom field. And when I glanced over documentation orderline field - am not sure if it is supported, and whether it is the right solution.

 

Does anyone has any suggestions?


Replies

 
Dmitrij Jazel
Reply

Ehh... was hoping to receive some suggestions by now. I guess that issue probably not so actual for anyone?

Still if anyone has anything to something about this one, would be more than happy to hear them out :-)

 
Mikkel Ricky
Reply
This post has been marked as an answer

Have you read How to use order line fields? More specifically the section Implementing the custom order line fields in the frontend?

Best regards,
Mikkel

Votes for this answer: 1
 
Dmitrij Jazel
Reply

hej Mikkel :-)

Nice, thanks for this information, that is exactly what I need :-)

Not sure why I haven't seen this link before, quite easy to find as I see it now.

The one I was trying to use was this one here: http://manual.dynamicweb-cms.com/Default.aspx?ID=7219

 
Dmitrij Jazel
Reply

Ok, what I am specifically am interested is this: 

  • A loop displaying the order line fields associated with the product in the cart. The loop can be inserted in the show cart template. See the template tag reference for further information.

And if I try to look for available loops that Orderline has to offer, I can see only 

CustomFields
CustomFieldList
Product.OrderLineFields

I tryed to look into each of them, and found that is probably yhe best one to use is CustomFields, so my loop looks like this right now (here "i" is comming from OrderLines loop in the checkout) :

@foreach(LoopItem cf in i.GetLoop("CustomFields")){
    if(cf.GetString("TestVal.System") == "TestVal"){
        <table cellpadding=2>
        <tr>
          <td style="width:500px;">
                @cf.TemplateTags()
          </td>         
          <td>
            <!-- Generate input for this field for each orderline, can't get it generated -->
          </td>
        </tr>
    </table>
    }    
}  

But what still worries me is, that this is a product field (not order line field) - and as documentation explained, I can use it. Ok, fair enough, probably even better idea. Why would you need orderline field than, if you can solve the task with product field!? Whatever works, I just need to be sure I can pass and receive this value for each individual orderline for individual user, further til the order.complete.

 

This is what I am getting, no input fields:

TestVal.Value.Clean    
TestVal.Value.FullPath    
TestVal    
TestVal.Value    
TestVal.Name                    TestVal
TestVal.System                 TestVal
TestVal.Template               TestVal

   
Dmitrij Jazel
Reply

Hmm, not sure why would you ever put this reference to old html loops. I have a better link for this ocasion: https://github.com/dynamicweb/razor/wiki/From-Dynamicweb-HTML-to-Razor#loops

What I was trying to say is: I am already in the OrderLines loop - this is how I have "i" reference (see my code exmaple).

So my question is: how do I generate InputtextField to it?

 

 
Mikkel Ricky
Reply

I'm linking to the documentation showing which loops are available inside your OrderLines loop. CustomFields is not available. The loops and template tags are the same in Dynamicweb HTML and Razor.

 
Casper Andersen
Reply
This post has been marked as an answer

Hello, i know this thread is very old by now! But i had the same problem today and the standard ecommerce solution template did not include this code, so i made it myself basing it on the old HTML code but transforming it into Razor

This is my code: Tested and working

<h2 class="h2">Orderline fields</h2>
                  <table cellpadding=2>
                  @foreach (LoopItem OrderLineFields in GetLoop("Product.OrderLineFields"))
                  {
                      <tr>
                        <td>
                          @OrderLineFields.GetValue("Ecom:Product.OrderLineField.Name")
                        </td>
                        <td>
                          @OrderLineFields.GetValue("Ecom:Product.OrderLineField.InputTextField")
                        </td>
                      </tr>
                  }
                    </table>

Votes for this answer: 1
 
Nicolai Høeg Pedersen
Reply

Hi Casper

Great! Thanks for sharing...

BR Nicolai

 
Mikkel Toustrup Olsen
Reply

Hi Nicolai,

Arent the values of these orderline fields stored in the Database?

I am working on an integration project where we need to update status of each orderline based off of the customers C5 (ERP system). By that we're importing all sorts of data by mapping data from the customer to the DW tables on the go.

However, I can't seem to find the table they reside in.

The EcomOrderLineFields only contains the custom fields we create in the backend - however I kinda need to know where to import the data for the field.

I guess the another option would be to create a new field in EcomOrderLines directly on the table, called OrderLineStatus, and set that field when importing?

BR Mikkel

 

 

ss.PNG
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

They are stored in a column called OrderLineFieldValues in the EcomOrderLines table in a format like this:

<OrderLineFieldValueCollection>
  <OrderLineFieldValue>
    <OrderLineFieldSystemName>FieldName</OrderLineFieldSystemName>
    <Value>FieldValue</Value>
  </OrderLineFieldValue>
</OrderLineFieldValueCollection>

Hope this helps,

Imar

 
Mikkel Toustrup Olsen
Reply

Hi Imar,

Thanks for your reply.

So if I understand it correctly, in order to manipulate with this data, I would have to write some logic to update the value based off of the fieldName maintaining the xml structure within that field(which is set to nvarchar(max) in the database) 

BR Mikkel

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Mikkel,
you could use the API for that. Here is the code which is updating the OrderLineFieldValues from the DynamicwebLiveIntegration project:
 orderLineFieldNode = orderLineNode.SelectSingleNode(string.Format("column [@columnName='{0}']", olf.SystemName));
                                        if (orderLineFieldNode != null)
                                        {
                                            if (orderLine.OrderLineFieldValues == null)
                                            {
                                                orderLine.OrderLineFieldValues = new OrderLineFieldValueCollection();
                                            }
                                            OrderLineFieldValue olfv = orderLine.OrderLineFieldValues.FirstOrDefault(fv => fv != null && string.Compare(olf.SystemName, fv.OrderLineFieldSystemName, true) == 0);
                                            if (olfv != null)
                                            {
                                                olfv.Value = orderLineFieldNode.InnerText;
                                            }
                                            else
                                            {
                                                olfv = new OrderLineFieldValue(olf.SystemName, orderLineFieldNode.InnerText);
                                                orderLine.OrderLineFieldValues.Add(olfv);
                                            }
                                        }

orderLineFieldNode is an xml node like:
<column columnName="YourCustomOrderLineFieldSystemName">SomeOrderLineFieldValue</column

Then in the end of the processing you need to call order.Save() or orderLine.Save() to save the values to database.

Regards, Dmitrij

 
Mikkel Toustrup Olsen
Reply

Hi Dmitrij,

Well this is not meant to be updated when manipulating the order.

The process is as follows..

1) Customer checkout / completes an order.

2) We then generate a file for the client's data provider(erp guy), who then returns a file for us to imort in which the orderid and the orderline/s from the order along with their respective status codes.

Eg: ORDER1; OL1, OL2, OL3; 2

We we recieve this file, we will run an automatic import which updates the specific order and its orderlines directly in the DB. 

Isn't that possible?.

I mean, im thinking of taking the value of the OrderLineFieldValues field in DB and parse that to XML, insert the statuscode for the respective orderline, parse this to a string and do an update on the field afterwards?

As I mention, I could create a custom field on the DB, and just manipulate with that and do some logic which fetches the status code from that :-)

BR Mikkel

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Mikkel,
that is possible, you can update that xml based string value in the database. Once you have the order line custom field (fx its SystemName is "StatusCode") gets created in the backend (so it gets present in the EcomOrderLineFields table),
you can then edit the [OrderLineFieldValues] column xml to add/update your "StatusCode" field value:
All you need to do is to support the XML schema pointed from Imar from the post above:
<OrderLineFieldValueCollection>
..... here can be some other fields
  <OrderLineFieldValue>
    <OrderLineFieldSystemName>StatusCode</OrderLineFieldSystemName>
    <Value>Some_Status_Value</Value>
  </OrderLineFieldValue>
</OrderLineFieldValueCollection>
Regards, Dmitrij

 

You must be logged in to post in the forum