1

I am adding a new Product using the API, I am then running the function below to add an Image to the newly created product.

The problem is, when I view the newly created product, it has 1 valid image that was uploaded and then 1 broken image. It seems like it always makes 2 image records in the Admin panel even though only 1 image is uploaded.

I have tested this on multiple Magento installs and the problem persist everywhere. I am at a lost as to what to do next.

View this image to see the result after adding 1 image through the API, you can see it makes 2 entries (1 good one and 1 bad one)...

enter image description here

You can see in the image that the broken image is selected as the default. I cannot figure out why this broken image is even being created instead of my uploaded image being used.

Below is the Image API code I am using.

function uploadImage( $sku, $imagePath, $productId ) {
    global $proxy;
    global $sessionId;

    $sku = strtoupper($sku );
    $newImage = array(
        'file' => array(
            'name' => 'file_name',
            'content' => base64_encode(file_get_contents($imagePath)),
            'mime'    => 'image/png'
        ),
        'label'    => "Item:" . $sku,
        'position' => 0,
        'types'    => array('image', 'small_image', 'thumbnail', 'ebayimage' ),
        'exclude'  => 0
    );
    try {
        $imageFilename = $proxy->call(
            $sessionId,
            'catalog_product_attribute_media.create',
            array(
                $productId,
                $newImage
            )
        );
        echo '<br>Image Filename Added '.$imageFilename;
        //var_dump($proxy->call($sessionId, 'product_media.list', $sku));
    }
    catch(Exception $e) {
        print( "Error assigning image to $sku: " . $e->getMessage() . "\n" );
    }
}

And here is my Product creating code which then calls the Image function above...

try {
    // Create new product
    $productId = $proxy->call(
        $sessionId,
        'product.create',
        array(
            'simple',
            $attributeSet,
            $productSku,
            $productData
        )
    );
    echo 'Product ID Create: '.$productId;

    // Upload and attach Image
    $imagePath = 'twitter-header.png';
    uploadImage( $productSku, $imagePath, $productId );

} catch (SoapFault $e) {
    echo "Product creation error $e";
}

Any ideas why it would be creating this dummy broken image record everytime it creates a valid record?

UPDATE I was starting to think that possibly another extension on the magento site I am working on might be the cause but I have now tried my code on a brand new fresh Magento Install and the issue still exist. For every Image that I create through the API, it then creates an additional broken image with the original image name with _1 added to the end of the filename.

I cannot figure out why this is happening, surely such a huuuuuge bug wouldn't have lived in Magento this long?

Here is the result of the API call...You can see 2 image records for each Image added. The 2nd is the broken image and it is assigned the thumbnail, small_image, and image values

enter image description here

2
  • I'm having the same problem.. What did you do to fix?
    – eleven11
    Commented Jun 3, 2014 at 0:29
  • @eleven11 I never was able to find a solution, if you do please share it as an answer to this question and i'll select your answer as the correct one!
    – JasonDavis
    Commented Jun 3, 2014 at 13:48

1 Answer 1

1

I would start in the API call itself, it looks to be a pretty hefty method, with lots of things going on:

A quick glance at the code, it may be permissions related, since some temporary files are created in the create method.

I would start by dumping or logging the $data just to see if its showing twice from your one call.

Hope this helps.

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.