Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Programmatically determine existance of product and update. View modes: 
User avatar
Member
Member
Wheeldo - 10/2/2009 9:40:27 AM
   
Programmatically determine existance of product and update.
Hi All,

I've been working with the product import sample code here: http://devnet.kentico.com/Knowledge-Base/E-commerce/Products-import-from-external-source.aspx

However, I need to first programmatically check for a product's existance and I'm unsure how to do this via the API. Could anybody give me any pointers please?

Also: I'll then need to update this product, instead of inserting a new one, should it already exist.

Thanks

User avatar
Kentico Developer
Kentico Developer
kentico_martind - 10/16/2009 4:24:04 AM
   
RE:Programmatically determine existance of product and update.
Hello,

You can use following method:

CMS.Ecommerce.SKUInfoProvider.GetSKUs("whereCondition", "orderByExpression");

to get DataSet with product records that fulfill given where condition. Then you can use SkuID from particular record from DataSet to create SKUInfo object, change its properties and save these changes. Please see sample code bellow:


CMS.Ecommerce.SKUInfo sku = CMS.Ecommerce.SKUInfoProvider.GetSKUInfo(skuId);
sku.SKUAvailableItems += 1;
CMS.Ecommerce.SKUInfoProvider.SetSKUInfo(sku);


Best Regards,

Martin Dobsicek

User avatar
Certified Developer v7
Certified  Developer v7
slycknick - 10/20/2009 4:15:16 AM
   
RE:Programmatically determine existance of product and update.
This is summary of some code I use. I hope it helps.
Nick

Dim newSKU As CMS.Ecommerce.SKUInfo
newSKU = CMS.Ecommerce.SKUInfoProvider.GetSKUInfoByGUID(guidSKU)

If newSKU Is Nothing Then

' Insert new product

newSKU = New CMS.Ecommerce.SKUInfo
With newSKU
.SKUGUID = guidSKU
.SKUNumber = strSKUNumber ' product id
' Set other defaults ....

End With


' Add SKU
CMS.Ecommerce.SKUInfoProvider.SetSKUInfo(newSKU)


Else

' Update sku
With newSKU
.SKULastModified = Now
End With

newSKU.Update()
CMS.Ecommerce.SKUInfoProvider.SetSKUInfo(newSKU)


End If

User avatar
Member
Member
Wheeldo - 11/4/2009 10:07:50 AM
   
RE:Programmatically determine existance of product and update.
Thanks all... that did the trick.