Skip to content

Instantly share code, notes, and snippets.

@acreeger
Forked from bentayloruk/PromoInfoApi.cs
Created March 14, 2012 19:35
Show Gist options
  • Save acreeger/2038895 to your computer and use it in GitHub Desktop.
Save acreeger/2038895 to your computer and use it in GitHub Desktop.
using Microsoft.CommerceServer.Catalog;
using Microsoft.CommerceServer.Runtime.Profiles;
namespace Enticify.CommerceServer.Tests.Scenarios
{
public class PromoInfoSourceApi
{
public void GetPromoInfoForProductAndDoSomething(Product csProduct, Profile csUserProfile)
{
var promotionQueryService = new PromotionQueryService();
//AC: this implies that AvailableToUser is optional - is that correct?
var promosTargetingProductQuery = new PromotionsTargetingProductQuery(csProduct)
{
AvailableToUser = csUserProfile,
};
ProductPromotionResults productPromotionResults = promotionQueryService.GetPromotions(promosTargetingProductQuery);
//AC: if AvailableToUser is optional, you could also have an override that takes just a csProduct, which saves creating a PromotionsTargetingProductQuery
//AC: unless of course there is more than one type of query that has a product as its principal object.
if (!productPromotionResults.HasPromotionsTargetingProduct)
return;
//Do something cool with the data.
//AC: Now I've put my mind back in CS-land, this makes more sense, but is still a little more ambiguous...
//AC: Does WhereConditionOnly only return products that are conditions, but not awards? It sounds like it should
//AC: If that is the case, how does one get products that are conditions, regardless if they were also awards? Is there a .WhereCondition?
//AC: I've looked through your previous versions of your gist, and think that TargetedAsCondition is a little clearer
//AC: Have you also considered productPromotionResults.findWhere(TargetingScope.Condition | TargetingScope.Award) (with a TargetingScope.ConditionAndAward option too) - I'm sure this can be LINQ-ified.
var conditionInfos = productPromotionResults.WhereConditionOnly;
var awardInfos = productPromotionResults.WhereAwardOnly;
var conditionAndAwardInfos = productPromotionResults.WhereConditionAndAward;
}
}
}
@bentayloruk
Copy link

Yeah, I think I might change it back. The Where* naming is not the guideline, the guidance I was channeling was "Don't be afraid to use specialized collections." and "Developers like to discover APIs by newing stuff up and looking at properties. Have a simple API they can get more advanced with as they get familiar." Of course, it's always difficult to get the balance. BTW - would be great to catch up on Skype sometime. Would be cool to hear more about your fantastic SF life.. Let me know when you have some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment