The total price of the order in the completed.cshtml

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 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.
7 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'}]);
3 years ago
Hi,

I have similar requirement on my Nop 4.2 site. I need the order total to be present on the checkout/completed page so that my Google Tag Manager scripts can track order totals.

If I can take advantage of the Google Analytics plugin instead of updating the model that would be great.

Below is my Google Analytics script:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src='https://www.googletagmanager.com/gtag/js?id={GOOGLEID}'></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{GOOGLEID}');
{CUSTOMER_TRACKING}
{ECOMMERCE_TRACKING}
</script>

Below is my Google Tag Manager script
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
<!-- End Google Tag Manager -->

Any ideas on how to pass the order total value to GTM ?
2 years ago
Hi

Did you ever find a solution for this?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.