Bukimedia / PrestaSharp

CSharp .Net client library for the PrestaShop API via web service
GNU General Public License v3.0
155 stars 152 forks source link

How can i check if product has images and update them? #300

Closed cbacalhauTri closed 5 years ago

cbacalhauTri commented 6 years ago

Hello

How can i check if my product has images on prestashop??

thanks

LuisDavidR commented 6 years ago

Hi, Maybe this piece of code can help you. What it does is: checks if the product has some images associated to it... if it has, then updates the first image to the new one you give (imagePath).. if not, adds a new image to that product.

//prod is a product already added on prestashop
//imgfac is the ImageFactory

if (prod.associations.images.Count > 0)
     imgfac.UpdateProductImage((long)prod.id, prod.associations.images.First().id, imagePath);
else
     imgfac.AddProductImage((long)prod.id, imagePath);
mowcixo commented 5 years ago

Closing as it is answered by @LuisDavidR correctly.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.