Developer forum

Forum » Ecommerce - Standard features » DiscountID in orderline

DiscountID in orderline

Nuno Aguiar
Reply

Hi,

 

We need to assign an image to a discount orderline. We created an item list (website) so the user could assign an image to a discount.

 

So far so good and we did that with Sales Discount for a client, but there are 2 problems:

  1. We don't get a tag with the DiscountID - we used Razor for that (bad for performance though)
    var orderLine = Dynamicweb.eCommerce.Orders.OrderLine.GetOrderLineByID(str_orderId);
    
    string discountId = orderLine.DiscountID.ToString();
  2. Using the Discount Matrix, the orderline does not have a DiscountID, when we use a reusable discount code

 

These situations are both in 8.5.1.14. It looks like a bug both in the the tags (issue 1) and the discount matrix (issue 2). Can someone confirm?

 

Best Regards,

Nuno Aguiar


Replies

 
Nicolai Høeg Pedersen
Reply

@1: In which template are you refering to?

@2: Both sales discounts and order discounts stores their IDs at Orderline.DiscountID. (Or what is a reusable discount code?) They also use the same types of orderlines, see this thread:

http://developer.dynamicweb.com/forum/ecommerce-standard-features/ecommerce-standard-features/discount-matrix-vs--sales-discount.aspx

 
Nicolai Høeg Pedersen
Reply

Attached a screen dump of the data in a cart with a product and a discount from the order discounts (Discount matrix)

Capture.PNG
 
Nuno Aguiar
Reply

Hi Nicolai,

 

This is inline with the http://developer.dynamicweb.com/forum/feature-requests/image-for-discounts.aspx request

 

Please check out http://dwhotfix.fasteddie.dw-demo.com/

  • Using TemplateTags() within the orderlines just breaks the template - I guess there's a bug
  • We need to assign a specific image according to the DiscountID (so your suggestion is not enough)
  • Issue 1 is within the cart (show cart) - Add http://dwhotfix.fasteddie.dw-demo.com/products/magpul%E2%84%A2-field-case-%E2%80%93-iphone%C2%AE-5-5s to the cart and go to "Edit Cart" and use "MAG10" as promo voucher
  • If you go to the backend and change the discount to a single use discount you will get the DiscountID with the query described in issue 1 (this is issue 2)

 

Best Regards,

Nuno Aguiar

 
Nicolai Høeg Pedersen
Reply

Hi Nuno

I'm totally confused (again). A discount is added as an orderline on the order - and everyone of them have an ID...Use eCommerce.Context.Cart to get the cart instance already loaded to avoid getting the extra DB calls.

You can simply do like this: <img src="path/<!--DiscountID-->.jpg"> or <img src="@CleverRazorFunctionThatLooksUpAnItemGetImageByDiscountID("DiscountID")">

Or am I missing something?

 
Nuno Aguiar
Reply

Hi Nicolai,

 

Thanks for the eCommerce.Context.Cart tip to avoid the extra DB calls.

 

As for the missing ID, we noticed by looking into the database that when a "reusable" voucher code is being rendered, the ordeline is there, but the DiscountID value was empty/null (in the database). Probably the eCommerce.Context.Cart has it. Will take a look at it and get back to you.

 

Thanks,

Nuno

 
Nuno Aguiar
Reply

Hi Nicolai,

 

We tried to get the discountID, but did not work

foreach (var orderline in Dynamicweb.eCommerce.Common.Context.Cart.OrderLines)
{
    <p>@orderline.DiscountID</p>
}

DiscountID is empty.



 

foreach (var orderline in Dynamicweb.eCommerce.Common.Context.Cart.OrderLines)
{
    <p>@orderline.DiscountID.ToString()</p>
}

Exception in template (Designs\Magpul\eCom7/CartV2/Step/ShowCart.cshtml): System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.dfebbbacdfaaffcfbdcf.Execute()
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context)
   at RazorEngine.Templating.TemplateService.Run(ITemplate template, DynamicViewBag viewBag)
   at RazorEngine.Templating.TemplateService.Parse(String razorTemplate, Object model, DynamicViewBag viewBag, String cacheName)
   at RazorEngine.Razor.Parse[T](String razorTemplate, T model, String cacheName)
   at Dynamicweb.Rendering.Template.Output()

 

Can you replicate it?

 

Best Regards,

Nuno

 
Nicolai Høeg Pedersen
Reply

It is not all orderlines that have a discount ID - only the discount lines. So calling ToString will fail when on normal orderlines.

 
Nuno Aguiar
Reply

Hi Nicolai,

 

I answered that with little context. That piece of code only runs when Ecom:Order:OrderLine.Type != 4 and the Ecom:Order:OrderLine.IsProduct is false (Dynamicweb 8.5.1)

 

The problem is Discount orderlines generated by the discount matrix, when discount condition is a reusable field, does not have the discountID. I cheked the DB. The orderline is there, the discount amount is correct, but the discountID is empty.

 

Hope it is clear now.

 

Best Regards,

Nuno

 
Nicolai Høeg Pedersen
Reply

I get the id's just fin, see attached screen.

Also my template attached. And screen of my discount.

Can you ellaborate?

Capture.PNG Capture2.JPG
 
Nuno Aguiar
Reply

Hi Nicolai,

 

We can't seem to get it to work

http://screencast.com/t/F1BtPQ69

 

Can you test it in http://dev.fasteddie.dw-demo.com/ ?

 

Best Regards,

Nuno

 
Nicolai Høeg Pedersen
Reply

I just inserted it, see dump:

Capture.JPG
 
Nuno Aguiar
Reply

Hi Nicolai,

 

Try it adding this product (in orange) http://dev.fasteddie.dw-demo.com/products/magpul%E2%84%A2-field-case-%E2%80%93-iphone%C2%AE-6

 

We have 1 discount of 50% using Sales Discounts (returns an ID) and another discount also of 50% (no ID). This is the one used in the screencast

 

(update) Looking back at the issue, and now testing in 8.6 looks like the Discount Matrix is not triggering a DiscountID, so it's not only a matter of a reusable voucher code

 

Best Regards,

Nuno

 
Nuno Aguiar
Reply

Hi Nicolai,

 

Did you manage to reproduce the problem? I need to provide a solution for this and I am stuck right now.

 

Best Regards,

Nuno

 
Nicolai Høeg Pedersen
Reply

Hi Nuno

You need to get an image on the checkout page?

You can see on the orderlines the name of the discount. Loop through the discounts and find the id by comparing the name from the orderline with the name on the discount. Best I can do right now. I can get the ID out for some reason... Will have someone look at it for 8.7

BR Nicolai

 
Nuno Aguiar
Reply

Hi Nicolai,

 

Well, I guess comparing the name seems to be the only way out. Thanks,

 

Nuno

 

You must be logged in to post in the forum