Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No image details in product and category #235

Open
shamnu opened this issue Oct 4, 2020 · 6 comments
Open

No image details in product and category #235

shamnu opened this issue Oct 4, 2020 · 6 comments

Comments

@shamnu
Copy link

shamnu commented Oct 4, 2020

image src is getting null in product API.
I tried to read all product as a list there is no image URL or a binary data
version (4.3 )

@Prateek58
Copy link

gtting same error please someone response!

@shamnu
Copy link
Author

shamnu commented Dec 8, 2020

@Prateek58
have you resolve this issue ?
am still facing this issue
if you got an solution plz help me to resolve

@ddepassUSOM
Copy link

I am having the same issue.
I have to resort to uploading images through nopcommerce admin tool one by one.
Documentation for API is misleading.

@shamnu
Copy link
Author

shamnu commented Feb 14, 2021

@ddepassUSOM you mean, we just need to upload the images once again from admin?. I have the test data which nop commerce provided. and my API is not returning the image with the result of API

@ddepassUSOM
Copy link

Correct. I'm having the same issue you are having.

@ddepassUSOM
Copy link

ddepassUSOM commented Feb 18, 2021

So I think I figured out my problem.
if you look back at the documentation:

Create a new product with a product image which will be downloaded by nopCommerce

POST /API/products

{
  "product": {
    "name": "Skate Banana",
    "full_description": "<strong>Great snowboard!</strong>",
    "short_description": "TWIN ALL TERRAIN FUN",
    **### "images": [
      {
        "src": "http://cdn.lib-tech.com/wp-content/uploads/2016/07/2016-2017-Lib-Tech-Skate-Banana-Yellow-Snowboard-800x800.png"
      }**
    ]
  }
}

When posting in your code, the image class you derived needs to reflect what the actual post JSON is suggesting.

so what I did was comment out what JSON is not using below example:
 public class Image
    {
        //public int id { get; set; }
        //public int picture_id { get; set; }
        //public int position { get; set; }
        public string src { get; set; }
        public object attachment { get; set; }
    }


Then amend my code as follows:
 Image[] imgS = new Image[cnt];
                    for (int i = 0; i < cnt; i++)
                    {
                        Image img = new Image
                        {
                            //id = PFvarient.variant_id + PFvarient.files[i].id,
                           // picture_id = PFvarient.files[i].id,
                            src = PFvarient.files[i].preview_url,                            
                            //position = 1,
                            //attachment = PFvarient.files[i].size
                            //attachment = ConvertImageURLToBase64(PFvarient.files[i].preview_url)
                        };
                        imgS[i] = img;
                    }

Then generate the json for posting:
 var dsProd = new
                {
                    product = new
                    {
                        name = prd.name,
                        sku = prd.sku,
                        short_description = prd.short_description,
                        full_description = prd.full_description,
                        id = prd.id,
                        parent_grouped_product_id = prd.parent_grouped_product_id,
                        price = prd.price,
                        images = prd.images,
                        created_on_utc = DateTime.UtcNow
                    }
                };
                var json = JsonConvert.SerializeObject(dsProd);



Hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants