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?
// 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);
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.
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
You can add items with the following code:
And request payment like so:
Hope this helps.
I was able to get it working. Thanks!
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.
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!
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.