The total price of the order in the completed.cshtml

2 years ago
It is possible in version 3.80 (and above) insert information about the total price of the order to completed.cshtml without modifying the model? I need insert this information to conversion script. In version 3.50 this worked:


@model CheckoutCompletedModel
@using Nop.Web.Models.Checkout;
@using Nop.Core;
@using Nop.Core.Infrastructure;
@using Nop.Core.Domain.Orders;
@{
    var _orderService = EngineContext.Current.Resolve<Nop.Services.Orders.IOrderService>();
    var order = _orderService.GetOrderById(Model.OrderId);
}
@{
    Layout = "~/Views/Shared/_ColumnsOne.cshtml";

    //title
    Html.AddTitleParts(T("PageTitle.Checkout").Text);
}
<div class="page checkout-page">
    @if (!Model.OnePageCheckoutEnabled)
    {
        @Html.Action("CheckoutProgress", "Checkout", new { step = CheckoutProgressStep.Complete })
    }
    <div class="page-title">
        <h1>@T("Checkout.ThankYou")</h1>
    </div>
    <div class="page-body checkout-data">
        @Html.Widget("checkout_completed_top")
        <div class="section order-completed">
            <div class="title">
                <strong>@T("Checkout.YourOrderHasBeenSuccessfullyProcessed")</strong>
            </div>
            <ul class="details">
                <li>
                    @T("Checkout.OrderNumber"): @Model.OrderId
                </li>
                <li>
                    <a href="@Url.RouteUrl("OrderDetails", new { orderID = Model.OrderId })">@T("Checkout.PlacedOrderDetails")</a>
                </li>
            </ul>
            <div class="buttons">
                <input type="button" value="@T("Checkout.ThankYou.Continue")" class="button-2 order-completed-continue-button" onclick="setLocation('@Url.RouteUrl("HomePage")')" />
            </div>
        </div>
        @Html.Widget("checkout_completed_bottom")
    </div>
</div>

<iframe width="119" height="22" frameborder="0" scrolling="no" src="http://any.server.com/checkConversion?c=123456789&[email protected]"></iframe>


But in version 3.80 does not work - it says error:

\Views\Checkout\Completed.cshtml(46): error CS0103: The name 'order' does not exist in the current context.
2 years ago
I haven't tested with that particular script before, but you can probably take advantage of the Google Analytics plugin. It already has the {TOTAL} variable exposed on the Thank you page. That's what I do with the Facebook, Bing, and Google remarketing tracking...

It appears to just be a page being called within an iframe...like the facebook pixel code.

You'd just need to write a bit of simple javascript to open a new window(off screen) and load that URL in it using the already present {TOTAL} variable.

For example, here's the chunk of code I put into the "Tracking code for {ECOMMERCE} part, with {DETAILS} line:" (middle section) of the Google Analytics plugin for tracking Facebook conversions:

(function() {
  var _fbq = window._fbq || (window._fbq = []);
  if (!_fbq.loaded) {
    var fbds = document.createElement('script');
    fbds.async = true;
    fbds.src = '//connect.facebook.net/en_US/fbds.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(fbds, s);
    _fbq.loaded = true;
  }
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', '1029384756', {'value':'{TOTAL}','currency':'USD'}]);