Developer forum

Forum » Swift » Custom OrderLine fields Swift

Custom OrderLine fields Swift

Marie Louise Veigert
Reply

Hi,

I try to add some orderline fields in checkout in Swift on DW9.

It seems like it isn't as 'straight forward' as it used to be :)

I saw a suggestion on forum to add a submit const for the orderline field, but it didn't work in our solution.

Are there a 'how to' regarding adding orderline fields in Swift and to get it submitted to the cart?

 

BR
Marie Louise


Replies

 
Marie Louise Veigert
Reply

Anyone? :)

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Marie,

I will try to describe the process the way I am used to it:

1. Define Orderline Field

2. Assign OrderlineField to Shop or to specific categories.
a. If you want the OrderlineField to apply to all products on your shop, you assign the OrderlineField to the shop:
Settings >Ecommerce > ProductCatalog>Shops>{YourEcommerceShop}>Order Line Fields
b. If you want the OrderlineField to apply only to specific ProductCategories, you go to Ecommerce>ProductCatalog>{YourEcommerceShop}>{YourCategory}>Edit>Order line fields

3. Now that you have assigned your OrderlineField, you can add values to it. All you need is an input field named like this: "EcomOrderLineFieldInput__{YourOrderlineFieldSystemName}"

This should be enough. I hope I did not miss any relevant step :)

Adrian

 
Marie Louise Veigert
Reply

Hi Adrian,

I have done the same steps as you have listed up. But it still doesn't 'save' to the orderline in DW when going to next step. So it seems like it isnt saving anything :)

If I use the 'field' the templatetags suggest it looks like this:

But it doesnt work either.


BR
Marie Louise

 
Aleksandar Borislavov Ivanov Dynamicweb Employee
Aleksandar Borislavov Ivanov
Reply

Hi Marie,

I have a snippet for adding comments to each order line that you can adapt to your solution.

The input needs to be inside the ordersubmit form and inside the orderlines loop

@try

{

    foreach (LoopItem item in orderline.GetLoop("Order.OrderLineFields").Where(y => y.GetString("Ecom:Order:OrderLine.OrderLineField.SystemName") != "CustomOrderLineComment"))

    {

        <div class="g-col-8">

            <input

                name="@item.GetString("Ecom:Order:OrderLine.OrderLineField.InputTextField.Name")"

                value="@item.GetString("Ecom:Order:OrderLine.OrderLineField.Value")"

                placeholder="@Translate("Add comment")"

                class="form-control"

                maxlength="250"

                onblur="UpdateComment()" />

        </div>

    }

 

    foreach (LoopItem item in orderline.GetLoop("Order.OrderLineFields").Where(x => x.GetString("Ecom:Order:OrderLine.OrderLineField.SystemName") == "CustomOrderLineComment"))

    {

        <div class="g-col-4 pt-2">

            <text>"</text>@item.GetString("Ecom:Order:OrderLine.OrderLineField.Value")<text>"</text>

        </div>

    }

}

catch (Exception ex)

{

   //Handle the exception

}

 

 

 
Marie Louise Veigert
Reply

Hi,

I can try :)

But where does the 'UpdateComment' come from? :) 

 
Aleksandar Borislavov Ivanov Dynamicweb Employee
Aleksandar Borislavov Ivanov
Reply

You don't need it - all it does is submit the form via javascript:

<script>

var UpdateComment = debounce(function () {
      document.querySelector("#ordersubmit").submit();
    }, 1);

</script>

 
Marie Louise Veigert
Reply

Hi again,

I worked - but only with the extra javascript :)

 

You must be logged in to post in the forum