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.

  • Igor 25 posts 45 karma points
    Jun 22, 2011 @ 12:26
    Igor
    0

    Ucommerce 2.0.0, how i can get bundles through API using c#

    Hello, dear uCommerce team.

    I was investigating your Marketing libraries, but i can't find a way, how i can get discount bundles using API.

    I wont to get all bundles which are added in umbraco.

    So basicly i need to get list of Compaigns, i had found some MarketingService class, but i can't create instance of that class, i can't find apropriate parameters to pass them in constructor.

    Hope you will help me, and if its possible, please provide some example.

    Thanks and best regards.

  • Igor 25 posts 45 karma points
    Jun 22, 2011 @ 12:36
    Igor
    0

    I made mistake, i can get all Compaigns, and Compaign items, but i can't find a way how to get products which are in compaign item.

  • Igor 25 posts 45 karma points
    Jun 22, 2011 @ 12:43
    Igor
    0

    this is where i had come:

     

    IQueryable<Campaign> campaigns = Campaign.All();

               foreach (Campaign camp in campaigns)

                {

                    foreach (CampaignItem item in camp.CampaignItems)

                    {

                        if (item.Name.ToLower() == "bundle discount")

                        {

     

                            foreach(Target target in Target.Find(x => x.CampaignItemId == item.Id).ToList())  //here i am getting error....

                            {

                                litInfo2.Text += "<br/>" + target.TargetId;

                            }   

                        }

                    }

                }

     

  • Igor 25 posts 45 karma points
    Jun 22, 2011 @ 12:44
    Igor
    0

    This is error message:

    could not resolve property: CampaignItemId of: UCommerce.EntitiesV2.Target [.Where[UCommerce.EntitiesV2.Target](.Select[UCommerce.EntitiesV2.Target,UCommerce.EntitiesV2.Target](NHibernate.Linq.NhQueryable`1[UCommerce.EntitiesV2.Target], Quote((entity, ) => (entity)), ), Quote((x, ) => (Equal(x.CampaignItemId, p1))), )]

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jun 23, 2011 @ 09:48
    Søren Spelling Lund
    0

    Hi Igor,

    Looking into this it seems that we forgot to add a mapping to that particular field. That's the reason for the error you're seeing. What you can do instead is use the CampaignItem property to load the targets like so:

    foreach(Target target in Target.Find(x => x.CampaignItem == item).ToList())
  • Igor 25 posts 45 karma points
    Jun 23, 2011 @ 11:11
    Igor
    0

    Thank you for your reply. Now it works without error. But can you explain for me how i can get products by the target or targetId? Or even, maybe i am going not in the right way. Basicly i wont to get all products which are in Bundle Act. I had spent few days investigating entity v2 without luck. I hope you will help me.

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jun 23, 2011 @ 12:52
    Søren Spelling Lund
    0

    Hi Igor,

    It's a pretty complicated domain to make sense of without docs (we are working on them), but here's how you get the targets for a campaignitem:

    var targetAggregator = ObjectFactory.Instance.Resolve();
    var targets = targetAggregator.GetApplyTargets(campaignItem);
    foreach (var genericTarget in targets.Where(x => x is ProductTarget)
    {
    var productTarget = genericTarget as ProductTarget;
    // product info available in target from properties Sku and VariantSku

    Targets are actually inherited to specific instances so you'll have to downcast to the specific type you want, in this case the ProductTarget.

    Hope it makes sense.

  • Igor 25 posts 45 karma points
    Jun 23, 2011 @ 15:58
    Igor
    0

    I couldn't make your code working, first i decided i am using old version of uCommerce - 2.0.0, i had installed version 2.0.1, but still without luck, so i made some changes, which works for me, i can get product name and id now:

       IQueryable<Campaign> campaigns = Campaign.All();
                foreach (Campaign camp in campaigns)
                {
                    foreach (CampaignItem item in camp.CampaignItems)
                    {
                        if (item.Name.ToLower() == "bundle discount")
                        {

                            IList<Target> targets = Target.Find(x => x.CampaignItem == item);
                            foreach (var genericTarget in targets.Where(x => x is ProductTarget))
                            {
                                var productTarget = genericTarget as ProductTarget;
                                litInfo2.Text += "Product name:" + productTarget.Sku + " Product Id:"
                                    + Product.SingleOrDefault(p => p.Name == productTarget.Sku).Id.ToString() + "<br/>";

                                // product info available in target from properties Sku and VariantSku
                            }
                        }
                    }

     

    Thanks for you very much :-) You really putted me on right way ;-) Best regards.

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jun 24, 2011 @ 08:57
    Søren Spelling Lund
    0

    Cool. BTW I noticed an opportunity to optimize the perf of your code a bit.

    You can bunch up these two lines into a single call:

    foreach (CampaignItem item in camp.CampaignItems)
                    {
                        if (item.Name.ToLower() == "bundle discount")

    Instead try this:

    foreach (CampaignItem item in camp.CampaignItems.Where(x => x.Name.ToLower() == "bundle discount"))
  • Igor 25 posts 45 karma points
    Jun 24, 2011 @ 12:07
    Igor
    0

    Thanks. Nice optimization. But i had 1 more clearing question.

    How can i get Award value of bundle?

    As i understood i should downcast target to award? But, still, i can't find some property in Award class, where award value palced.

    Can you help me with that?

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jun 27, 2011 @ 08:52
    Søren Spelling Lund
    0

    Awards are different from targets. So you want to grab those in the same way you're loading up targets.

    Award.Find(x => x.CampaignItem == myCampaignItem)

    Like Targets there are multiple concrete implementations of the award depending on how it's configured.

  • Igor 25 posts 45 karma points
    Jun 27, 2011 @ 10:51
    Igor
    0

    But how can i get award value? I mean some discount price, i can't see some properties related to that in Award class. Maybe i should use some another logic?

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jun 27, 2011 @ 14:33
    Søren Spelling Lund
    0

    Hi Igor,

    You have to downcast the Award to a specific one. I've attached a screenshot of the concrete types.

  • Igor 25 posts 45 karma points
    Jun 28, 2011 @ 11:33
    Igor
    0

    Thanks, it helped me to figure out. Much appreciate.

Please Sign in or register to post replies

Write your reply to:

Draft