4

I want all images of a product to use the default small_image, thumbnail and image again for every storeview using the SOAP api.

So far I've tried to set the 'types' using catalog_product_attribute_media.update to null but with no success.

            foreach($storeviews as $storeviewId) {
                $result = $client->call(
                    $session,
                    'catalog_product_attribute_media.list',
                    $productId,
                    $storeviewId
                );

                foreach($result as $image) {
                    $client->call(
                        $session,
                        'catalog_product_attribute_media.update',
                        [ 
                            $productId,
                            $image['file'],
                            [
                                'types' => null,
                            ]
                        ],
                        $storeviewId
                    );
                }
            }

3
+50

You have an error in your API call, the parameter type needs to be an array in order to be processed correctly. If you change your code and use an empty array instead of null you should achieve what you want.

Anyway it's not necessary to make update calls for images which do not have any image type set. So please change the code for the second foreach loop as follows and give it a try:

foreach($result as $image) {
    if (count($image['types']) > 0){
        $client->call(
            $session,
            'catalog_product_attribute_media.update',
            [ 
                $productId,
                $image['file'],
                [
                   'types' => []
                ]
            ],
            $storeviewId
        );
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.