Commerce Server General - Creating Product Variants using FP1 API

This is Interesting: Free IT Magazines  
Home > Archive > Commerce Server General > July 2004 > Creating Product Variants using FP1 API





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Creating Product Variants using FP1 API
Matthew Watkins

2004-07-20, 5:53 pm

I am trying to create a new Product and its variants using the Microsoft.CatalogServer API.

The code I have runs to completion, but when I look at the resulting product in the Catalog Manager, the product is correct but no variants are created, and no error is returned, and no error is recorded in the event log.

Does anyone have working code that creates Products, its variants and sets the variant information.

Thanks in Advance

The code is as follows

If IsNewBln Then
objProduct = objBaseCatalog.CreateProduct(_ProductDefinition, UniqueIDStr, _Price, _Category, NameStr)
Else
objProduct = objBaseCatalog.GetProduct(UniqueIDStr)
End If


Dim objCategory As Category = GetCategory()

Dim objProductInfo As CatalogItemsDataSet

Dim objItem As CatalogItemsDataSet.CatalogItem



objProductInfo = objProduct.Information

objItem = objProductInfo.CatalogItems(0)

If ProductDs.Tables(CatalogProductTable).Rows.Count <> 1 Then
Throw New ApplicationException("1 and only 1 Product row is required")
Else
Dim rw As DataRow
rw = ProductDs.Tables(CatalogProductTable).Rows(0)

For Each dc As DataColumn In ProductDs.Tables(CatalogProductTable).Columns
objItem(dc.ColumnName) = rw(dc.ColumnName)
Next



Dim objVariants As CatalogItemsDataSet
Dim dv As DataView = New DataView




objVariants = objProduct.Variants


dv.Table = objVariants.CatalogItems

dv.RowFilter = ""

For Each rwVariant As CatalogItemsDataSet.CatalogItem In objVariants.CatalogItems
dv.Table = ProductDs.Tables(CatalogVariantTable)
dv.RowFilter = "VariantID = '" + rw("VariantID") + "'"
Dim drv As DataRowView = dv.Item(0)

rwVariant.BeginEdit()
rwVariant.ListPrice = drv("cy_List_Price")


For Each dc As DataColumn In ProductDs.Tables(CatalogVariantTable).Columns
If dc.ColumnName <> "VariantID" And dc.ColumnName <> "cy_List_Price" Then

rwVariant(dc.ColumnName) = drv(dc.ColumnName)
End If





Next
rwVariant.EndEdit()

rwVariant.AcceptChanges()
Dim str As String = rwVariant.RowError

Next
objVariants.CatalogItems.AcceptChanges()
objVariants.AcceptChanges()


'All Information should now be in synch
objProduct.Save()





Vinayak Tadas[MSFT]

2004-07-20, 5:53 pm

To create a variant you should be calling the AddVariant method on the
Product object.
Also you should not call the AcceptChanges methods on the Variants
datatable.
objVariants.CatalogItems.AcceptChanges()
objVariants.AcceptChanges()


--------------------
Thread-Topic: Creating Product Variants using FP1 API
thread-index: AcRuiIwdAVUKMSU9RUe24/i6xit3aQ==
X-WBNR-Posting-Host: 81.178.227.60
From: =?Utf-8?B?TWF0dGhldyBXYXRraW5z?= <Matthew
Watkins@discussions.microsoft.com>
Subject: Creating Product Variants using FP1 API
Date: Tue, 20 Jul 2004 11:37:01 -0700
Lines: 91
Message-ID: <D2B6C9A2-9925-4DEC-B20B-B143DEAD69B4@microsoft.com>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.commerceserver.general
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 127.0.0.1
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.commerceserver.general:14312
X-Tomcat-NG: microsoft.public.commerceserver.general

I am trying to create a new Product and its variants using the
Microsoft.CatalogServer API.

The code I have runs to completion, but when I look at the resulting
product in the Catalog Manager, the product is correct but no variants are
created, and no error is returned, and no error is recorded in the event
log.

Does anyone have working code that creates Products, its variants and sets
the variant information.

Thanks in Advance

The code is as follows

If IsNewBln Then
objProduct = objBaseCatalog.CreateProduct(_ProductDefinition,
UniqueIDStr, _Price, _Category, NameStr)
Else
objProduct = objBaseCatalog.GetProduct(UniqueIDStr)
End If


Dim objCategory As Category = GetCategory()

Dim objProductInfo As CatalogItemsDataSet

Dim objItem As CatalogItemsDataSet.CatalogItem



objProductInfo = objProduct.Information

objItem = objProductInfo.CatalogItems(0)

