Jump to content

Edit History

Sevarf2

Sevarf2

Hello, I'm trying to update / add a product image in a specific position, or declination as prestashop says.
I'm able to add an image but I can't add the declination id in the request and presta adds the image at the end leaving the other ids empty, if any....solutions? Thanks

I already tried to add the imge id at the end of the url like so "domain.com/api/images/products/productid/imageid/" but it doesn't work

this is my code for adding an image

 

function psProductsImageAdd($store,$productId,$image,$mime='image/jpg'){
        
        $apiUrlImage = $store->shopurl.'/api/images/products/'.$productId.'/';

        $args['image'] = new CurlFile($image, $mime);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
        curl_setopt($ch, CURLOPT_URL, $apiUrlImage);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_USERPWD, $store->apikey.':');
        curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
        $result = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        return $httpCode;
        
    }

 

Sevarf2

Sevarf2

Hello, I'm trying to update / add a product image in a specific position, or declination as prestashop says.
I'm able to add an image but I can't add the declination id in the request and presta adds the image at the end leaving the other ids empty, if any....solutions? Thanks

this is my code for adding an image

 

function psProductsImageAdd($store,$productId,$image,$mime='image/jpg'){
        
        $apiUrlImage = $store->shopurl.'/api/images/products/'.$productId.'/';

        $args['image'] = new CurlFile($image, $mime);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
        curl_setopt($ch, CURLOPT_URL, $apiUrlImage);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_USERPWD, $store->apikey.':');
        curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
        $result = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        return $httpCode;
        
    }

 

×
×
  • Create New...