Rank: Advanced Member
Groups: HelpDesk, Developers Joined: 11/9/2018(UTC) Posts: 564
Thanks: 122 times Was thanked: 26 time(s) in 25 post(s)
|
In Able Gold, the payment-widget user control abstracted both a void CheckingOut() and a void CheckedOut() method. This was invaluable when I needed to hook into the post-checkout behaviors regardless of which payment method was used during the checkout process. Each payment method was coded to call those abstracted methods if they were specified.
It doesn't seem this same design was followed in v9 code. Am I missing it somewhere?
|
|
|
|
Rank: Advanced Member
Groups: Admin, Administrators, Developers, Registered, HelpDesk, Authorized User Joined: 7/31/2019(UTC) Posts: 77
Was thanked: 8 time(s) in 8 post(s)
|
Hi, Yes you are right, the mentioned CheckingOut() and CheckedOut() event methods are lost while moving to MVC and controller classes. Alternately for post checkout processing you can use one of the two following approaches: 1. Implement your own custom OrderPlaced event handler, this event is fired when order is placed. For details check this forum post: https://www.ablecommerce...ers-by-username#post16602. Override the ExecuteCheckout() method of CommerceBuilder.Services.Checkout.CheckoutService class. The ICheckoutService defines only one method "ExecuteCheckout", which you can override/extend for your requirement. Here I provide you some sample code that how you can override/extend it easily in your scenario. just save the class in your App_Code or "Code" folder under your website, and register the service implementation for IOC container. Code:namespace My.Organization.XYZ.Services.Checkout
{
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using CommerceBuilder.Common;
using CommerceBuilder.Orders;
using CommerceBuilder.Services.Checkout;
using CommerceBuilder.DomainModel;
/// <summary>
/// Provides services to convert a shopping session to an order.
/// </summary>
[RegisterFor(typeof(ICheckoutService))]
public class CustomCheckoutService : CheckoutService
{
/// <summary>
/// Executes a checkout request.
/// </summary>
/// <param name="checkoutRequest">The checkout request</param>
/// <param name="validateBasket">A value indicating whether the basket should be validated before executing checkout.</param>
/// <param name="triggerEvents">If 'true' store events are triggered during the checkout. If 'false' store events are suppressed.</param>
/// <returns>The checkout response</returns>
public override CheckoutResponse ExecuteCheckout(CheckoutRequest checkoutRequest, bool validateBasket = true, bool triggerEvents = true)
{
Basket basket = checkoutRequest.Basket;
IBasketService basketService = AbleContext.Resolve<IBasketService>();
/*******************************************/
/*perform your pre-checkout operations here*/
/*******************************************/
// prepare basket items data, as it might not be avilable after a successful checkout request
var response = base.ExecuteCheckout(checkoutRequest, validateBasket, triggerEvents);
if(response.Success)
{
// perform your post checkout operations here
}
// return a successful checkout response
return response;
}
}
}
NOTE: note that I am actually calling the base base.ExecuteCheckout() function so, everything will work properly regarding checkout. You just need to wire-up your custom code as suggested in comments. |
|
|
|
|
Rank: Advanced Member
Groups: HelpDesk, Developers Joined: 11/9/2018(UTC) Posts: 564
Thanks: 122 times Was thanked: 26 time(s) in 25 post(s)
|
Ohhhhhh. So I could handle both a pre-checkout and post-checkout situation, and maintain the original checkout behavior, without changing actual checkout code. Well played, sir :)
When you say "and register the service implementation for IOC container", haven't you already done that with [RegisterFor(typeof(ICheckoutService))] ??
|
|
|
|
Rank: Advanced Member
Groups: Admin, Administrators, Developers, Registered, HelpDesk, Authorized User Joined: 7/31/2019(UTC) Posts: 77
Was thanked: 8 time(s) in 8 post(s)
|
Quote:When you say "and register the service implementation for IOC container", haven't you already done that with [RegisterFor(typeof(ICheckoutService))] ?? Yes, you are right. Using RegisterFor attribute we can register the implementation for IOC container. |
|
1 user thanked Naveed Ashraf for this useful post.
|
|
|
Rank: Advanced Member
Groups: HelpDesk, Developers Joined: 11/9/2018(UTC) Posts: 564
Thanks: 122 times Was thanked: 26 time(s) in 25 post(s)
|
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The AbleCommerce Forums uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close