Developer forum

Forum » Integration » Tiered pricing with live integration

Tiered pricing with live integration

Caro De Weze
Reply

Hi,

Our customer would like us to add tiered pricing with live integration; is that possible? For example:

  • For 1 piece: Set the standard price, e.g., €10 per piece.
  • For 2 pieces: Add a new pricing rule where the price is reduced, e.g., €18 for 2 pieces (which amounts to €9 per piece).

Kind regards,
Caro De Weze


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Caro,

it is possible using the Live integraiton api. It can return the list of the lowest prices per available Units of measure for the product, but it can not get all available prices per different quantities/currencies using Live integration.
You need to activate the “Use unit prices” option in the Live integration settings and then have
the code like that in your template that will try to get the prices:

using System;

var settings = SettingsManager.GetSettingsByShop(Global.CurrentShopId);
var user = Dynamicweb.Security.UserManagement.UserContext.Current.User;
var productInfo = ProductManager.GetProductInfo(product, settings, user);
if (productInfo != null)
{
    var prices = Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Products.ProductManager.GetPrices(productInfo);

    foreach (var price in prices)
    {
        PriceContext context = new PriceContext(Common.Context.Currency, Common.Context.Country);
        var calculated = PriceCalculated.Create(context, new PriceRaw(price.Amount, Common.Context.Currency), product);
        calculated.Calculate();

        pricesTemplate.SetTag("Ecom:Product.Prices.Amount", calculated.PriceWithoutVATFormattedNoSymbol);
        pricesTemplate.SetTag("Ecom:Product.Prices.AmountFormatted", calculated.PriceWithoutVATFormatted);
        pricesTemplate.SetTag("Ecom:Product.Prices.AmountWithVAT", calculated.PriceWithVAT);
        pricesTemplate.SetTag("Ecom:Product.Prices.AmountWithVATFormatted", calculated.PriceWithVAT);
        pricesTemplate.SetTag("Ecom:Product.Prices.Currency", price.CurrencyCode);
        pricesTemplate.SetTag("Ecom:Product.Prices.VariantID", price.VariantId);
        pricesTemplate.SetTag("Ecom:Product.Prices.UserID", price.UserId);
        pricesTemplate.SetTag("Ecom:Product.Prices.UserCustomerNumber", price.UserCustomerNumber);
        pricesTemplate.SetTag("Ecom:Product.Prices.GroupID", price.UserGroupId);
        pricesTemplate.SetTag("Ecom:Product.Prices.ValidFrom", price.ValidFrom.HasValue ? price.ValidFrom.Value.ToShortDateString() : String.Empty);
        pricesTemplate.SetTag("Ecom:Product.Prices.ValidTo", price.ValidTo.HasValue ? price.ValidTo.Value.ToShortDateString() : String.Empty);
        pricesTemplate.SetTag("Ecom:Product.Prices.UnitID", price.UnitId);
        pricesTemplate.SetTag("Ecom:Product.Prices.LanguageID", price.LanguageId);
        pricesTemplate.SetTag("Ecom:Product.Prices.Country", price.CountryCode);
        pricesTemplate.SetTag("Ecom:Product.Prices.ShopID", price.ShopId);
        pricesTemplate.SetTag("Ecom:Product.Prices.Quantity", price.Quantity);

        pricesTemplate.SetTag("Ecom:Product.Prices.Price", calculated.Price);
        pricesTemplate.SetTag("Ecom:Product.Prices.PricePIP", calculated.PricePIP);
        pricesTemplate.SetTag("Ecom:Product.Prices.PriceFormatted", calculated.PriceFormatted);
        pricesTemplate.SetTag("Ecom:Product.Prices.PriceWithVAT", calculated.PriceWithVAT);
        pricesTemplate.SetTag("Ecom:Product.Prices.PriceWithVATFormatted", calculated.PriceWithVATFormatted);
        pricesTemplate.SetTag("Ecom:Product.Prices.PriceWithoutVAT", calculated.PriceWithoutVAT);
        pricesTemplate.SetTag("Ecom:Product.Prices.PriceWithoutVATFormatted", calculated.PriceWithoutVATFormatted);
        pricesTemplate.SetTag("Ecom:Product.Prices.PriceWithoutVATFormatted", calculated.PriceWithoutVATFormatted);
        pricesTemplate.SetTag("Ecom:Product.Prices.Price.VAT", calculated.VAT);
        pricesTemplate.SetTag("Ecom:Product.Prices.Price.VATFormatted", calculated.VATFormatted);
        pricesTemplate.SetTag("Ecom:Product.Prices.Price.VATPercent", calculated.VATPercent);
        pricesTemplate.SetTag("Ecom:Product.Prices.Price.VATPercentFormatted", calculated.VATPercentFormatted);
        pricesTemplate.SetTag("Ecom:Product.Prices.Currency.Code", calculated.Currency.Code);
        pricesTemplate.SetTag("Ecom:Product.Prices.Currency.Symbol", calculated.Currency.Symbol);                
        pricesTemplate.SetTag("Ecom:Product.Prices.CurrencyName", calculated.Currency.GetName(Common.Context.LanguageID));        
    }
}
}


If that is not suitable then you can consider Odata api approach to import all available prices in the Data integration batch import.


BR, Dmitrij

 

You must be logged in to post in the forum