Developer forum

Forum » Development » Order line sorting when using ParentLineID

Order line sorting when using ParentLineID

Morten Bengtson
Reply

After creating a custom SalesDiscountProvider I noticed that orderlines with ParentLineID does not affect the sorting of orderlines when rendered.

I would expect all orderlines with a parent id to follow that parent orderline, so that they are rendered in correct order.

Example:

  1. OrderLine (ID="OL1", ParentLineID="")
  2. OrderLine (ID="OL2", ParentLineID="")
  3. OrderLine (ID="OL4", ParentLineID="OL2")
  4. OrderLine (ID="OL5", ParentLineID="OL2")
  5. OrderLine (ID="OL3", ParentLineID="")

I was able to "fix" this by implementing custom sort functionality in an OrderTemplateExtender, but I think this should be handled automatically by eCommerce when ParentLineID is set.

DW version: 8.4.1.19

Sample code from custom SalesDiscountProvider:

var discountPrice = this.CalculateDiscountPrice(orderLine, this.DiscountValue.Amount);
var discountOrderLine = this.CreateOrderLine(order, orderLine, discountPrice);
order.OrderLines.Add(discountOrderLine, false);

private OrderLine CreateOrderLine(Order order, OrderLine parent, double discountPrice)
{
    var orderLine = new OrderLine();
    orderLine.OrderID = order.ID;
    orderLine.Order = order;
    orderLine.Quantity = 1.0;
    orderLine.Modified = DateTime.Now;
    orderLine.ProductName = this.DiscountName;
    orderLine.SetUnitPrice(discountPrice);
    orderLine.DiscountID = this.DiscountID;
    orderLine.ParentLineID = parent.ID;
    orderLine.Type = Base.ChkString(Base.ChkNumber(OrderLine.OrderLineType.ProductDiscount));

    return orderLine;
}

Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

Hi Morten,

Have you enabled "Organize orderlines..." under Management Center -> Ecommerce -> Advanced configuration -> Shopping Cart?

This should do the trick.

- Jeppe

Votes for this answer: 2
 
Morten Bengtson
Reply

Thanks Jeppe, that makes it work as expected. There really is a checkbox for everything ;-)

I just wonder why we need to enable this. Is there any use case where you do not want your orderlines to be organized?

IMHO, this sorting should be enabled by default.

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

I agree with you.

The reason this has not been enabled by default is because it was a change to the way orderlines are rendered. We decided to make this a setting you opt into, as to not force changes if they're unwanted.

Maybe the time is ripe to make this feature enabled by default -- at least for new solutions. We'll discuss it internally.

 
Morten Bengtson
Reply

While you're at it, maybe you should review all the other global settings as well. 

I've been using the installation wizard for new installs. It comes with a standard Globalsettings.aspx file, which doesn't have canonical URLs enables by default. There are probably many more examples like this.

Out of the box, the global settings should have the default settings that fit 80 out of 100 sites (or more). It doesn't make sense that we have to enable a lot of stuff to make a simple site work as expected.

I do understand why you don't just force changes onto existing sites, but it would be great if new installations was born with a "best practice" setup.

Anyway, thanks for your help. I'll shut up now :)

 
Remi Muller
Reply

Yes good point. There should be a best practice or recommended global settings.

For new solutions i already use a modified global settings as a start. Make it happen for new installations so everybody has a smooth start :)

 

You must be logged in to post in the forum