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.

  • David 29 posts 110 karma points
    Jul 14, 2013 @ 01:40
    David
    0

    How to reference UCommerce.API in a custom UmbracoApiController

    Hi,

    I want to use the Web API / jQuery.Ajax to get product variants, add to cart etc

    I've created a Controller inheriting UmbracoApiController, and placed the controller in the Controllers directory.

    How do I use the UCommerce.API from within my controller?  I want to pass in Product objects etc

    Thanks.

  • David 29 posts 110 karma points
    Jul 15, 2013 @ 00:34
    David
    0

    Can anyone help out with this one?

     

    Thanks.

  • Martin 181 posts 740 karma points
    Jul 16, 2013 @ 19:36
    Martin
    0

    Hi David,

    I have never used WebAPI at this point but as I understand it's just "another" way of providing webservices. In the following example I'm trying to add a product to my basket using the high level API.

    using UCommerce.Api;
    using Umbraco.Web.WebApi;
     
    namespace UCommerceSupport.CustomControllers
    {
    public class BasketApiController : UmbracoApiController
    {
    public void AddToBasket(int quantity, string sku)
    {
    TransactionLibrary.AddToBasket(quantity, sku, variantSku: null, addToExistingLine: true, executeBasketPipeline: true, catalogId: null);
    }
    }
    }
     

    Then you can call your service at /umbraco/basketapi/AddToBasket with AJAX. This is actually first time looking into WebApi but it seems quite easy to pass objects from AJAX. Try to take a look at this:

    http://stackoverflow.com/questions/10493111/asp-net-webapi-how-to-pass-object-with-getjson

    If more questions just ask and I will try to answer :)

    Best regards Martin

     

    Edit: This forum seriously need a "codeblock" >.<

  • David 29 posts 110 karma points
    Jul 16, 2013 @ 20:44
    David
    0

    Thanks for the response, Martin.  The code looks straight forward enough, my problem is how to reference UCommerce.Api namespace.

    I've setup Umbraco in Visual Studio, the installed uCommerce via the package installation.  

    I then create an API controller but am unable to reference the uCommerce.Api namespace.  Do I need to add uCommerce to my project like in this example? http://www.publicvoid.dk/CategoryView,category,uCommerce.aspx

    Cheers,

    David.

  • Martin 181 posts 740 karma points
    Jul 17, 2013 @ 18:46
    Martin
    0

    Yes you need to reference the assemblies you want to use.

    I personally reference all uCommerce assemblies from my own assemblies if they're need in there. Otherwise if you have Resharper it tempts to take assemblies directly from bin folder in website (and that can be annoying if you're working on a team).

    Edit:

    uCommerce.Api lives specificly in ucommerce.dll

Please Sign in or register to post replies

Write your reply to:

Draft