Developer forum

Forum » Ecommerce - Standard features » Unit Price Discount tag wrong

Unit Price Discount tag wrong

Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi,

 

Consider this screencast https://www.screencast.com/t/W59dHK6NB

When we have multiple prices (aka Price Matrix), we are having some tags with the wrong values, which is causing the Swift templates to react badly. As far as I can tell, the problem is not the templates.

orderline.GetString("Ecom:Product.Discount.Price.PriceFormatted");

This returning the default unit price (i.e. $100). I was expecting it to be $85 considering my example (because there is no discount), which causes Swift templates to render things correctly.

 

 

The orderline total calculations are accurate, it's just the Discount price that looks odd.

 

Can this be reproduced and fixed?

 

Best Regards,

Nuno Aguiar


Replies

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply

Hi Nuno,

the behavior seems to be feature, since the tag as well as Ecom:Product.Price tag is not related to qantity condition (note price from matrix can be applied OK in the tags if without it), orderline tags like Ecom:Order:OrderLine.UnitPrice.Price are under it only. I see the logic on old admin versions as well (tested on 9.10.21 and up).

BR, Oleg QA 

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Oleg,

 

If I understood you correctly you are saying the Product.Discount.Price.PriceFormatted is generated based on Product.Price tag (in this case 100), but then the UnitPrice is set to another value because of the Price matrix.

 

But that means that I can never trust the Product.Discount.Price to be lower than the UnitPrice and I can't trust the fact that they are different to determine that there is a discount (which in this case there isn't.

 

I guess in my mind, this tag should be returning the same value as the UnitPrice, because there is no discount.

 

If there needs to be another tag and/or something that better determines this expectation, that's fine by me too. My point is that in the templates we should only be doing basic comparisions to determine what is the discounted price vs the non-discounted price (which is what the standard Swift templates are doing), but that currently can't be trusted if there are prices with the price matrix.

 

Did I understood you correctly?

 

Best Regards,

Nuno Aguiar

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Hi Nuno,

I don’t think the tags are “wrong”, but the use of those tags and the expectations probably is 😊

The use of Ecom:Product.Discount.* tags doesn't make any sense, since these tags don't seem to have anything to do with the discounts applied in the cart.
I'm not sure if these tags contain wrong values or whether the purpose of these tags is something else.

I guess what you are looking for is order line template tags as shown in this example...

Ecom:Order:OrderLine.Quantity = 3

Ecom:Order:OrderLine.Price = 300.00 (OK)
Ecom:Order:OrderLine.TotalDiscount = -90.00 (OK)
Ecom:Order:OrderLine.TotalPriceWithProductDiscounts = 210.00 (OK)

Ecom:Order:OrderLine.UnitPrice = 100.00 (OK)
Ecom:Order:OrderLine.UnitDiscount = -30.00 (does not exist - Should be the value of Ecom:Order:OrderLine.TotalDiscount divided by Ecom:Order:OrderLine.Quantity)
Ecom:Order:OrderLine.UnitPriceWithProductDiscount = 70.00 (does not exist - Should be the value of Ecom:Order:OrderLine.TotalPriceWithProductDiscounts divided by Ecom:Order:OrderLine.Quantity)

Until these tags are made available, you could do the math yourself - unless there is something I'm missing here...

@foreach (var orderline in GetLoop("OrderLines"))
{
    double orderLineQuantity = orderline.GetDouble("Ecom:Order:OrderLine.Quantity");

    double orderLineTotalPrice = orderline.GetDouble("Ecom:Order:OrderLine.Price.Price.Value");
    double orderLineTotalDiscount = orderline.GetDouble("Ecom:Order:OrderLine.TotalDiscount.Price.Value");
    double orderLineTotalPriceWithProductDiscounts = orderline.GetDouble("Ecom:Order:OrderLine.TotalPriceWithProductDiscounts.Price.Value");
    
    double unitPrice = orderline.GetDouble("Ecom:Order:OrderLine.UnitPrice.Price.Value");
    double unitDiscount = orderLineTotalDiscount / orderLineQuantity;
    double unitPriceWithProductDiscounts = orderLineTotalPriceWithProductDiscounts / orderLineQuantity;
}

We already have these calculated prices on Dynamicweb.Ecommerce.Orders.OrderLine

  • OrderLine.UnitDiscount
  • OrderLine.UnitPriceWithProductDiscount

The prices are also available on OrderLineViewModel which used by Customer Experience Center and the endpoint at /dwapi/ecommerce/carts/{secret}.
The new properties were added in feature #7681, but it seems that we forgot to add them as template tags.

I guess the only thing we need is to render the two prices as template tags when rendering an order line:

RenderPriceInfo(orderLine.UnitDiscount, template, "Ecom:Order:OrderLine.UnitDiscount");
RenderPriceInfo(orderLine.UnitPriceWithProductDiscount, template, "Ecom:Order:OrderLine.UnitPriceWithProductDiscount");

