How to get SKU price with discounts for a specified user?

Alexander Ulmaskulov asked on September 26, 2018 09:20

Could you tell me please, how to get SKU price with discounts for a specified user?

I work with Kentico from console application through C# API.

CMS.DataEngine.CMSApplication.Init();  
var sku = SKUInfoProvider.GetSKUInfo(5069);  
var price = SKUInfoProvider.GetSKUPrice(sku, null, true, false);  

So, I want to apply user discounts for a price. I need to execute this method from specified user context, I guess.
Thanks in advance!

Correct Answer

Alexander Ulmaskulov answered on October 24, 2018 11:06

I found the solution. I thought, that I need to use context or something else. But no. Code (C#):

if (CMS.DataEngine.CMSApplication.Init())
{
    SiteContext.CurrentSiteID = 1;
    var userInfo = UserInfoProvider.GetUserInfo("alexander@ulmaskulov.ru");
    var skuInfo = SKUInfoProvider.GetSKUInfo(5069);
    var cart = ShoppingCartFactory.CreateCart(new 
    SiteInfoIdentifier(SiteContext.CurrentSite.SiteID), userInfo);
    var price = SKUInfoProvider.GetSKUPrice(skuInfo, cart, true, false);
}
0 votesVote for this answer Unmark Correct answer

Recent Answers


Suneel Jhangiani answered on September 26, 2018 11:48

Which version of Kentico are you using as there were considerable changes to the Ecommerce module in v11 that would make this easier.

1 votesVote for this answer Mark as a Correct answer

Alexander Ulmaskulov answered on September 26, 2018 12:37 (last edited on September 26, 2018 12:39)

We use Kentico10. And now I have discovered the problem source:
ECommerceContext.CurrentShoppingCart // is null in our console application.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.