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.

  • Justin Spradlin 139 posts 347 karma points
    Sep 24, 2011 @ 22:27
    Justin Spradlin
    0

    Add item to cart and checkout programatically

    Hi, 

    I am implementing a very simple store. We are using ucommere to sell subscriptions for our site. Eventually we will add more items but now, I have one product "Membership" with 3 variants for 1 Month, 3 Months and 6 Months. Due to the nature of the site, we are not doing recurring subscriptions. 

    Since our store is so simple now, I have implemented a simple with three radio buttons and a "Ready to purchase". 

    I have tried to figure out how to programatically add items to my cart but I am running into problems with null references. I have tried to mimic the behavior of the XSLT cart, but I am not using XSLT macros, just some server side controls on a masterpage template for our "Buy Now" page. 

     

    Are there any guides on how to add items to a cart and request the payment?

    Thanks,

    Justin

  • Søren Spelling Lund 1797 posts 2786 karma points
    Sep 26, 2011 @ 12:44
    Søren Spelling Lund
    0

    You can add items with the following code:

    // Add product
    var product = Product.All().First(); // Grab any product
    SiteContext.Current.OrderContext.GetBasket().PurchaseOrder.AddProduct(product);

    And request payment like so:

    // Grab purchase order to get order total and billing currency for request
    var purchaseOrder = SiteContext.Current.OrderContext.GetBasket().PurchaseOrder;

    // Find a payment method by name
    var paymentMethod = PaymentMethod.SingleOrDefault(x => x.Name == "Creditcard");

    // Grab the service for the payment method, which is the piece that actually requests payment
    var service = paymentMethod.GetPaymentMethodService();

    // Create a new payment request and request payment from the service
    // Will typically redirect the customer to the payment gateway for payment processing
    var payment = service.RequestPayment(new PaymentRequest(purchaseOrder, paymentMethod,
    new Money(purchaseOrder.OrderTotal.Value, purchaseOrder.BillingCurrency); 

    Hope this helps.

  • Justin Spradlin 139 posts 347 karma points
    Sep 26, 2011 @ 15:52
    Justin Spradlin
    0

    I was able to get it working. Thanks!

  • Søren Spelling Lund 1797 posts 2786 karma points
    Sep 26, 2011 @ 17:05
    Søren Spelling Lund
    0

    Wonderful. Our next reference store implementation should go a long way to help you in the future. It will be based on Razor and .NET exclusively.

  • Justin Spradlin 139 posts 347 karma points
    Sep 26, 2011 @ 17:34
    Justin Spradlin
    0

    That sound great. I was using a dotPeek from Resharper to inspect what was going on in the XSLT extension methods and that as a little slow ;).  

    I had a few starnge problems but they ended being that some how my default product (Membership) had the Price Group Id for Euro not my USD price group id. So I was getting all kinds to strange null ref errors. I also had to manually set the current catalog name on the context by hand since I am not using a traditional store. 

    Let me know if I could help out. I'd like to if I can. 

    Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft