logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
Joe Payne2  
#1 Posted : Wednesday, October 7, 2020 2:56:35 PM(UTC)
Joe Payne2

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?

Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

Naveed Ashraf  
#2 Posted : Wednesday, October 14, 2020 1:14:31 PM(UTC)
Naveed Ashraf

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#post1660

2. 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.
Thanks for your support!
Naveed Ashraf
Ablecommerce.com
Developer Assistance Available
Joe Payne2  
#3 Posted : Wednesday, October 14, 2020 2:07:40 PM(UTC)
Joe Payne2

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))] ??
Naveed Ashraf  
#4 Posted : Wednesday, October 14, 2020 2:19:26 PM(UTC)
Naveed Ashraf

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.
Thanks for your support!
Naveed Ashraf
Ablecommerce.com
Developer Assistance Available
thanks 1 user thanked Naveed Ashraf for this useful post.
Joe Payne2 on 10/14/2020(UTC)
Joe Payne2  
#5 Posted : Wednesday, October 14, 2020 2:31:15 PM(UTC)
Joe Payne2

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)
Excellent. Thanks!
Users browsing this topic
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.