API Questions on Kentico API.
Version 6.x > API > Order Items View modes: 
User avatar
Member
Member
max! - 5/30/2012 8:10:01 AM
   
Order Items
Hello there!

I need information about how to browse the order items from a specified order.
I explain what I want to do :

I'm creating new inventory rules thanks to the override of UpdateInventoryInternal(), the thing is that when I want to delete a product from the order, I want to apply an action on it (add data in a custom table for each product)
I used this code OrderItemInfoProvider.GetOrderItems(order.OrderID) to browse the orderItems until I noticed there was an issue ; this method returns the order object from database.

The thing is that when you remove at least 2 products from the order, the order "update" is diferent from when there is only one product to remove thanks to Event Logs. It seems Kentico do an "update" operation for each product but when it does it for the last product, the order is not updated and because the commit is at the really end of the whole operation I dont know.

I tried to get the updated order through the ECommerceContext or directly from ShoppingCartObj.Order but it doesnt work.

Can you try to help me plz ?

Cheers

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 5/31/2012 8:25:16 AM
   
RE:Order Items
Hello,


I am not sure whether I understand it.

You remove some order items (products) from an order by a code, right?

When it updates the order after each item removal, it updates only the last item changes in reality? The previous item removals have no effect because of the bad transaction? If you remove the items one by one, it works correctly, right?

Is that correct?


Best regards,
Helena Grulichova

User avatar
Member
Member
max! - 6/1/2012 2:53:39 AM
   
RE:Order Items
Thank you helena,

kentico_helenag wrote:
When it updates the order after each item removal, it updates only the last item changes in reality? The previous item removals have no effect because of the bad transaction? If you remove the items one by one, it works correctly, right?

Is that correct?

This is correct.
It updates only the last item as the transaction is committed at the really end, so the first item is not updated correctly.
If I want to remove items one by one there is no problem at all, but since there are at least 2 products to remove, there is a problem.

How can I manage to avoid this behaviour ?

Cheers

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 6/2/2012 8:12:03 AM
   
RE:Order Items
Hello,


What code do you use exactly to delete the items? Thank you in advance for your response.


Best regards,
Helena Grulichova

User avatar
Member
Member
max! - 6/4/2012 2:32:36 AM
   
RE:Order Items
Hello!

In fact I dont really delete the items but I do an operation on them, in order to simulate a delete operation in a custom table with inventory quantities. My new inventory is based on the use of custom tables, that's why I put my code in the override UpdateInventory function.
The behaviour when adding a product to the order works greatly, and when removing a product there's a problem.
Here is the part of my code :

IEnumerable<OrderItemInfo> orderItems = OrderItemInfoProvider.GetOrderItems(order.OrderID);
//seems to be not the good updated order object
foreach (OrderItemInfo orderItem in orderItems )
{

SKUInfo sku = GetSKUInfo(orderItem.OrderItemSKUID);

ShoppingCartItemInfo cartItem = cartObj.CartItems.SingleOrDefault(c => (c.CartItemBundleGUID == orderItem.OrderItemBundleGUID) && (c.SKUID == orderItem.OrderItemSKUID));

if ((cartItem == null) || (cartItem.CartItemUnits == 0))
{

if (!updates.ContainsKey(orderItem.OrderItemSKUID))
updates[orderItem.OrderItemSKUID] = -orderItem.OrderItemUnitCount;
else
updates[orderItem.OrderItemSKUID] += -orderItem.OrderItemUnitCount;

}
}

updates is a table containing order objects with SKUID and difference between basket and order quantity.

Cheers.

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 6/4/2012 5:42:50 AM
   
RE:Order Items
Hello,


I have consulted the issue with our developers and it would be the best to customize the DeleteOrderItemInfoInternal method of the OrderItemInfoProvider class to catch the event when it removes a product from an order. You can get the product according to the SKUId from the OrderItemInfo product.

It is not possible to catch the current state of order in the UpdateInventoryInternal method so it is needful to customize more methods to catch all needful actions.

You can also consider the Consulting services for this. The solution architects can help you with the best architecture for your customization.


Best regards,
Helena Grulichova

User avatar
Member
Member
max! - 6/12/2012 9:57:46 AM
   
RE:Order Items
Hello,

I come back as I still have issues.
Seems that the DeleteOrderItemInfo function is executed every time an update is done on the order.
So how can I know, if it's a regular update or if it's a product removed ? because as you may understood, I have a treatmant when quantities are different, but what I need is when we delete a product from order ?

Also, why it's located in the DeleteOrderItemInfo and not in the RemoveShoppingCartItem ?

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 6/18/2012 9:08:20 AM
   
RE:Order Items
Hello,


I have consulted the issue. The problem is that we do not update the order items which were changed or delete the items, it always deletes all order items and then creates them from the shopping cart object. The system does not know which item exactly was changed or removed.

You can follow the same approach in your external table. When it creates or deletes any item, it will create or delete the item in your database. Please be aware that it will delete and re-create the items every time you update an order.

In this case, please customize these methods:

DeleteOrderItemInfoInternal(OrderItemInfo itemObj)

SetOrderItemInfoInternal(OrderItemInfo itemObj)


It is also possible to customize this method:

SetOrderItemsInternal(ShoppingCartInfo cartObj)

where you can access the values before changes in the Order (through cartObj.OrderId -> the OrderInfo object) and the new values of the order (through cartObj.CartItems). Then you can make some custom comparation and update some values in your external table.


Best regards,
Helena Grulichova