Would adding those template tags solve your issues?

/Morten

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Morten,

 

Template Tags

Fair enough about the wrong expectation :) The new tags would be great to allow us to have that. Can you give me a Feature # that I can keep track of for that?

 

OrderLineViewModel

The UnitPriceBeforeDiscount and the TotalDiscount properties are there, but they are not populated. I raised this as an issue initially here https://doc.dynamicweb.com/forum/swift/swift/swift-order-details-viewmodel-issues. Here's a smaller repro, using a Swift database:

  • Login
  • Add 5x "Test Discount produt" product
  • Place the order and go to the Order details

If you take a look at the orderlineView model this is what you'll get (below) (disregard the Id of course)

{
  "Id": "DOL24486",
  "ProductId": "PROD100",
  "ProductVariantId": "",
  "ProductLanguageId": "LANG1",
  "ProductName": "Test No Discounts (incl VAT)",
  "ProductNumber": "test01",
  "ProductVariantName": "",
  "ProductImage": "/Files/Images/Products/Bikes/10016.jpg",
  "PrimaryOrDefaultGroup": {
    "Id": "GROUP35",
    "Name": "Sale"
  },
  "Reference": "",
  "Quantity": 3,
  "UnitId": "",
  "UnitName": "",
  "OrderLineFields": {},
  "Price": {
    "CurrencyCode": "USD",
    "PriceWithoutVat": 300,
    "PriceWithoutVatFormatted": "$300.00",
    "PriceWithVat": 300,
    "PriceWithVatFormatted": "$300.00",
    "VatFormatted": "$0.00",
    "VATPercentFormatted": "0%",
    "Price": 300,
    "PriceFormatted": "$300.00",
    "ShowPricesWithVat": true
  },
  "UnitPrice": {
    "CurrencyCode": "USD",
    "PriceWithoutVat": 100,
    "PriceWithoutVatFormatted": "$100.00",
    "PriceWithVat": 100,
    "PriceWithVatFormatted": "$100.00",
    "VatFormatted": "$0.00",
    "VATPercentFormatted": "0%",
    "Price": 100,
    "PriceFormatted": "$100.00",
    "ShowPricesWithVat": true
  },
  "UnitPriceBeforeDiscount": {
    "CurrencyCode": "USD",
    "PriceWithoutVatFormatted": "$0.00",
    "PriceWithVatFormatted": "$0.00",
    "VatFormatted": "$0.00",
    "VATPercentFormatted": "0%",
    "PriceFormatted": "$0.00",
    "ShowPricesWithVat": true
  },
  "TotalDiscount": {
    "CurrencyCode": "USD",
    "PriceWithoutVatFormatted": "$0.00",
    "PriceWithVatFormatted": "$0.00",
    "VatFormatted": "$0.00",
    "VATPercentFormatted": "0%",
    "PriceFormatted": "$0.00",
    "ShowPricesWithVat": true
  },
  "BomOrderLines": []
}

Looks like there's a bug then, would you agree? In which case I would also need a Bug # for it :)

 

Best Regards,

Nuno Aguiar

 

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Morten,

 

Whenever you have the chance, it would be great to know what the direction is, either to wait for the next release with a Bug and a Feature fix, or add patches to Swift templates so we have a working set of templates while this is coming.

 

Best Regards,

Nuno Aguiar

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply
This post has been marked as an answer

Hi Nuno,

There were some issues with discount calculations because it used information from PageView and Common.Context.
That didn't work because PageView and Common.Context is not available/used in the web api.

I have registered bug #10269 and implemented the following fixes

  1. Render missing template tags for discount information on order lines (already available on OrderLineViewModel)
    • Ecom:Order:OrderLine.UnitDiscount
    • Ecom:Order:OrderLine.UnitPriceWithProductDiscount 
  2. Ensure that discount calculations use information from the order instead of PageView or Common.Context

Note: You should probably not be using UnitPriceBeforeDiscount. Just use UnitPrice, UnitDiscount and UnitPriceWithProductDiscount.
UnitPriceBeforeDiscount is set when order line unit price is changed through order edit in the administration or through cart management in front end.

/Morten

Votes for this answer: 1
 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Morten,

 

Perfect, thanks a lot for your help. I will keep an eye out for #10269 and work with the Swift team too.

 

Thanks for the call out on the UnitPriceBeforeDiscount. I will stay clear from that one as much as I possibly can :)

 

Best Regards,

Nuno Aguiar

 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply

Hi Nuno

The bug #10269 has been fixed in Dynamicweb release 9.14.3

Get this from the download section: https://doc.dynamicweb.dk/downloads/dynamicweb-9

Kind Regards
Care Support
Kristian Kirkholt

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Thank you Kristian 

 

You must be logged in to post in the forum