2

I want to update product image label for specific store view using API v1. First, I've created product

$res = $client->call($session, 'catalog_product.create', array(
'downloadable',
47,
'standardapiv1_' . uniqid(),
array(
    'websites' => array(2),
    'name' => 'Standard api v1',
    'description' => 'Product description',
    'short_description' => 'Product short description',
    'weight' => '10',
    'status' => '1',
    'visibility' => '4',
    'price' => '100',
    'tax_class_id' => 1,
    'meta_title' => 'Product meta title',
    'meta_keyword' => 'Product meta keyword',
    'meta_description' => 'Product meta description'
),));

and added product image to this product

$res2 = $client->call($session, 'product_media.create', array(
    $res, array(
        'file' =>$newFile,
        'label'=>'standard api',
        'types'=>array('thumbnail'),
        'exclude'=>0
    )
));

Product was successfully created. When I run this request to API

$res =$client->call($session, 'product_media.update', array(
1047,
'/i/m/image_10.jpg',
array(
    'file'=>$newFile,
    'label'=>'update lbl',
),
'2'));

I got this error Product with the 'standard-api-v1' url_key attribute already exists. If last parameter is not set - storeView - everything works well, so source of problem is looks like be here: \app\code\core\Mage\Catalog\Model\Product\Attribute\Media\Api.php line 256:

try {
    $product->save();
    } catch (Mage_Core_Exception $e) {
        $this->_fault('not_updated', $e->getMessage());
    }

Does anyone know, what am I doing wrong? I've made some research, and found answers, that it was a bug in EE 1.13

1 Answer 1

1

This will do the trick. I didn't pass in the store id but you can pass it in the same way that you were.

$attrSetId = 4;
$sku       = 'standardapiv1_' . uniqid();

$client    = new SoapClient($url, array('trace' => 1));
$sessionId = $client->login($username, $password);
$productId = $client->call($sessionId, 'catalog_product.create',
                           array('downloadable',
                                 $attrSetId,
                                 $sku,
                                 array(
                                     'websites'          => array(2),
                                     'name'              => 'Standard api v1',
                                     'description'       => 'Product description',
                                     'short_description' => 'Product short description',
                                     'weight'            => '10',
                                     'status'            => '1',
                                     'visibility'        => '4',
                                     'price'             => '100',
                                     'tax_class_id'      => 1,
                                     'meta_title'        => 'Product meta title',
                                     'meta_keyword'      => 'Product meta keyword',
                                     'meta_description'  => 'Product meta description'
                                 ),));

$file        = pathinfo('media/wysiwyg/about-us2.jpg');
$fileContent = base64_encode(file_get_contents($filePath));
$mimeType    = image_type_to_mime_type(exif_imagetype($filePath));
$attrCodes   = array('small_image', 'base_image', 'thumbnail');

$pathToImg = $client->call($sessionId, 'product_attribute_media.create',
                           array($productId,
                                 array(
                                     'file'     => array(
                                         'name'    => $file['filename'],
                                         'content' => $fileContent,
                                         'mime'    => $mimeType
                                     ),
                                     'label'    => 'Some Image',
                                     'position' => 2,
                                     'types'    => $attrCodes,
                                     'exclude'  => 0
                                 )
                           ));

$result = $client->call($sessionId, 'product_attribute_media.update',
                        array($productId,
                              $pathToImg,
                              array(
                                  'label'    => 'Updated Image Label',
                                  'position' => 2,
                                  'types'    => $attrCodes,
                                  'exclude'  => 0
                              )
                        )
);
2
  • 1
    thank you for answer, but that is the problem - when @storeView is not passed, everything is OK, error occurs when IT IS passed. May 15, 2016 at 19:41
  • ok, i will see if i can revamp my answer May 15, 2016 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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