Is there a way to check whether a product already exists in Magento using the SOAP API that doesn't require using exception handling for the control flow?
I have the following code that works, but I wouldn't say it follows best practices.
Dim productExists As Boolean
Try
Dim webService As MagentoService = New MagentoWS.MagentoService
Dim productInfo As catalogProductReturnEntity = webService.catalogProductInfo(sSessionId, sku, String.Empty, Nothing, "sku")
productExists = True
Catch ex As SoapHeaderException
productExists = False
End Try
I have to catch the SoapHeaderException and then use the fact that the exception was thrown to know that the product doesn't exist.
Best Answer
I'm not sure how
.NET
s SOAP API would handle this, but I'd try using thecatalog_product.list
method with a SKU filter. If the resulting list/array/collection/whatever-its-serialized-as is empty, then you know the product doesn't exist.Per the comments below, the following code should get you that list