How to use the Advertise field of a Campaign Item of uCommerce
Hi,
I am currently working with the Marketing Functionality of uCommerce. I am trying to get Advertisements directly on the pages of products that have a discount or other marketing campaign connected. I know that you can create custom text fields for an Marketing Campaign Item in the Settings-->Definitions Section of the uCommerce Backend. But how do I access these fields? Is there anything in the API or is there an XSLT command to check if a product is advertised and then extract this advertisement information to display it on the product page?
I know now how to access the custom data fields. But how do I find out, if a certain Product is advertised? I can't find any Advertise Information in the Product class and no Product information in the CampaignItem class
In XSLT you can use CommerceLibrary:GetTargetedCampaignItems() to retrieve campaigns items based on your current context. Any campaign items returned will include XML containing your custom fields.
In .NET the equivalent is to use our targeting service like so:
If you want a list of all active campaign items regardless of the current context you can use MarketingService directly:
var targetingService = ObjectFactory.Instance.Resolve<ITargetingService>(); IList<CampaignItem> targetedCampaignItems = (targetingService as MarketingService).GetActiveCampaignItems();
Please be aware that if you use MarketingService directly as in the latter case your campaign items will not be targeted at all, but it can be useful for creating a global list of discounts.
I dug a little bit into the API and into the tutorials and stumbled several times over the the UCommerce.Runtime.SiteContext. What exactly is it and how do I use it? Is it used to get information to the current Product? And if so, how do I have to set it up to make it work?
By default uCommerce uses SiteContext, specifically CatalogContext, to determine what the customer is currently vieweing. CatalogContext in turn uses the query parameters called catalog, category, and sku to determine what the catelog, category, and product in context are.
If these are not populated Advertise will not work as the current context will never be satisfied.
I'm having a similar issue. I can see how you are doing this with the xslt sample provided as there is a relation between the CampaignItem and product "$campaignItems/campaignItems/campaignItem/product[@sku]". I require to do this with C# and am trying to add this functionality to my razor macro. I used the snippet from above:
There was a similar question a while back on the forum in the post "How can I get bundles through API using C#". It shows how to get specific information from the targets and awards, which make up the campaign item in question.
I just realised that I've been asking the wrong question all along. The reason for campaign items not showing is probably because you've got multiple targets configured in the "Advertise" section. In versions prior to 2.1 uCommerce requires that all these targets are satisfied, e.g. if you've got four product targets set up they all need to be displayed on the same page.
I pushed out the final prerelease of uCommerce 2.1 which changes this behavior: If any of the "Advertise" targets are satified the campaign item will be display, e.g. if any of the four products are on the page the campaign item will show up.
This is probably what has been tripping you up so far.
I downloaded the new package and installed it. I created some new Campaign Items for testing. It works now, but only sometimes, as it seems. I am still using the method mentioned above. I set the CatalogContext with a XSLT extension function and then read the contents of GetTargetedCampaignItems()
It seems to work with single products. If I simply create a Campaign Item and give it an Advertise Field for a specific product, I can read the Text I provided in the "Ad" tab of my product. But there seems to be a bug I cannot quite track down, since in one category, all of the items have the same advertisement text as the one item I actually advertise.
Some things still don't work, I can't create an advertisement for a Category. The corresponding text just won't show up. It is also not possible to create an advertisement for a specific variant of a product, it will also not show up.
I was able to create targeted campaigns items for categories and product families with the default site, but not for individual variants. It seems they never get into context using the default because they're never in context.
is there an xslt equivlent in umbraco 2.0? I had a go trying to build the xml myself but couldnt see how you get the products for the campaign items:
public static XmlDocument AllCampaigns() { StringBuilder sb = new StringBuilder(); sb.Append("<campaigns>"); var targetingService = UCommerce.Infrastructure.ObjectFactory.Instance.Resolve<UCommerce.Marketing.ITargetingService>(); IList<UCommerce.EntitiesV2.CampaignItem> targetedCampaignItems = (targetingService as UCommerce.Marketing.MarketingService).GetActiveCampaignItems(); foreach (UCommerce.EntitiesV2.CampaignItem campItem in targetedCampaignItems) { sb.Append("<campaign name='" + campItem.Campaign.Name + "'>"); foreach(UCommerce.EntitiesV2.CampaignItemProperty p in campItem.CampaignItemProperties) { //how do i get products? } sb.Append("</campaign>"); }
sb.Append("</campaigns>"); XmlDocument doc = new XmlDocument(); doc.LoadXml(sb.ToString()); return doc; }
Sorry didn't catch that one. It's a private method.
It's really just there for convenience. It basically renders unit price discounts in a special way to make them a little easier to work with in XSLT. They will be rendered with default XML even if you leave out the singleProductAward stuff.
How to use the Advertise field of a Campaign Item of uCommerce
Hi,
I am currently working with the Marketing Functionality of uCommerce. I am trying to get Advertisements directly on the pages of products that have a discount or other marketing campaign connected. I know that you can create custom text fields for an Marketing Campaign Item in the Settings-->Definitions Section of the uCommerce Backend. But how do I access these fields? Is there anything in the API or is there an XSLT command to check if a product is advertised and then extract this advertisement information to display it on the product page?
Christian
I know now how to access the custom data fields. But how do I find out, if a certain Product is advertised? I can't find any Advertise Information in the Product class and no Product information in the CampaignItem class
Any ideas?
Christian
In XSLT you can use CommerceLibrary:GetTargetedCampaignItems() to retrieve campaigns items based on your current context. Any campaign items returned will include XML containing your custom fields.
In .NET the equivalent is to use our targeting service like so:
If you want a list of all active campaign items regardless of the current context you can use MarketingService directly:
Please be aware that if you use MarketingService directly as in the latter case your campaign items will not be targeted at all, but it can be useful for creating a global list of discounts.
I tried the XSLT Command, but it returns an Empty XML
<campaignItems><campaignItem /></campaignItems>
Maybe I don't quite understand what "the current context" means here?
I dug a little bit into the API and into the tutorials and stumbled several times over the the UCommerce.Runtime.SiteContext. What exactly is it and how do I use it? Is it used to get information to the current Product? And if so, how do I have to set it up to make it work?
Hi Christian,
By default uCommerce uses SiteContext, specifically CatalogContext, to determine what the customer is currently vieweing. CatalogContext in turn uses the query parameters called catalog, category, and sku to determine what the catelog, category, and product in context are.
If these are not populated Advertise will not work as the current context will never be satisfied.
Hope this helps.
Hi Søren,
I'm having a similar issue. I can see how you are doing this with the xslt sample provided as there is a relation between the CampaignItem and product
"$campaignItems/campaignItems/campaignItem/product[@sku]". I require to do this with C# and am trying to add this functionality to my razor macro.
I used the snippet from above:
This didn't seem to contain anything useful in determining the discount.
Regards,
Olie
There was a similar question a while back on the forum in the post "How can I get bundles through API using C#". It shows how to get specific information from the targets and awards, which make up the campaign item in question.
Once again, this does not seem to work, and I am most certain, that I am making a mistake ;-)
I wrote this in my XSLT:
<xsl:value-of select="MyLibrary:SetCommerceContext($catalogName, $category, $productSku)" />
<textarea cols="100" rows="10">
<xsl:copy-of select="CommerceLibrary:GetTargetedCampaignItems()"/>
</textarea>
The function SetCommerceContext is defined as follows:
public static string SetCommerceContext(string catalog, string category, string sku) {
SiteContext.Current.CatalogContext.CurrentCatalogName = catalog;
SiteContext.Current.CatalogContext.CurrentCategoryName = category;
SiteContext.Current.CatalogContext.CurrentProductSku = sku;
return "";
}
Shouldn't this populate my SiteContext? But the XML I get from CommerceLibrary:GetTargetedCampaignItems() is still empty...
The strings I use as parameters seem to be correct. I printed them and they showed the correct values.
Does it make a difference if you add ?category=categoryName to your URL?
Hi Christian,
I just realised that I've been asking the wrong question all along. The reason for campaign items not showing is probably because you've got multiple targets configured in the "Advertise" section. In versions prior to 2.1 uCommerce requires that all these targets are satisfied, e.g. if you've got four product targets set up they all need to be displayed on the same page.
I pushed out the final prerelease of uCommerce 2.1 which changes this behavior: If any of the "Advertise" targets are satified the campaign item will be display, e.g. if any of the four products are on the page the campaign item will show up.
This is probably what has been tripping you up so far.
Sorry about the inconvenience.
Hi Søren,
I downloaded the new package and installed it. I created some new Campaign Items for testing. It works now, but only sometimes, as it seems. I am still using the method mentioned above. I set the CatalogContext with a XSLT extension function and then read the contents of GetTargetedCampaignItems()
It seems to work with single products. If I simply create a Campaign Item and give it an Advertise Field for a specific product, I can read the Text I provided in the "Ad" tab of my product. But there seems to be a bug I cannot quite track down, since in one category, all of the items have the same advertisement text as the one item I actually advertise.
Some things still don't work, I can't create an advertisement for a Category. The corresponding text just won't show up. It is also not possible to create an advertisement for a specific variant of a product, it will also not show up.
I will perform some more testing to see whats going on.
I was able to create targeted campaigns items for categories and product families with the default site, but not for individual variants. It seems they never get into context using the default because they're never in context.
Hi Soren, you said you can get all campaigns regardless of context with this:
is there an xslt equivlent in umbraco 2.0? I had a go trying to build the xml myself but couldnt see how you get the products for the campaign items:
Thanks in advance for any help
There's not but it's straightforward to create your own. It's basically a wrapper around a couple of calls.
Here's what the XSLT extension will look like:
thanks for the reply! is there a namespace needed for GetSingleProductCampaignItems()? my intellisence doesnt pick it up...
the xml produced without that iteration looks ok:
what does this add?
Sorry didn't catch that one. It's a private method.
It's really just there for convenience. It basically renders unit price discounts in a special way to make them a little easier to work with in XSLT. They will be rendered with default XML even if you leave out the singleProductAward stuff.
is working on a reply...