Developer forum

Forum » Development » ProductService.GetProductById not returning product variant

ProductService.GetProductById not returning product variant

Arnór Halldórsson
Arnór Halldórsson
Reply

Hi,

Under the ProductService class we have the function GetProductById that has various input schemes:

public Product GetProductById(string productId, string productVariantId, bool useDefaultLanguage);
public Product GetProductById(string productId, string productVariantId, string productLanguageId, bool useAssortments);
public Product GetProductById(string productId, string productVariantId, string productLanguageId);

If I have a product with 2 variants, so 3 rows in the EcomProducts table: 1 for the head product, and then 1 row for each variant combination. If I then call GetProductById, sending in the product id, variant id and languageId, the function will always return to me the head product, not the variant combination one. Is this how it's supposed to be? And if so, if I want to get exactly the EcomProduct item for that specific variant combination, must I do a SQL select for it instead?

EcomProducts table example (Ignore the null fields): https://imgur.com/a/EYsV8aQ

TLDR; Sending GetProductById("164798", "SVARTUR..", "LANG1"); will always return the top product on the image above.

Best regards,
Arnór

Replies

 
Steffen Kruse Hansen
Reply

Hi Arnór,

The GetProductById method should be able to return the actual variant, when you specify the VariantId when you call it, so this seems a bit weird that you get the main product.

I have a couple of questions:

 - The VariantId 'SVARTUR..', how many VariantGroups does it consist of? We usually use . for separating the different options from the VariantGroups, so if you have three VariantGroups, you normally get something like VO1.VO5.VO10. So if you only have one VariantGroup, and the ID of the selected option is 'SVARTUR..', you could run into some problems.

 - Which version of Dynamicweb are you using?

Best regards,

Steffen

 
Arnór Halldórsson
Arnór Halldórsson
Reply

Hi Steffen,

Yes I know, all in all we have 3 variant groups: COLOR, SIZE and STYLE. This product only has COLOR variants, and therefore the variantID for the product becomes SVARTUR..

If a product has only SIZE variants, the variantIDs would be: .XL. 

We're receiving this data from a 3rd party PIM system, could the problem lie in the extra dots? Should we trim off the extra dots so the variantID becomes only SVARTUR, and no dots unless there are multiple variant groups for the product?

Best regards,
Arnór

 

You must be logged in to post in the forum