Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Christian Rieß 24 posts 46 karma points
    Oct 04, 2011 @ 13:01
    Christian Rieß
    0

    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

     

  • Christian Rieß 24 posts 46 karma points
    Oct 04, 2011 @ 14:42
    Christian Rieß
    0

    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

     

  • Søren Spelling Lund 1797 posts 2786 karma points
    Oct 04, 2011 @ 21:08
    Søren Spelling Lund
    0

    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:

    IList<CampaignItem> targetedCampaignItems = ObjectFactory.Instance.Resolve<ITargetingService>().GetTargetedCampaignItems();

    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.

  • Christian Rieß 24 posts 46 karma points
    Oct 06, 2011 @ 16:21
    Christian Rieß
    0

    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?

  • Christian Rieß 24 posts 46 karma points
    Oct 10, 2011 @ 15:06
    Christian Rieß
    0

    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?

  • Søren Spelling Lund 1797 posts 2786 karma points
    Oct 10, 2011 @ 17:16
    Søren Spelling Lund
    0

    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.

  • Olie 11 posts 52 karma points
    Oct 11, 2011 @ 03:56
    Olie
    0

    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:

    IList<CampaignItem> targetedCampaignItems =ObjectFactory.Instance.Resolve<ITargetingService>().GetTargetedCampaignItems();

    This didn't seem to contain anything useful in determining the discount.

    Regards,
    Olie

  • Søren Spelling Lund 1797 posts 2786 karma points
    Oct 11, 2011 @ 14:46
    Søren Spelling Lund
    0

    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.

     

  • Christian Rieß 24 posts 46 karma points
    Oct 11, 2011 @ 16:20
    Christian Rieß
    0

    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.

  • Søren Spelling Lund 1797 posts 2786 karma points
    Oct 14, 2011 @ 15:34
    Søren Spelling Lund
    0

    Does it make a difference if you add ?category=categoryName to your URL?

  • Søren Spelling Lund 1797 posts 2786 karma points
    Oct 17, 2011 @ 12:09
    Søren Spelling Lund
    0

    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.

  • Christian Rieß 24 posts 46 karma points
    Oct 26, 2011 @ 11:45
    Christian Rieß
    0

    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.

  • Søren Spelling Lund 1797 posts 2786 karma points
    Nov 08, 2011 @ 11:33
    Søren Spelling Lund
    0

    I will perform some more testing to see whats going on.

  • Søren Spelling Lund 1797 posts 2786 karma points
    Nov 15, 2011 @ 16:02
    Søren Spelling Lund
    0

    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.

  • Phil Crowe 192 posts 256 karma points
    May 23, 2012 @ 12:38
    Phil Crowe
    0

    Hi Soren, you said you can get all campaigns regardless of context with this:

    var targetingService =ObjectFactory.Instance.Resolve<ITargetingService>();
    IList<CampaignItem> targetedCampaignItems =(targetingService asMarketingService).GetActiveCampaignItems();


     

     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;

     

    Thanks in advance for any help

     

     

  • Søren Spelling Lund 1797 posts 2786 karma points
    May 24, 2012 @ 09:10
    Søren Spelling Lund
    0

    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:

    /// <summary>
    /// Gets all active <see cref="CampaignItem">campaign items</see>.
    /// </summary>
    public static XPathNodeIterator GetActiveCampaignItems()
    {
        var marketingService = ObjectFactory.Instance.Resolve<ITargetingService>() as MarketingService;
    
        var discountRender = ObjectFactory.Instance.Resolve<IXmlRenderer<CampaignItem>>();
        var document = discountRender.RenderDocument(marketingService.GetActiveCampaignItems(), "campaignItems");
    
        // Render singleProductAwards
        var singleProductAwardIndex = 0;
        var singleProductAwardsElement = document.CreateElement("campaignItem");
        var singleProductAwardRenderer = new SingleProductAwardRenderer();
        foreach (var campaignItem in GetSingleProductCampaignItems())
        {
            singleProductAwardsElement.AppendChild(singleProductAwardRenderer.Render(document, campaignItem, singleProductAwardIndex++));
        }
        document.DocumentElement.AppendChild(singleProductAwardsElement);
    
        return document.GetXPathNodeIterator();
    }
  • Phil Crowe 192 posts 256 karma points
    May 24, 2012 @ 10:48
    Phil Crowe
    0

    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:

     

     public static XmlDocument GetActiveCampaignItems()
     {
              var marketingService = ObjectFactory.Instance.Resolve<ITargetingService>() as MarketingService;
    
              var discountRender = ObjectFactory.Instance.Resolve<IXmlRenderer<CampaignItem>>();
              var document = discountRender.RenderDocument(marketingService.GetActiveCampaignItems(), "campaignItems");
    
              // Render singleProductAwards
              var singleProductAwardIndex = 0;
              var singleProductAwardsElement = document.CreateElement("campaignItem");
              var singleProductAwardRenderer = new SingleProductAwardRenderer();
            /*
                foreach (var campaignItem in marketingService.)
        {
            singleProductAwardsElement.AppendChild(singleProductAwardRenderer.Render(document, campaignItem, singleProductAwardIndex++));
        }
              * */
        document.DocumentElement.AppendChild(singleProductAwardsElement);
        return document;
    }  

    what does this add?

     

  • Søren Spelling Lund 1797 posts 2786 karma points
    May 25, 2012 @ 09:07
    Søren Spelling Lund
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft