Developer forum

Forum » Swift » Show how many times you get the same product for free in order summary

Show how many times you get the same product for free in order summary

Caro De Weze
Reply

Hi,

If you receive multiple free products, you don't see the number of free products in the order summary at the cart/checkout. If it concerns different products, these will be nicely listed, but if, for example, I receive 2 of the same products for free, this will not be shown. On my screenshot you can see that I get 'Green paint system' for free, but it does not show that I get it for free twice:

When I look at the code in OrderSummary.cshtml is not provided, but I do want to show this. How do I add this?

Caro

free-products.png

Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Caro

You can do something like this:

@* Discounts (only order discounts) *@
@foreach (LoopItem orderline in GetLoop("OrderLines"))
{
    bool isDiscount = orderline.GetBoolean("Ecom:Order:OrderLine.IsDiscount");
    bool isOrderDiscount = orderline.GetInteger("Ecom:Order:OrderLine.Type") == 1;
    string quantity = string.Empty;
    if (orderline.GetDouble("Ecom:Order:OrderLine.Quantity") > 0)
    {
        //This is a free product - show quantity
        quantity = $" (Qty: {orderline.GetString("Ecom:Order:OrderLine.Quantity")})";
    }
    if (isDiscount && isOrderDiscount)
    {
        <div class="d-flex justify-content-between"><span>@orderline.GetString("Ecom:Order:OrderLine.ProductName")@quantity</span><span class="text-price">@orderline.GetString("Ecom:Order:OrderLine.TotalPriceWithProductDiscounts.PriceFormatted")</span></div>
    }
}

It will add "(Qty: 2)" if there is more than one. You can format it differently if you need to.

BR Nicolai

Votes for this answer: 1
 
Caro De Weze
Reply

Hi Nicolai,

Thanks, that works.

Now I want to show the product id in the same way. I thought this would work with @orderline.GetString("Ecom:Order:OrderLine.ProductID"), but this doesn't. Can you tell me where things are going wrong here:
@foreach (LoopItem orderline in GetLoop("OrderLines")) {
  bool isDiscount = orderline.GetBoolean("Ecom:Order:OrderLine.IsDiscount");
  bool isOrderDiscount = orderline.GetInteger("Ecom:Order:OrderLine.Type") == 1;
  string quantity = string.Empty;
  if (orderline.GetDouble("Ecom:Order:OrderLine.Quantity") > 0) {
    quantity = $" (Qty: {orderline.GetString("Ecom:Order:OrderLine.Quantity")})";
  }
  if (isDiscount && isOrderDiscount) {
 
  <div class="d-flex justify-content-between free-products-and-discounts">
      <span>@orderline.GetString("Ecom:Order:OrderLine.ProductID")</span
      <span>@orderline.GetString("Ecom:Order:OrderLine.ProductName")@quantity</span>
      <span class="text-price">@orderline.GetString("Ecom:Order:OrderLine.TotalPriceWithProductDiscounts.PriceFormatted")</span>
    </div>

  }
}

Thank you in advance.

Caro

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Looks right... Try writing out @orderline.TemplateTags() which will give you all tags on the orderline and its values

 

You must be logged in to post in the forum