API Questions on Kentico API.
Version 6.x > API > Custom inventory rules View modes: 
User avatar
Member
Member
heybro-yopmail - 5/3/2012 9:49:49 AM
   
Custom inventory rules
Hi again!

I'd like to know how could I change the inventory rules (which files ?) when an order is completed in the Kentico ECommerce.
I mean, because bundle products dont offer the possibility to decrement the inventory of products which are part of the bundle product, I'd like to be able to decrement them manually.

I have doubts on it as I think the functions are located in the ECommerce.dll

Thanks

User avatar
Member
Member
heybro-yopmail - 5/4/2012 7:50:03 AM
   
RE:Custom inventory rules
Anybody can tell me where these functions are located ?

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 5/5/2012 7:33:58 AM
   
RE:Custom inventory rules
Hello,


you can add the custom code to the check-out process when we create an order ~\CMSModules\Ecommerce\Controls\ShoppingCart\ShoppingCartPreview.ascx.cs - the ProcessStep() method. Or you can customize the SetOrder method which creates the order from the shopping cart. We use this method (ShoppingCartInfoProvider.SetOrder(this.ShoppingCartInfoObj)) in the method mentioned above.

See here: E-commerce 6 - New customization model for more details how to customize the e-commerce built-in methods or providers.


Best regards,
Helena Grulichova

User avatar
Member
Member
heybro-yopmail - 5/7/2012 9:06:49 AM
   
RE:Custom inventory rules
Thanks Helena for your answer and for the link given which was very instructive.

The first thing I wanted to do was to update sku quantities once the order is completed and finished, I found the function SKUInfoProvider. UpdateInventoryInternal(ShoppingCartInfo cartObj) whicht one matches with the function ShoppingCartInfoProvider.ActualizeSKUAvailableItems(ShoppingCartInfo shoppingCart) in the previous version so I think it's the good one.

But I'm unable to change sku quantites with this code :
foreach (ShoppingCartItemInfo prod in cartObj.CartItems)
{
prod.SKUObj.SKUAvailableItems = prod.SKUObj.GetIntegerValue("SKUAvailableItems", 1) - 1;

}

At the moment, I'm just trying to decrement by 2 the number of sku for each order.

Cheers


User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 5/10/2012 8:01:49 AM
   
RE:Custom inventory rules
Hello,


can you try to use a code like:

foreach (ShoppingCartItemInfo cartItem in cartObj.CartItems)
{

// Get cart item SKU
SKUInfo sku = GetSKUInfo(cartItem.SKUID);

// New units = item available units - (item units in cart - item units from order)
sku.SKUAvailableItems -= (cartItem.CartItemUnits - orderUnits);

// Save changes
SetSKUInfo(sku);

}


and change the calculation there.


Best regards,
Helena Grulichova

User avatar
Member
Member
heybro-yopmail - 5/11/2012 5:16:23 AM
   
RE:Custom inventory rules
Hello

Thanks Helena for the all the support given.

You gave me first the function to override when creating an order.
Now, with the code given I can customize my inventory rules due to UpdateInventoryInternal(ShoppingCartInfo cartObj) function in the SKUINfoProvider.

There is still one issue, the code you gave me only works when creating an order.
I mean the override function mentionned above seems to be executed when creating an order but not when updating one.

Is there another function called to update inventory when updating items quantity in an order ?

Thanks

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 5/14/2012 5:19:12 AM
   
RE:Custom inventory rules
Hello,


I have checked the code and if you change the order items in CMSDesk -> E-commerce -> Orders, it uses the code:

ShoppingCartInfoProvider.SetOrder(this.ShoppingCartInfoObj);


and this method calls:

SKUInfoProvider.UpdateInventory(cartObj);


as well so your custom changes in this method should be used. How does your customized method look like exactly?


Best regards,
Helena Grulichova