Developer forum

Forum » Development » Cannot find product with GetProductsById

Cannot find product with GetProductsById

Yung Yi Wang
Reply

I'm having trouble finding the product with Products.GetProductsById with a ProductId and VariantId. I get null response back.

If I use GetProductsBySQL I also get null response back, but if I use the query in MSSQL management I can find the products. What is going wrong with these functions??

 


Replies

 
Morten Snedker
Reply

Hi Yung,

Do you have a full code example we can see?

Best regards
Morten

 
Nicolai Høeg Pedersen
Reply

And is the product in stock, published and have a price?

 
Yung Yi Wang
Reply

I am using Core 8.8.0.6

I made a function trying to get product info. The product has stock and price. When I tried Product.GetAllProducts() I am missing alot of products in my productcollection, how is that possible? If I use Product.GetProductByNumber, I am able to get the product, but other methods is giving me NULL reponse back. Product.GetProductsBySql("SELECT * FROM [EcomProducts]"); is also not getting all the products.

 

public static ProductStockModel GetResults(string productId, string variantId)
{
    Product product = Product.GetProductByID(productId, variantId);    
    ProductStockModel ProductResult = new ProductStockModel();

    if (product == null)
    {
        return ProductResult;
    }

    ProductResult.Number = productId;
    ProductResult.VariantId = variantId;

    ProductResult.Colors = GetVariantColors(product.VariantGroups);

    return ProductResult;
}

 
Nicolai Høeg Pedersen
Reply

It could be language that is the issue. The call you have here uses eCommerce.Common.Context.LanguageID - and if the context is not the same as the data, you will get null.

Otherwise it looks fine.

If you still cannot find it, we need a URL and the parameters you call this method with - the product and variantid.

BR Nicolai

 
Yung Yi Wang
Reply

LanguageID is the same as my data: LANG1. I am currently still developing in local environment.

I will try to get this to an online test environment.

 
Yung Yi Wang
Reply

I put in on test environment and there I get the product back.

I think the development database data request/response is corrupt???

If I use the CMS management center and execute the SQL query I get the product also in development. What is going wrong in development backend?? Something is corrupt.

 
Nicolai Høeg Pedersen
Reply

I have no clue... :-).
I would need to see your setup to locate the error - make sure the website, database and IIS matches what you think it should. Sometimes I get my things messed up so I cannot understand what happens...

 

You must be logged in to post in the forum