If ProductDs.Tables(CatalogProductTable).Rows.Count <> 1 Then
Throw New ApplicationException("1 and only 1 Product row is
required")
Else
Dim rw As DataRow
rw = ProductDs.Tables(CatalogProductTable).Rows(0)

For Each dc As DataColumn In
ProductDs.Tables(CatalogProductTable).Columns
objItem(dc.ColumnName) = rw(dc.ColumnName)
Next



Dim objVariants As CatalogItemsDataSet
Dim dv As DataView = New DataView




objVariants = objProduct.Variants


dv.Table = objVariants.CatalogItems

dv.RowFilter = ""

For Each rwVariant As CatalogItemsDataSet.CatalogItem In
objVariants.CatalogItems
dv.Table = ProductDs.Tables(CatalogVariantTable)
dv.RowFilter = "VariantID = '" + rw("VariantID") + "'"
Dim drv As DataRowView = dv.Item(0)

rwVariant.BeginEdit()
rwVariant.ListPrice = drv("cy_List_Price")


For Each dc As DataColumn In
ProductDs.Tables(CatalogVariantTable).Columns
If dc.ColumnName <> "VariantID" And dc.ColumnName <>
"cy_List_Price" Then

rwVariant(dc.ColumnName) = drv(dc.ColumnName)
End If





Next
rwVariant.EndEdit()

rwVariant.AcceptChanges()
Dim str As String = rwVariant.RowError

Next
objVariants.CatalogItems.AcceptChanges()
objVariants.AcceptChanges()


'All Information should now be in synch
objProduct.Save()







Thanks
Vinayak Tadas
Microsoft
http://blogs.msdn.com/vinayakt

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2002 Microsoft Corporation. All rights
reserved.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Get Secure! For more info visit http://www.microsoft.com/security. Please
reply to the newsgroups only. Thanks

Matthew Watkins

2004-07-20, 5:53 pm

Removing the accept changes did the trick

Thanks

Matthew




""Vinayak Tadas[MSFT]"" wrote:

> To create a variant you should be calling the AddVariant method on the
> Product object.
> Also you should not call the AcceptChanges methods on the Variants
> datatable.
> objVariants.CatalogItems.AcceptChanges()
> objVariants.AcceptChanges()
>
>
> --------------------
> Thread-Topic: Creating Product Variants using FP1 API
> thread-index: AcRuiIwdAVUKMSU9RUe24/i6xit3aQ==
> X-WBNR-Posting-Host: 81.178.227.60
> From: =?Utf-8?B?TWF0dGhldyBXYXRraW5z?= <Matthew
> Watkins@discussions.microsoft.com>
> Subject: Creating Product Variants using FP1 API
> Date: Tue, 20 Jul 2004 11:37:01 -0700
> Lines: 91
> Message-ID: <D2B6C9A2-9925-4DEC-B20B-B143DEAD69B4@microsoft.com>
> MIME-Version: 1.0
> Content-Type: text/plain;
> charset="Utf-8"
> Content-Transfer-Encoding: 7bit
> X-Newsreader: Microsoft CDO for Windows 2000
> Content-Class: urn:content-classes:message
> Importance: normal
> Priority: normal
> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
> Newsgroups: microsoft.public.commerceserver.general
> NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 127.0.0.1
> Path: cpmsftngxa06.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
> Xref: cpmsftngxa06.phx.gbl microsoft.public.commerceserver.general:14312
> X-Tomcat-NG: microsoft.public.commerceserver.general
>
> I am trying to create a new Product and its variants using the
> Microsoft.CatalogServer API.
>
> The code I have runs to completion, but when I look at the resulting
> product in the Catalog Manager, the product is correct but no variants are
> created, and no error is returned, and no error is recorded in the event
> log.
>
> Does anyone have working code that creates Products, its variants and sets
> the variant information.
>
> Thanks in Advance
>
> The code is as follows
>
> If IsNewBln Then
> objProduct = objBaseCatalog.CreateProduct(_ProductDefinition,
> UniqueIDStr, _Price, _Category, NameStr)
> Else
> objProduct = objBaseCatalog.GetProduct(UniqueIDStr)
> End If
>
>
> Dim objCategory As Category = GetCategory()
>
> Dim objProductInfo As CatalogItemsDataSet
>
> Dim objItem As CatalogItemsDataSet.CatalogItem
>
>
>
> objProductInfo = objProduct.Information
>
> objItem = objProductInfo.CatalogItems(0)
>
> If ProductDs.Tables(CatalogProductTable).Rows.Count <> 1 Then
> Throw New ApplicationException("1 and only 1 Product row is
> required")
> Else
> Dim rw As DataRow
> rw = ProductDs.Tables(CatalogProductTable).Rows(0)
>
> For Each dc As DataColumn In
> ProductDs.Tables(CatalogProductTable).Columns
> objItem(dc.ColumnName) = rw(dc.ColumnName)
> Next
>
>
>
> Dim objVariants As CatalogItemsDataSet
> Dim dv As DataView = New DataView
>
>
>
>
> objVariants = objProduct.Variants
>
>
> dv.Table = objVariants.CatalogItems
>
> dv.RowFilter = ""
>
> For Each rwVariant As CatalogItemsDataSet.CatalogItem In
> objVariants.CatalogItems
> dv.Table = ProductDs.Tables(CatalogVariantTable)
> dv.RowFilter = "VariantID = '" + rw("VariantID") + "'"
> Dim drv As DataRowView = dv.Item(0)
>
> rwVariant.BeginEdit()
> rwVariant.ListPrice = drv("cy_List_Price")
>
>
> For Each dc As DataColumn In
> ProductDs.Tables(CatalogVariantTable).Columns
> If dc.ColumnName <> "VariantID" And dc.ColumnName <>
> "cy_List_Price" Then
>
> rwVariant(dc.ColumnName) = drv(dc.ColumnName)
> End If
>
>
>
>
>
> Next
> rwVariant.EndEdit()
>
> rwVariant.AcceptChanges()
> Dim str As String = rwVariant.RowError
>
> Next
> objVariants.CatalogItems.AcceptChanges()
> objVariants.AcceptChanges()
>
>
> 'All Information should now be in synch
> objProduct.Save()
>
>
>
>
>
>
>
> Thanks
> Vinayak Tadas
> Microsoft
> http://blogs.msdn.com/vinayakt
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
> You assume all risk for your use. © 2002 Microsoft Corporation. All rights
> reserved.
> Use of included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm
> Get Secure! For more info visit http://www.microsoft.com/security. Please
> reply to the newsgroups only

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com