Showing product discounts with GetTargetedCampaignItems
Hi there,
I'm using CommerceLibrary:GetTargetedCampaignItems() to get the relevant discounts for a product page. However, there seem to be many cases where this isn't pulling through discounts.
For example, I have a £5 discount on all items in category x, so I do:
Advertise: Product Category x
Act: Product Category x
Award: Amount off order total £5 (actually, 4.13 given the 20% VAT)
However, using GetTargetedCampaignItems from the context of a relevant product page doesn't give me the discount. I can only access it from the category page context.
I don't even understand how CommerceLibrary:GetTargetedCampaignItems() knows what context I'm looking at, since it doesn't take any parameters.
The only way I can find for showing discounts on a product page is to create a whole new discount for each product. I can't list multiple products under "Advertise" because this seems to be an AND rather than an OR (so only shows where the condition matches all).
Do I need to be writing some c# controls to do this? And how does GetTargetedCampaignItems know what I'm looking at?
The Category target pulls campaign items when you're actually viewing the specified category, which is not the case on the product page by default. I can see how this might be confusing.
The context, which tells marketing foundation what you're looking at, is populated by "Populators". Each populator is resposible for grabbing a piece of the context and serving it up to marketing foundation.
The category populator for example will use the CatalogContex class to find the current category. If you wish to include category level discounts on your product page make sure that CatalogContext.CurrentCategoryName is set to the category you want included. By default you do this by including a querystring paramter called category=MyCategory.
If you use the built-in friendly URLs and make sure to include category information in your product URL by using CommerceLibrary:GetNiceUrl(catalogName, categoryName, sku) you should have the information required available to marketing foundation.
You can populate the category by adding a new popular to marketing foundation if you don't want the category as part of your URL. If you take a look at one of the existing ones it should be pretty obvious how to accomplish that. Once it's done you'll want add it to marketing.config found in /umbraco/ucommerce/configuration.
Cheers Søren. I had a look into this, but got a little bit lost and wasn't sure if it was worth the time figuring out at this stage. I'm not even sure where these populators live, i.e. filesystem, database, etc? Also, putting the category back in the URL gives some other benefits (such as keeping the correct category expanded in the navigation!)
So I'm putting the category in the URL. Which is great, but raises a new issue (oh no!)
I'm not sure how to have those categories included in the URL to a product when using related products. From a specific product's page, when I pull in the list of related products, I'm not sure how to find out what category they are in. I'm using:
But this gives no info about the category a product is in (and I understand why - it's not straight forward as a product can be in any number of categories).
So perhaps just using the questystring parameter isn't the way to solve the problem?
Regarding categories for products you could go looking for matching categories for the related products, but it might confusing that the category changes when you navigated to Category A => Product A => Product B and find yourself in Category B as well. I'd probably just use Category A for the products.
BTW the populators are .NET code, which implement ITargetingContextPopulator and live in an assembly in the /bin folder of your site. They are configured in /umbraco/ucommerce/configuration/marketing.config.
Hi again Søren. Just to come back to this a little late.
I originally sidestepped this issue by simply not using category discounts and not getting into the populators. We're now trying to think of a way to create an XML product feed that can be used with third parties, e.g. a shopping comparison site.
The real issue I can't get my head around is how to feed out the correct product prices. Would we need to iterate every product in the system and apply these populators to find out the correct price to putin the feed?
Depending on the type of discounts you might not be able to display the proper price at all. Typically only unit price discounts make are able to be displayed in the way you describe as any other type of discount depends on the composition of the cart, e.g. 10% off if you buy product A and B together.
In your case you probably want to get all active campaign items instead of just the ones in the context. You can do that by using MarketingService and GetActiveCampaignItems.
Showing product discounts with GetTargetedCampaignItems
Hi there,
I'm using CommerceLibrary:GetTargetedCampaignItems() to get the relevant discounts for a product page. However, there seem to be many cases where this isn't pulling through discounts.
For example, I have a £5 discount on all items in category x, so I do:
However, using GetTargetedCampaignItems from the context of a relevant product page doesn't give me the discount. I can only access it from the category page context.
I don't even understand how CommerceLibrary:GetTargetedCampaignItems() knows what context I'm looking at, since it doesn't take any parameters.
The only way I can find for showing discounts on a product page is to create a whole new discount for each product. I can't list multiple products under "Advertise" because this seems to be an AND rather than an OR (so only shows where the condition matches all).
Do I need to be writing some c# controls to do this? And how does GetTargetedCampaignItems know what I'm looking at?
Cheers,
Zac
Hi Zac,
The Category target pulls campaign items when you're actually viewing the specified category, which is not the case on the product page by default. I can see how this might be confusing.
The context, which tells marketing foundation what you're looking at, is populated by "Populators". Each populator is resposible for grabbing a piece of the context and serving it up to marketing foundation.
The category populator for example will use the CatalogContex class to find the current category. If you wish to include category level discounts on your product page make sure that CatalogContext.CurrentCategoryName is set to the category you want included. By default you do this by including a querystring paramter called category=MyCategory.
If you use the built-in friendly URLs and make sure to include category information in your product URL by using CommerceLibrary:GetNiceUrl(catalogName, categoryName, sku) you should have the information required available to marketing foundation.
Hope this helps.
That's really helpful, thanks Søren.
We'd chopped out the category from the URL for SEO purposes, which is why it wasn't working!
You can populate the category by adding a new popular to marketing foundation if you don't want the category as part of your URL. If you take a look at one of the existing ones it should be pretty obvious how to accomplish that. Once it's done you'll want add it to marketing.config found in /umbraco/ucommerce/configuration.
Cheers Søren. I had a look into this, but got a little bit lost and wasn't sure if it was worth the time figuring out at this stage. I'm not even sure where these populators live, i.e. filesystem, database, etc? Also, putting the category back in the URL gives some other benefits (such as keeping the correct category expanded in the navigation!)
So I'm putting the category in the URL. Which is great, but raises a new issue (oh no!)
I'm not sure how to have those categories included in the URL to a product when using related products. From a specific product's page, when I pull in the list of related products, I'm not sure how to find out what category they are in. I'm using:
But this gives no info about the category a product is in (and I understand why - it's not straight forward as a product can be in any number of categories).
So perhaps just using the questystring parameter isn't the way to solve the problem?
Hi Zac,
Gotcha.
Regarding categories for products you could go looking for matching categories for the related products, but it might confusing that the category changes when you navigated to Category A => Product A => Product B and find yourself in Category B as well. I'd probably just use Category A for the products.
BTW the populators are .NET code, which implement ITargetingContextPopulator and live in an assembly in the /bin folder of your site. They are configured in /umbraco/ucommerce/configuration/marketing.config.
Hi again Søren. Just to come back to this a little late.
I originally sidestepped this issue by simply not using category discounts and not getting into the populators. We're now trying to think of a way to create an XML product feed that can be used with third parties, e.g. a shopping comparison site.
The real issue I can't get my head around is how to feed out the correct product prices. Would we need to iterate every product in the system and apply these populators to find out the correct price to putin the feed?
Many thanks,
Zac
Depending on the type of discounts you might not be able to display the proper price at all. Typically only unit price discounts make are able to be displayed in the way you describe as any other type of discount depends on the composition of the cart, e.g. 10% off if you buy product A and B together.
However, this post will show you how to iterate the discounts and see what they are: http://our.umbraco.org/projects/website-utilities/ucommerce/ucommerce-support/21481-Ucommerce-200,-how-i-can-get-bundles-through-API-using-c?p=0
In your case you probably want to get all active campaign items instead of just the ones in the context. You can do that by using MarketingService and GetActiveCampaignItems.
Hope this helps.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.