API
Version 7.x > API > Product update after bundle item change View modes: 
User avatar
Member
Member
mantis - 6/18/2013 9:48:42 AM
   
Product update after bundle item change
Hey,

I have ecommerce site where I set up products. Some products can be bundles.
The bundle price is calculated using each bundle item price.
For example:
Main product: Shower, Price : 0
Bundle item: Head, Price 100
Bundle item: Mixer, Price 200

So the total price of shower is 300.
I need this price for product ordering in the list (by price asc/desc) and for display in product details.

For this I created additional field in CMS.Product, called TotalPrice.
Then subscribed to global events...
DocumentEvents.Insert.Before += Document_Insert_Before;
DocumentEvents.Update.Before += Document_Update_Before;
DocumentEvents.Delete.Before += Document_Delete_Before;

And here problems starts:
1. Document_Update_Before does not see yet that bundle item was added or removed.. it happens later... Update.After event does not help too...
I am using: InfoDataSet<SKUInfo> items = SKUInfoProvider.GetBundleItems(product.SKUID);
This finally I solved by creating CustomBundleInfoProvider...

2. Document_Delete_Before - here I am trying to find all parent products to which document belongs as bundle item using such select:
select BundleID as ParentSkuID from COM_Bundle where SKUID = @deletedSkuId
and it seems that in Document.Before event these entries ALREADY removed, so I cannot find affected products anymore. And it looks like CustomBundleInfoProvider is not called at all.

Can you please advice, how can I reliable update document TotalPrice when changing child (bundle items) products.

I am using Kentico 7.34, web site.

regards
Mantas

User avatar
Certified Developer 13
Certified Developer 13
kentico_josefd - 7/11/2013 4:11:34 AM
   
RE:Product update after bundle item change
Hello,

You are correct in your description of why it is not suitable to use the handlers for this functionality, they simply do not carry the required information (or carry it too late) to be helpful. However after some investigation I have found the method DeleteSKUInfoInternal that is used to remove SKU and its dependencies.

Overriding this method using custom provider and registering it in the CMS should allow you to get the SKUID of the product before it gets deleted from the COM_Bundle:

namespace CustomProviders
{
/// <summary>
/// Customized ShippingOptionInfo provider.
/// </summary>
public class CustomSKUInfoProvider : SKUInfoProvider
{
protected override void DeleteSKUInfoInternal(SKUInfo skuObj)
{
// Your logic here

base.DeleteSKUInfoInternal(skuObj);
}
}
}


Regards,
Josef Dvorak