Developer forum

Forum » Integration » Get several prices from Live Prices

Get several prices from Live Prices

David Miguel Luis dos Santos
Reply

Hi all,

I'm looking to retrieve some prices from BC (Live Integration with Live Prices), for different quantities to be rendered on the Product Detail Page.

Saw on a forum post that it could be possible to do it with the Template Extender.

So I made this code and try to debbug it, to check that the code runs. But, when I debug it, I go to a product detail page and the break point (inside the ExtendTemplate method) never gets hit.

using Dynamicweb;
using Dynamicweb.Ecommerce.DynamicwebLiveIntegration.TemplateExtenders;
using Dynamicweb.Environment;
using Dynamicweb.Rendering;

namespace S_DW_Expotape.Custom_Code.Pricing
{
    public class ProductQuantityTemplateExtender : ProductTemplateExtender
    {
        public override void ExtendTemplate(Template template)
        {
            template.SetTag("custom:tag", 1.23);
        }
    }
}

 

Can anyone help on this, please?


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

How did you "make this code"? Did you compile it to a DLL and drop that in the solution's bin foider?

Imar

 
David Miguel Luis dos Santos
Reply

I just created a file with this class and compiled with the solution.

Am I doing it wrong?

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Nope - should be right

Are yuo using Swift? Because Swift renders using the product catalog for viewmodels - it uses models in the template and not template tags like the extender above, and will then never get hit.

Instead you can store the resulting qty prices in a request items or in other cache, and retrieve them using a ProductViewmodel extension method.

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi David,
what templates do you use? Is it Rapido or Swift or something custom?
BR, Dmitrij

 
Roald Haahr
Reply

Hi Dmitriy,

The project David and I are working on is a Swift. We switched to making an extension method for the ProductViewModel to get the prices from BC. However, the prices are not returned as expected. We try to get the prices with the method shown below.

The info returned from calling GetProductInfo

As you see, the Prices entry in the dictionary does not contain any prices and thus the variable livePrices is empty as well.

In BC we have the following prices for 21107.

The prices are retrieved with live integration on the product page and in the cart. We are getting similar results with Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Products.ProductManager. What are we missing?

Kind regards,
Roald

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Roald,
can you check you have activated the Live integration option: ""Use unit prices"" ON?
Then could you also check all Logging checkboxes in the Live integration settings and check the response xml which is in the Files/System/Log/LiveIntegration folder if the prices are actually returned from BC?
Maybe the problem is that you don't get them from BC
BR, Dmitrij

 
Jan Sangill
Reply

Hi, hijacking this thread a little.

I am seing the same thing. When calling:

@{ 
    var product = Dynamicweb.Ecommerce.Services.Products.GetProductById("83666202196", "", true);
    var settings = Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Configuration.SettingsManager.GetSettingsByShop("SHOP1");
    var infoProduct = Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Products.ProductManager.GetProductInfo(product, settings, Pageview.User);
    var prices = Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Products.ProductManager.GetPrices(infoProduct);
}

Prices returned are this:

[
  {
    "Id": null,
    "ProductId": "83666202196",
    "VariantId": null,
    "LanguageId": "LANG1",
    "UnitId": "Unit_STK",
    "CurrencyCode": "DKK",
    "Quantity": 1.0,
    "PeriodId": "",
    "Amount": 495.81675,
    "AmountString": null,
    "CustomerGroupId": "",
    "Priority": 0,
    "CountryCode": null,
    "ShopId": null,
    "ValidFrom": null,
    "ValidTo": null,
    "UserId": null,
    "UserGroupId": null,
    "UserCustomerNumber": "97910338",
    "IsInformative": false,
    "StockLocationId": 0,
    "IsWithVat": false,
    "ExternalId": null
  }
]

So, it is not returning the:

 <table tableName="EcomPrices">
    <item table="EcomPrices">
      <column columnName="PriceProductId"><![CDATA[83666202196]]></column>
      <column columnName="PriceUserCustomerNumber"><![CDATA[97910338]]></column>
      <column columnName="PriceProductUnitId"><![CDATA[Unit_STK]]></column>
      <column columnName="PriceQuantity"><![CDATA[1]]></column>
      <column columnName="PriceAmount"><![CDATA[495.81675]]></column>
      <column columnName="PriceAmountWithVat"><![CDATA[495.817]]></column>
    </item>
  </table>

Also, if I call this on a random place, like in the top of the master layout page, and not in the Productview page - then nothing is returned - because productinfo is null.
Can the live integration code here beused anywhere I want and work - or do I need to use it specifick places?  
var prices = Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Products.ProductManager.GetPrices(infoProduct);

 

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Jan,
it looks like you are missing one method that is triggering the request to the ERP, so your code will not work at every place (where there is no functionality that is triggering the Live requests). The methods you used just use the information from the cache and if it is not present there then no productInfo/prices will be returned.

Try to use this method first and then yours code after this:
Dynamicweb.Ecommerce.DynamicwebLiveIntegration.TemplatesHelper class method:
public static bool UpdateProduct(Product product, double quantity, string currencyCode, string shopId, bool updateCache = false)

You can check if the request was made by enabling all Logging checkboxes in the Live integration settings and check the log file content in the /Files/System/Log/LiveIntegration folder.

BR, Dmitrij

 
Jan Sangill
Reply

Hi, yes, that seemed to help! Thank you!

 
Jan Sangill
Reply

Hi Dmitriy,

If I send updateCache to updateProduct to be true, and then reload the page and only call:

   var infoProduct = Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Products.ProductManager.GetProductInfo(product, settings, Pageview.User);
    var prices = Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Products.ProductManager.GetPrices(infoProduct);

Still nothing is returned. Can it be true I need to call updateProduct on every pageload? And that if UpdateProduct is called with UpdateCache the firsdt time, should it not remember?

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Jan,
If you use the cache level "Page" then - yes, you need to call UpdateProduct with UpdateCache each page load. With Page cache level the product information is only cached per single page load.

If you don't want to call this method at each page load then you need to set the cache level to "Session" for products requests, then the request will only be made if the product was not requested before.

So try to always use the  UpdateProduct method as it will automatically check if the product is in the cache, then if it is it will not be sent in the request.


Kind regards, Dmitrij

 

You must be logged in to post in the forum