Changing kit product to regular product breaks checkout

by Joe Payne 20. Julie 2012 21:41

Found an obscure bug this week in AC7.  If you have an existing product configured as a kit, changing it to a regular product (removing all kit components) could break your checkout.  Here’s why:

When Able writes a kit product to the basket, it also writes a value to the KitList field on the basket line item record.  This value tells Able to expect the basket line item to be a Kit product.  Same thing when an item is written to a wishlist.

However, when removing components from a kit product in the catalog, Able doesn’t update any existing basket items for the same ProductId.  So any abandoned baskets still have the a value in the KitList field.

If a shopper adds the product (when it was a kit) to their basket and then returns to purchase it AFTER the ProductId is changed to a regular product, Checkout doesn’t know how to handle this.  the KitList field still has a value, but the original product no longer has any components.  Checkout blows up.

A second way to make this happen is the Reorder button.  Often a shopper will log into their My Account page, view their previous order and click the Reorder button.  However, Able code doesn’t validate the previous order products against the current catalog.  It just assumes if the ProductId still exists, it must be configured the same as it was on the previous order.

So the shopper again winds up with a basket item having a KitList value for a product that no longer has components.  Checkout crashes and shoppers cannot complete the purchase.

The solution for the client was two-fold.  First, we had to clear all records from the ac_BasketItems table.  Second, we had to modify the Reorder button to simply redirect to the store catalog instead of repopulating the basket with items.

Tags: , ,

AC7 Articles | Personal

How to loop through kit components for a product

by Joe Payne 15. Februarie 2012 10:50

Here’s a quick code snippet that shows demonstrates how to loop through the kit components assigned to a product.  This is useful when you need to manually parse out something specific from the kit setup of a particular product.

// find the product associated with a particular kit choice 
int _KitProductId = -1;
foreach (ProductKitComponent _PKC in _Product.ProductKitComponents)
{
    KitComponent _KitComp = _PKC.KitComponent;
    foreach (KitProduct _KitProd in _KitComp.KitProducts)
    {
        if (_KitProd.Quantity == 3) // any test you want to make here
        {
            _KitProductId = _KitProd.KitProductId;
            break;
        }
    }
}
 
// if we didn't find a choice in the kit list for the given product, we cannot
// add this item to the basket at this time.  
 
if (_KitProductId == -1)
{
    ErrorMessageDataSource.Insert(new ErrorMessage(MessageSeverity.Error,"CustomCode", "Could not find the product we wanted.");
    continue;
}

Tags: , ,

AC7 Articles

Month List